I have been working on this OpenAL problem many times and I can’t find the best way to ensure audio reproduction in the application.
This is the story: I have music, speech narration and sound effects as far as 150 different sound files in .caf and .mp3 format (only for music/narrations).
The application is an interactive-book, therefore each screen has different graphics and sounds, none of them are repeated (I didn’t make the design and concept, so… I am just coding).
The way that I use the sounds is in this format:
First, each screen is switched by using Director Class, after that I use to load the sound by: audio.loadSound (for short sounds) and audio.loadStream (for narration). Sound files for narrations are between 550Kb and 1.2Mb uncompressed.
To reproduce sounds, I use to call audio.play(sound, params)
Then (here I guess the problem reside) when the screen has to be switched to another one, the Clean (director function in the lua code) is invoked with the following lines:
audio.stop(channel)
audio.dispose(sound)
sound=nil
Now, if the sound is reproduced until the end and then the user switch the screen, there is no problem. The channel is liberated and the sound is eliminated (I guess from the memory, but I am not really sure). Then if the user switch the screen in the middle of a sound, (playing) sometimes the stop works well, but dispose seems to not free the resource from the memory, therefore ALmixer_FreeData: alDeleteBuffers failed. Invalid Operation is raised. Some times, after several screens the sound, music or narrations are totally lost. Some times, the volume (really I don’t know why…), goes down without any reason. If the application still running at the end, a crash is produced either in the simulator (including Corona exception and close) or device (app crash).
So, I did some workarounds like add audio.stop(0) on the start of every screen, after the switch. It helps only if there was a previous sound played. If not, it will stop sounds and no more reproductions are executed. (strange behaviour, but happens).
I tried to stop only the active channel, paused or playing one but it seems that it does not work as expected.
In my code the line check if the channel is active by using:
if audio.isChannelPlaying(soundChannel) or audio.isChannelActive(soundChannel) then
audio.pause(soundChannel)
But even so, the audio is not stopped and therefore is not disposed as it is supposed to be. So, at the end, the problem persists.
I tried different scenarios without to much result. I saw there was/is a bug in the Apple OpenAl implementation, but I am also saw applications running well without this problem, so where is the problem? In the Apple OpenAl mixer implementation, in the Corona wrapper or in my code?
I even saw many threats about this issue in the forum without to many clues and I guess Ansca help is required here to put an example code on how to deal with this situation (different screens with Director class, with different sounds loaded, played and disposed in every screen).
Flavio.
[import]uid: 3022 topic_id: 16935 reply_id: 316935[/import]