Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

and again about memory issues with SoundPool

I am aware that SoundPool was intended to handle small fx like sounds and I made sure my 4 sound clips which I want to play one by one in some sequence are small enough.

I used ogg quality 0 and clips are 35kb, 14kb, 21kb and 23kb totaling 92kb of compressed audio. I have no idea how to estimate what the uncompressed size would be, but it should not be a lot, right?

So when I play 4 sounds in sequence, it works well for first 9 times (9 sequences x 4 sounds) but starts to cause memory issues on the nines sequence for one of the sounds. It is always sequence 9 when I start to see error.

What is the best way to handle that? I have a few ideas:

1) compress sounds even more (ogg quality -1 and mono instead of stereo)

2) unload and load sounds constantly using SoundPool.load and SoundPool.unload

3) release and recreate soundPool instance time from time

Is there anything else I can do? It is embarrassing that android api cannot handle so small clips. I wonder how people create games with a lot of sound effects...

Errors look like that:

ERROR/AudioFlinger(35): not enough memory for AudioTrack size=1048640 DEBUG/MemoryDealer(35): AudioTrack (0x25018,size=1048576)

like image 725
mishkin Avatar asked Nov 05 '22 07:11

mishkin


1 Answers

It seems I was able to resolve my issue after:

1) downsampled my sound clips from 44 to 22khz. Uncompressed size was cut in half (I figured how to estimate uncompressed sound size - export your clip to uncompressed wav). I used nice open source tool Audacity

2) trim the sounds more to reduce duration

3) put try/catch around play() just in case (it does catch errors when it try to play the sound but cannot)

like image 162
mishkin Avatar answered Nov 11 '22 10:11

mishkin