5

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)

mishkin
  • 5,932
  • 8
  • 45
  • 64

2 Answers2

2

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)

mishkin
  • 5,932
  • 8
  • 45
  • 64
  • Thanks it works for me. Before that my sound file getting cut. But i have converted and resample that m4a from 44 to 22 and now it works without getting cut. – Shreyash Mahajan Oct 29 '12 at 11:01
0

That seems odd. SoundPool should be expanding your audio clips into memory when it loads them, and once loaded I wouldn't expect you to run into memory issues later. When I've run into memory issues it was right at the beginning, not later on. You sure you're not loading more sounds later on?

To answer your other question, some games use JET Player and MIDI sounds instead of SoundPool. The JetBoy sample program that comes in the Android SDK is a great example of how to do this type of sound work in an app.

Dave MacLean
  • 5,163
  • 2
  • 22
  • 31
  • thanks for response...I tested my app more today and noticed that issue happens with 4 sounds which i loop using soundpool looping. I loaded 17 other clips and they work fine but after my app triggers one of 4 looped ones, it crashes. I do preload all of them when activity created and nowhere else. I downsampled my clips from 44 to 22khz and it helped a bit, but app still crashes with memory issue. – mishkin Nov 05 '10 at 04:06
  • i need to play ogg files so I guess JetBoy is not an option for me but thanks for suggestion – mishkin Nov 05 '10 at 04:07