Hi,
In my game I need to:
- play sound 1
- wait
- stop sound 1
- play sound 2 (immediately)
I’ve implemented it using the old API and everything used to work just find.
Today I’ve tried to migrate it to the new OpenAL API, and I found out that the second sound is not being played every time…
I saw that both sounds use the same channel (makes sense since that channel is free after stopping the first sound).
Is it possible that there is a race condition between the stop and play methods which causes this problem?
Here is a sample code which demonstrates the problem:
- load 2 sounds
- wait for 2 seconds, and play the first sound
- wait for another 0.5 second
- stop the first sound and immediately play the second sound
When I test it with 2 sounds (the first one should last more than 0.5 second) I get that the second sound is not being played every time…
[code]
– load sounds
– sound1 length = ~4 seconds
local snd1_snd = audio.loadSound( “sound1.caf” )
– sound1 length = ~0.5 second
local snd2_snd = audio.loadSound( “sound2.caf” )
local snd1_cnl = -1
local snd2_cnl = -1
local function timer2Cb( evt )
– stop sound1
print( "stop channel " … snd1_cnl )
audio.stop( snd1_cnl )
if ( true == audio.isChannelActive( snd1_cnl ) ) then
print( “channel " … snd1_cnl … " is still active…” )
end
– play sound2
local free_cnl = audio.findFreeChannel()
snd2_cnl = audio.play( snd2_snd, { channel = free_cnl } )
print( "play sound2, snd2_cnl = " … snd2_cnl )
end
local function timer1Cb( evt )
– play sound1
snd1_cnl = audio.play( snd1_snd )
print( “----------” )
print( "play sound1, snd1_cnl = " … snd1_cnl )
– stop sound1 in 1 second
timer.performWithDelay( 500, timer2Cb)
end
– play sounds in delay
timer.performWithDelay( 2000, timer1Cb, 0 )
[/code] [import]uid: 9536 topic_id: 4337 reply_id: 304337[/import]