# Use of binary flags and duration variables for sound

## Recommended Posts

In another thread someone was trying to use data tables for sound engine use.  I suggested using seperate variables for each sound that would act as both duration and the sound effect itself.

Nukey Shay suggested using a variable for bitwise flags and another variable for duration.  My addled brain came up with a scheme that has a big problem:

Say, an enemy needs a torpedo sound.  Simple!  Raise the torpedo sound flag and set the duration:

def torpedosound=soundlfag{0}

def lasersound=soundlfag{0}

soundflag{0} = 1

duration = 25

But, now the player fires and needs his laser sound played.  So,  we set the laser sound flag:

soundflag{1} = 1

duration = 35

The torpedo flag hasn't finished yet so the duration get overwritten with the duration of the laser!   I can also imagine the game needing the opposite where a laser sound is playing but needds the torpedo sound to play (thus overriding the torpedo sound).

I never had to worry about this with my single variable for a specific sound method.  Each sound was always run if it was more than 0.  Since the variable was also the duration each sound couldn't mess with the others duration or priority.

How does one use just one variable for sound flags and a single duration variable given the two issues presented (priority and duration being overridden)?

##### Share on other sites

My brain isn't working good enough tonight to understand your post. Have you checked out the sound effects in Seaweed Assault:

I have constants for the different sound effects:

```   ;***************************************************************
;
;  Constants for channel 0 sound effects (_Ch0_Sound).
;  [The c stands for constant.]
;
const _c_Torp_Hit_Seaweed_01 = 1
const _c_Torp_Hit_Seaweed_02 = 2
const _c_Ship_Bounce = 3
const _c_Shoot = 4
const _c_1000_Health = 5
const _c_Game_Over = 6
const _c_Gyvolver = 7

;***************************************************************
;
;  Constants for channel 1 sound effects (_Ch1_Sound).
;  [The c stands for constant].
;
const _c_Ship_Drop_In = 1
const _c_Tentacle_Reaching_Up = 2
const _c_Wrothopod = 3
const _c_Canister_Appear = 4
const _c_Canister_Touched = 5
const _c_Corroded_Tick_Down = 6
const _c_Corroded_Seaweed_Moosh = 7
const _c_Corroded_Chase = 8
const _c_Corroded_Hit_Ship = 9
const _c_GO_Seaweed_Attack = 10
const _c_MLS_Seaweed_Close_In = 11```

Then I check with if-thens if I don't want the sound to play if certain sounds are already playing:

```   ;```````````````````````````````````````````````````````````````
;  Starts torpedo fire sound effect (channel 0).
;
if _Ch0_Sound = _c_Ship_Bounce then goto __Done_Fire

if _Ch0_Sound = _c_1000_Health then goto __Done_Fire

_Ch0_Counter = 0 : _Ch0_Sound = _c_Shoot : _Ch0_Duration = 1

__Done_Fire```

##### Share on other sites

It would only work if you cut the first sound off when the second one is playing; otherwise you need two variables. The other possibility would be if all of your sounds are length 16 or less you could divide the variable into nybbles, one for each channel.

##### Share on other sites

Is it possible to have it check to see if the duration for the first sound was finished and if that sound is still playing to have the new sound play on the second channel?

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.