Oct 8th update: The 2.3.5 update for SGS2 seems to fix the problem. At least I can’t reproduce the problem anymore. I don’t know how quickly the update will roll out for all the different versions of the phone and in different regions, but if the problem indeed has been fixed, it might not be worth the trouble to work around it. Unless of course you get other benefits from OpenSL.
I received feedback in June about DiceShaker D&D crashing on the then new Samsung Galaxy S2. After finally getting a proper excuse to buy one, I was quickly able to reproduce the problem. Looking at the stack trace produced by the crash, it seemed to be caused by SoundPool.
I/DEBUG (20675): *** *** *** *** *** *** *** *** *** *** *** I/DEBUG (20675): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad I/DEBUG (20675): #12 pc 000046ae /system/lib/libsoundpool.so
SoundPool is one of the available options for playing sounds in an Android application, perhaps the best / easiest to use for game sound effects. Googling “galaxy s2 soundpool” I found out that other app developers had also had the same problem reported, and made the same conclusion about the cause. The problem had been reported to the Andoid bug tracker on June 13th. Reducing the number of audio channels used seemed to gradually make the SoundPool crashes less frequent, but I couldn’t get completely rid of the problem until reducing the channels to one. That didn’t sound like a good solution, so I temporarily excluded the SGS2 from the supported devices list, and hoped that Samsung/Google would fix the problem shortly – it was constantly crashing even high profile titles like Cut the Rope (on Gift Box levels), so it might get some priority.
Three months after the bug had been reported, Samsung released Android 2.3.4 for the SGS2. The problem was still there. Some comments on the bug tracker claim the problem exists also on the leaked 2.3.5 update. Researching better workarounds for the problem I came across Gray Fin Studios’ account on how they fixed the problem using OpenSL ES. OpenSL ES is a native audio library introduced in Android 2.3, and while it wouldn’t work on older devices, one could make their app automatically use it if it was available and fall back to SoundPool on older OS’es, which didn’t have the problem. After reading about Gray Fin’s positive experiences with OpenSL ES, I quickly hacked together a simple SoundPool’esque audio implementation on top of it.
Some quick initial testing seems to agree with Gray Fin’s findings. SoundPool usually crashes after playing some random samples in a loop for less than a minute, the OpenSL seems not to. The OpenSL implementation is limited at the moment, but may perhaps be of some use if you’ve just started looking into workarounds. It’s source code is available at http://code.google.com/p/opensl-soundpool.
I haven’t considered fragmentation a huge problem for Android so far, but I think this is a good example of the kind of problems the huge amount of different makes and models can bring. Until last spring SoundPool was a proper choice for producing sound effects in an Android app, then someone releases a device on which it doesn’t work and sells 10 million units of the said device in 5 months, and suddenly you just can’t use that part of the Android API anymore.
The following handset share statistics from a Finland-only-app CallerInfo kind of underlines the point about having to support Galaxy S2 – it’s already huge (SGS2 has been available here since April).