title: MP3 Decoding on Android
body: <p>We're implementing a program for Android phones that plays audio streamed from the internet.  Here's approximately what we do:</p>
  
  <ol>
  <li>Download a custom encrypted format.</li>
  <li>Decrypt to get chunks of regular MP3 data.</li>
  <li>Decode MP3 data to raw PCM data in a memory buffer.</li>
  <li>Pipe the raw PCM data to an AudioTrack</li>
  </ol>
  
  <p>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.</p>
  
  <p>We didn't write our own MP3 decoder, but used MPADEC (<a href="http://sourceforge.net/projects/mpadec/" rel="nofollow noreferrer">http://sourceforge.net/projects/mpadec/</a>).  It's free and was easy to integrate with our program.  We compile it with the NDK.</p>
  
  <p>After exhaustive analysis with various profiling tools, we're convinced that it's this decoder that is falling behind.</p>
  
  <p>Here's the options we're thinking about:</p>
  
  <ol>
  <li><p>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.</p></li>
  <li><p>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.</p></li>
  <li><p>Get access to the built-in MP3 decoder through the NDK.  I don't know if this is possible.</p></li>
  </ol>
  
  <p>Does anyone have any suggestions on what we can do to speed up our MP3 decoding?</p>
  
  <p>--
  Rob Sz</p>