开发者

and again about memory issues with SoundPool

I am aware that SoundPool was intended to handle small f开发者_Go百科x 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)


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)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜