Problems with Android Soundpool

I have an application on the Android Market and I use the SoundPool classes for sound effects. I noticed that of all the Android API components, this seems to have caused me most of the problems. For example:

  • HTC Desire has problems playing WAV files (this makes it block randomly). Using .ogg files fixes this.

  • In Droid, if you exceed the number of channels in an initialization call:

mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);

the phone will close. If you can imagine the difficulty in debugging! I don’t own on the phone. This required a lot of disinterested help from my clients. Changing β€œ4” to β€œ16” fixed the problem. I have no doubt that if 16 sounds were heard simultaneously, it would still rattle. Fortunately, the chances are low.

  • Also getting random crashes on different devices. I have a catlog from one of my clients that has heap overflow errors related to playing sounds.

Now I have changed my sound manager to use MediaPlayer. At the moment, it looks normal. I'm just wondering if any other developers are experiencing these problems?

+6
android soundpool
source share
1 answer

It seems that AudioFlinger can play sound up to 1 MB at any given time. Heap errors occur if this limit is exceeded. This assumption is based on some code that I found in the AudioFlinger source code:

 AudioFlinger::Client::Client(const sp<AudioFlinger>& audioFlinger, pid_t pid) : RefBase(), mAudioFlinger(audioFlinger), mMemoryDealer(new MemoryDealer(1024*1024)), mPid(pid) { // 1 MB of address space is good for 32 tracks, 8 buffers each, 4 KB/buffer } 

And this:

 size_t size = sizeof(audio_track_cblk_t); size_t bufferSize = frameCount*channelCount*sizeof(int16_t); if (sharedBuffer == 0) { size += bufferSize; } mCblkMemory = client->heap()->allocate(size); if (mCblkMemory != 0) { ... } else { LOGE("not enough memory for AudioTrack size=%u", size); client->heap()->dump("AudioTrack"); } 

Is anyone even better informed?

+4
source share

All Articles