I am using audio.loadSound( “audio.wav” ) format. I call on most of these sounds (“audio.play( sound )”) several times during a level through an onLocalCollision( self, event ) function, but a few are called outside of this function. The symptoms are that after about 35 min of play the sound stops working. The gameplay continues normally, but all sound stops. This issue does not cause a crash. The issue is not specific to any particular level or event. The only common factor is time. I check for memory leaks and cannot find any. The audio files I am using are: WAV, 16 bit, 352kbps bitrate, 22KHz, and Mono. Also I am using the build 2011.484. Any suggestions would be most appreciated. [import]uid: 14935 topic_id: 9010 reply_id: 309010[/import]
I tested it in the Windows simulator and it does not happen. I played for over 1 hour with no sound issues. On the iPad and iTouch it occurs right around 30 min like clockwork. I tried reducing the number of sounds and it still took 30 min. Anyone have any ideas? Thanks in advance. [import]uid: 14935 topic_id: 9010 reply_id: 32905[/import]
I will have to check for this problem when I get home tonight. [import]uid: 12108 topic_id: 9010 reply_id: 33132[/import]
Ok. I appreciate it. I also tried to redo my sound files to be 16 bit, 176kbps, 11KHz, and Mono. This didnt help. I am not using channels because the sounds are just occuring on collision and I have no continuos sound. But I did put code in to check to make sure that somehow the channels were not being used up and I always have 30-32 free channels. I also tried putting in code to set the volume to 0.5 and it didnt help. Through all of this testing still no sound after ~30 minutes. But gameplay continues normally. I have played it for 20 minutes after with no other issues on both iPad and iTouch. [import]uid: 14935 topic_id: 9010 reply_id: 33138[/import]
Also, I was curious if someone had a good document resource for how the sound API handles memory and such. [import]uid: 14935 topic_id: 9010 reply_id: 33139[/import]
My first guess would be there is some kind of overflow condition in the timers. The new upper layer of the audio code is almost identical across all platforms with a platform specific differences. The timer system is one of those areas that is different on iOS.
Which iOS version numbers and specific devices have you tested on?
If you could figure out roughly the exact moment it breaks, that might be helpful. If it is a timer problem, I expect the number to be some kind of magic number that overflows. The timer system is based on unsigned 32-bit integers. In theory, it should overflow in a little over 49 days, not 30 minutes.
The iOS implementation is:
static ALuint ALmixer_GetTicks()
{
return (ALuint)((CACurrentMediaTime()-s_ticksBaseTime)*1000.0);
}
Are you playing short sound effects or are you continuously looping and streaming music? Also, is playing sounds via loadStream and loadSound both broken. I would expect playing sounds via loadSound to continue working while loadStream would break if this is a timer overflow problem, though I might be wrong about this point. (Don’t use any fade-outs/ins/expires.)
Also please verify you are not backgrounding/resuming your app.
It is also possible there is a bug in Apple’s underlying implementation of OpenAL which will also differ from Mac, Windows, and Android.
Almixer (the audio engine backend we use) is open source. The code is really scary, but if you are brave and persistent, you can see for yourself how everything is implemented. Patches are always welcome too.
http://playcontrol.net/opensource/ALmixer/
[import]uid: 7563 topic_id: 9010 reply_id: 33166[/import]
iTouch iOS - 4.1 (8B117)
iPad iOS - 4.3.2(8H7)
I am playing short sound effects throughout the game. There is no continuos sound playing. I am using loadSound() for all sounds and I am not using any (fade-outs/ins/expires). I am not backgrounding or resuming either.
I switched all sound over to media.newEventSound and media.playEventSound and I am testing right now on iPad. Using this way I have no sound at all on the iTouch. [import]uid: 14935 topic_id: 9010 reply_id: 33168[/import]
I just left multipuck running on an iPad 2 for an hour and a half. It still plays sounds.
Are there error messages in your device log? Perhaps you are running out of memory? Maybe you are leaking audio resources. Did you read this page:
http://developer.anscamobile.com/partner/audionotes
Make sure to load sounds only once at time and dispose them if you need to free the memory.
[import]uid: 7563 topic_id: 9010 reply_id: 33175[/import]
I just tested the iPad using the media.newEventSound/media.playEventSound and I played for 1 hour without any sound issues. Also, the iTouch worked to. I just had to shut it off a few times and it started playing the sound. I am testing it now. [import]uid: 14935 topic_id: 9010 reply_id: 33177[/import]
“I just left multipuck running on an iPad 2 for an hour and a half. It still plays sounds.”
Sorry let me clarify. I can walk away with my game on and continue an hour later and it still has sound. Its only continuos game play.
[import]uid: 14935 topic_id: 9010 reply_id: 33179[/import]
So I guess the question is 'Does audio.loadSound/audio.play use the same memory management as media.newEventSound/media.playEventSound?"
[import]uid: 14935 topic_id: 9010 reply_id: 33181[/import]
I am setting sounds to nil after each level. I used print statements for each to see if they were using table space and then set them to nil and they then show nil in the print statements. Do I have to use dispose()? I assumed if they are nil then I was safe. [import]uid: 14935 topic_id: 9010 reply_id: 33183[/import]
No, that won’t work (for now). You must call dispose() to free the sounds or you will leak. This is most likely your problem. This is all documented in that AudioNotes page I pointed you to.
The old and new audio systems are completely different and don’t share any code.
One reason we haven’t done the nil thing is we were worried about memory pressure. If we wait to rely on Lua’s garbage collector, the audio may not be cleaned up when you need it, hence the explicit dispose. Since audio tends to eat lots of memory, we wanted to play it safe to start with and will experiment with gc down the road.
A separate reason is that getting this right is actually hard. There are corner cases where you can nil the reference, but the audio is still being used internally (to play). And then in the completion callback, the reference must be resurrected and potentially you could play the sound again. These problems are not insurmountable, but we wanted to spend the time to implement it correctly the first time because if we don’t implement it correctly, it will cause massive headaches (unexpected crashes) for everybody.
[import]uid: 7563 topic_id: 9010 reply_id: 33186[/import]
Ok. I finally got a chance to work on it and switched all the sound back over to audio.loadSound/audio.play. Then I added audio.stop and dispose and it works fine. Thanks for the help. [import]uid: 14935 topic_id: 9010 reply_id: 33644[/import]
A further confirmation that all is good: I finally got around to testing this in my own game and the sound worked fine. I held my iPhone in my hand and tapped the screen occasionally to keep it from falling asleep. The theme music played continuously for 40 minutes before I turned it off. [import]uid: 12108 topic_id: 9010 reply_id: 33834[/import]
Hi there,
I’m still having problems with this. After 5-10 minutes of gameplay, some sound effects stop playing while others continue. I thought maybe I was using all channels as one sound effect is being called a lot at this point in the game; however, they continue to end and to be played again. Other sound effects do not play when this one sound effect is not playing, either.
Disposing the sound effects is not an option for me as I want to continue using all sound effects for the life of the program. Am I missing something?
I am using loadSound and there are no fades or volume changes on any channel. Any help is appreciated -
Nick [import]uid: 7472 topic_id: 9010 reply_id: 34299[/import]
Make sure you read the AudioNotes page.
Do not call loadSound more than once for a file since you are not disposing it.
If this is not working, check the number of free channels before playing to make sure you are not out of channels. Check the return value of audio.play to make sure it actually played on a channel.
[import]uid: 7563 topic_id: 9010 reply_id: 34344[/import]