MP3 Decoding on Android
- by Rob Szumlakowski
Hi. We're implementing a program for Android phones that plays audio streamed from the internet. Here's approximately what we do:
Download a custom encrypted format.
Decrypt to get chunks of regular MP3 data.
Decode MP3 data to raw PCM data in a memory buffer.
Pipe the raw PCM data to an AudioTrack
Our target devices so far are Droid and Nexus One. Everything works great on Nexus One, but the MP3 decode is too slow on Droid. The audio playback starts to skip if we put the Droid under load. We are not permitted to decode the MP3 data to SD card, but I know that's not our problem anyways.
We didn't write our own MP3 decoder, but used MPADEC (http://sourceforge.net/projects/mpadec/). It's free and was easy to integrate with our program. We compile it with the NDK.
After exhaustive analysis with various profiling tools, we're convinced that it's this decoder that is falling behind.
Here's the options we're thinking about:
Find another MP3 decoder that we can compile with the Android NDK. This MP3 decoder would have to be either optimized to run on mobile ARM devices or maybe use integer-only math or some other optimizations to increase performance.
Since the built-in Android MediaPlayer service will take URLs, we might be able to implement a tiny HTTP server in our program and serve the MediaPlayer with the decrypted MP3s. That way we can take advantage of the built-in MP3 decoder.
Get access to the built-in MP3 decoder through the NDK. I don't know if this is possible.
Does anyone have any suggestions on what we can do to speed up our MP3 decoding?
--
Rob Sz