Interrupted sounds

Why don't our sounds layer up on top of each other with any consistency? It completely ruins our game play at the moment :(

We have a number of instances of the same character appearing on the screen at once. The sounds they produce are frequently interrupted and cut-off when a number of them are attempting to play at once. They just don't seem to layer up.

We have tried using varying channels for each sound with no success. Is this something other people have experienced? What fixes are there if any?

Method used by each instance of the character:

1
2
3
4
5
-- Our character instance
local Character = {};
-- Our character's explosion noise.
Character.explosion_1 = audio.loadSound("sounds/explosion_1.aif");
audio.play(Character.explosion_1, {channel=1}); -- We make sure not to use channel for other sounds.

I suspect you are using the API incorrectly. You have multiple things that look suspicious.

- Your character explicitly requests channel 1. If all your character instances are requesting channel 1, they will fight for the channel (likely, subsequent attempts to play will fail because the resource is in use...it shouldn't cut out)

- You are (re)loading multiple instances of the same file for each character. If they all share the same sound, you should just load it once and share the handle.

- Conversely, you are unloading the sound when the character goes away. This is bad for multiple reasons.
-- If multiple characters are sharing the sound, unloading the sound will break things.
-- If your character is still playing a sound while you are stopping/unloading, your sounds may be cut off

- To emphasize the last point, make sure you only stop and unload the sound after the sound has finished playing. A typical pitfall is that killing your object instance (say an asteroid explodes/dies/goes-away), the visual effect may need to disappear before the sound completes. Invoking a destructor at the end of the visual is the wrong thing to do as the lifetimes of the visual effect and sound effect are different. Either you need to decouple the clean up of them or detect which is the longer of the two and then do clean up at the end of the longer one.

One more thing, the parameter you are passing to audio.stop() is garbage. audio.stop expects a channel number, not a sound reference.

Great help,
The creatures are modular, so what I think we'll do is load the sounds just once into the central game play file, then reference them out through function variables. This is opposed to loading sounds within each creature and then cleaning them up on death.

Example pseudo code: newCreature( moveSound );

Took the reference for: audio.stop( )

from the docs' example: http://developer.anscamobile.com/reference/index/audiostop

1
2
backgroundMusicChannel = audio.play( backgroundMusic, { loops=-1 }  ) 
audio.stop( backgroundMusicChannel )

Stlll having issues, even if we load the sound once, then call it from it's handle.

It must be to do with clashes on channels. There are multiple creatures and we've done what we can to distinguish and access available channels.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
-- Init sound.
local sound_dir = "sounds/";
local fuseChannel = nil;
Creature.fuse_lit_snd = audio.loadSound(sound_dir .. "fuse_lit.aif");
 
...
 
-- Play sound.
fuseChannel = audio.findFreeChannel();
audio.play(Creature.fuse_lit_snd, {channel=fuseChannel});
audio.setVolume( 0.4, { channel=fuseChannel } );
 
...
 
-- Later, once the sound has most defiantly ended.
audio.stop(fuseChannel);
audio.dispose(self.fuse_lit_snd);
self.fuse_lit_snd = nil;

Testing with: print( audio.freeChannels );
Starts out with no sounds: "32".

When there should be 6-8 sounds playing over 'free channels' it only ever seems to reach: "29".

The variable for audio.stop is named backgroundMusicCHANNEL. Not sure how that is unclear.

You should be allowed 32 simultaneous sounds. Our audio engine (ALmixer) does not cull or stop sounds when out of resources. It will simply refuse to play the next sound you request. Sounds stopping short implies you have something in your code that is still calling stop/dispose when you shouldn't be.

Is this on Mac, Windows, iOS, or Android?

Check the value of both fuseChannel and what return value audio.play returns to make sure the play succeeded.

views:1428 update:2011/9/28 9:01:40
corona forums © 2003-2011