Google Android 1.0 API: Great Architecture but Short on Sound

The Android API is very well designed with regards to application integration and general mobile use.  I think google did an awesome job with the architecture.  The Activity/Intent/Application model is very well though out and allows for some nice "piggybacking" of one app onto another for extended functionality.  I like the layouts and views a lot.  They gave us a SurfaceView to do double-buffering of drawable area on screen and they even gave us an OpenGL 1.3 implementation.  What about sound?  The Android sound API seems to have taken a back burner for the latest 1.0 release.

For one, the only officially supported wave-playing interface is the MediaPlayer.  MediaPlayer can play one piece of media at a time.  There is a limit of 10 media player instances.  New instances take time to load and prepare the media.  This means all in all, you are limited to 10 pieces of disk-based media pre-loaded at any given time.  Let's say for example that you have a racing game, like Light Racer and you have 4 cars driving at the same time (so 4 media players) but at any given time you may need to play up to 4 concurrent explosions (let's say they all hit each other simultaneously) and you have a music track and an announcer.  That's all 10 right there and we didn't even take into account any other noises.

So why not just create a media player on-demand as you need to play a sound?  Quick answer: it takes too long to load.

What about writing your own audio handler and feeding the bytestream of audio to the soundbuffer or directly to the audio device?  Unlike DirectSound or any other game-sound API, there is no such thing.  The implications of this are that you can do no sound synthesis (no really good virtual-instrument apps, voice disguisers, etc).  You also can not mix sounds, put effects on them (like echo in a room) or any of that.  

This very limited API means that the only way to have semi-rich sound in a game is to have lots of sound samples that comprise most of the scenarios the game may come across and have very tight management of which mediaplayers are ready to go.  This means very large APKs and difficulty coding.

And what about engine noises or players running at variable rates?  It will all have to be hacked into presampled sounds that sound like the engine is revving up even though it doesn't truly match what the engine is doing.  These are the types of things that make games feel cheap - when sound and video don't seem to really match up accurately.

There is a class in android that looks like it was written specifically to support games.  It's not a direct interface to the audio byte stream like we would all really love to have, but it is a sound pool capable of changing sampling rates on the fly and playing multiple concurrent sounds in its own streams.  The class, obviously enough, is called SoundPool.  I used it when writing Light Racer but it's very, very fragile and has no documentation.  It mostly works but tends to lock up the device sometimes.  I'm very let down that the developers didn't just polish this off and offer it in SDK 1.0.  For my game and I'm sure many others, its design is adequate and is far better than MediaPlayer, which is absolutely not suited well for games.

Unfortunately now I have to switch to MediaPlayers for v1.1 of my game because too many people are reporting crashes with SoundPool.  This is going to have a negative impact on the overall game experience as I have to limit the way the motors sound and it will increase the complexity of my code.  

I can't imagine it would have been very difficult to provide a directsound-like API in Android 1.0 and I'm very let down by the fact that it wasn't done.  The iPhone has many interesting audio apps - none of which will be available on the android because it's just not possible right now.

I'm just hoping the design teams make sound a priority in Android 1.1.


Post a comment here or discuss this and other topics in the forums

Very nice!

I'm so happy they finally added the AudioTrack class. Now we can finally have virtual kazoos!

Sound on Cupcake

Cupcake 1.5 hooks the sound up. Check out our notes on our blog.