Hello everyone, I am developing a game using NDK and I am using the SoundPool to manage the sounds aspect. Recently I've hit a rather unpleasant phenomenon. In my code sounds are related to events, and most of them are loops which are started at a touch event and stopped when the touch is over, this is an example. All sound ids for SoundPool are loaded prior to using them only once, then when a sound is needed I call the Play method in the SoundPool class. Sometimes I have a very large amount of Play/Stop pairs, for example when quickly tapping a fire button, which would otherwise just keep looping a machinegun if the finger would stick to the screen. As far as I've read in the reference, the Stop method called on a stream ID should cleanup the native memory needed for the process. Problem is after some 20-30 Play/Stop pairs, every call of Play raises this error and the sound does not play.
03-05 15:52:14.912: ERROR/AudioTrack(3991): AudioFlinger could not create track, status: -12 03-05 15:52:14.912: ERROR/SoundPool(3991): Error creating AudioTrack 03-05 15:52:15.073: ERROR/AudioFlinger(52): not enough memory for AudioTrack size=79860 03-05 15:52:15.073: DEBUG/MemoryDealer(52): AudioTrack (0x17718, size=1048576) 03-05 15:52:15.073: DEBUG/MemoryDealer(52): 0: 00015958 | 0x00000000 | 0x00003940 | F 03-05 15:52:15.073: DEBUG/MemoryDealer(52): 1: 00012dc0 | 0x00003940 | 0x00003040 | A .... more stuff here... 03-05 15:52:15.073: DEBUG/MemoryDealer(52): 17: 000137a0 | 0x000DD820 | 0x0000DE20 | A 03-05 15:52:15.073: DEBUG/MemoryDealer(52): 18: 00013940 | 0x000EB640 | 0x0000DE20 | A 03-05 15:52:15.073: DEBUG/MemoryDealer(52): 19: 00013af8 | 0x000F9460 | 0x00006BA0 | F 03-05 15:52:15.073: DEBUG/MemoryDealer(52): size allocated: 957344 (934 KB) I get a valid stream id from play but the sound never shows up. If I stop the sound requesting after some time the sound would play again, like some memory has been freed up in the meantime, but with little Play/Stop calling I hit the out of memory warning again. I've even added an extra Stop on streams every time I pick up play (stream ids are related to sound ids in a data structure, usually I don't have more then one stream ID per sound ID) to no resolve. It just seems the AudioPool is not really cleaning stuff up when the Stop is called, but rather lately and the SoundPool just runs out of memory for playing new streams, although the number of streams should be constant from my code. I find this quite annoying because all the sounds are loaded only once. If I get out of mem because of the overhead generated by 50 Play/Stop requests for different sounds something is wrong. I've searched the web for similar behavior but I could not find anything regarding this issue. I don't see any way to rewind a stream and don't just call Stop/Play over again. I haven't yet tried to do a full release() from time to time, but this solution doesn't strike me as very good one, I am not very keen on reloading 12 sound files every 40 Play requests during gameplay. I've checked they I always call stop for started streams before calling a new play for the same sound id, also the fact that sounds recover after some time seems to point that the issue is not in my code. I would expect issues to be permanent if I had any kind of leaks regarding sound streams. Any suggestion would be highly appreciated. Andrei -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

