2

I am using a SoundPool to load several sound clips into and play them back.

It is functioning 100% correctly from what I can tell. But during the .load() calls I am getting my log spammed with:

06-09 11:30:26.110: ERROR/AudioCache(23363): Heap size overflow! req size: 1050624, max size: 1048576

I am loading in 11 sound files, of those 2 are very small ~3kb and the rest are between 10kb - 15kb. Windows is reporting

Size: 114kb

Size on disk: 128kb

Am I pushing the limits of what SoundPool is capable of holding? Is there some setting I should be altering to avoid this overflow? Any guidance on how I should be setting up my audio controls would be much appreciated.

trincot
  • 317,000
  • 35
  • 244
  • 286
FoamyGuy
  • 46,603
  • 18
  • 125
  • 156
  • SoundPool is fairly bug ridden. Even though you're working with relatively small sound files, you're better option is to still use MediaPlayer. – Brian Jun 09 '11 at 16:51
  • 1
    You can use multi SoundPool instances to prevent the heap size error. You can find more detail from http://stackoverflow.com/a/15331311/1124084 – andyao Mar 11 '13 at 04:48

2 Answers2

3

SoundPool is going to decompress the loaded audio to PCM data so it is ready to play instantly without the latency of decoding. If the audio you are loading is compressed heavily, such as MP3, then that can get blown up quite a bit. Try encoding the audio as mono if stereo isn't necessary (it usually isn't for short sound effects).

Douglas Jones
  • 2,522
  • 1
  • 23
  • 27
0

SoundPool has 1Mb buffer size limit per track. But this limit applies not to file size but to decompressed raw PCM data.

I suggest to use SoundPoolCompat from 3d party library. It has similar api to SoundPool, but has custom buffer size, all data within that buffer will be loaded into memory and played with small latency like SoundPool does. All data that exceed that buffer size will be loaded on demand (which adds latency, similar to MediaPlayer). But it will not crash nor play data that's only fits buffer size like SoundPool. Also buffer size is expressed in file size not in decompressed data size. Which is more convenient to api user.

implementation 'com.olekdia:sound-pool:3.2.0'

https://gitlab.com/olekdia/common/libraries/sound-pool

Oleksandr Albul
  • 1,611
  • 1
  • 23
  • 31