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
My theory is there is a race condition deep inside Apple’s implementation which is causing this. Unfortunately if that’s true, that means we can’t really do anything to fix this and must wait for Apple.
A possible workaround is to tell findFreeChannel() to start looking for a free channel at snd1_cnl+1, e.g:
local free_cnl = audio.findFreeChannel(snd1_cnl+1)
However, I encourage you to file a bug with Apple at https://bugreport.apple.com
For now, you can simply refer to the bug at OpenRadar and provide any specific information about your app. Your bug will be marked as a duplicate, but this "votes’ for a bug and gives them additional information. After, I get more time to poke at this, I’ll file a new more specific bug and will ask you to file a new bug to reference that one as well.
I encourage anybody else affected by this bug to do the same and file a bug with Apple. This is the procedure we need to follow to get them to fix their bugs.
[import]uid: 7563 topic_id: 4337 reply_id: 14800[/import]
For the record, I filed bug 8857655 at Apple’s Bug Reporter which references the other bug I mentioned on Open Radar. I do encourage everybody to file a bug on Apple’s Radar referencing 8857655. You don’t have to say much except that you are affected by this bug. [import]uid: 7563 topic_id: 4337 reply_id: 16353[/import]