title: Low-latency audio playback on Android
body: <p>I'm currently attempting to minimize audio latency for a simple application:</p>
  
  <p>I have a video on a PC, and I'm transmitting the video's audio through RTP to a mobile client. With a very similar buffering algorithm, I can achieve 90ms of latency on iOS, but a dreadful ±180ms on Android.</p>
  
  <p>I'm guessing the difference stems from the <a href="http://code.google.com/p/android/issues/detail?id=3434">well-known</a> latency <a href="http://audioprograming.wordpress.com/2012/12/02/an-update-on-the-latency-issue/">issues</a> on Android.</p>
  
  <p>However, after reading around for a bit, <a href="http://createdigitalmusic.com/2012/07/android-high-performance-audio-in-4-1-and-what-it-means-plus-libpd-goodness-today/">I came upon this article</a>, which states that:</p>
  
  <ol>
  <li><p>Low-latency audio is available since Android 4.1/4.2 in certain devices.</p></li>
  <li><p>Low-latency audio can be achieved using <a href="http://libpd.cc/">libpd, which is Pure Data library for Android</a>.</p></li>
  </ol>
  
  <p>I have 2 questions, directly related to those 2 statements:</p>
  
  <ol>
  <li><p>Where can I find more information on the new low-latency audio in Jellybean? <a href="http://developer.android.com/about/versions/jelly-bean.html">This is all I can find but it's sorely lacking in specific information</a>. Should the changes be transparent to me, or is there some new class/API calls I should be implementing for me to notice any changes in my application? I'm using the AudioTrack API, and I'm not even sure if it should reap benefits from this improvement or if I should be looking into some other mechanism for audio playback.</p></li>
  <li><p>Should I look into using libpd? It seems to me like it's the only chance I have of achieving lower latencies, but since I've always thought of PD as an audio synthesis utility, is it really suited for a project that just grabs frames from a network stream and plays them back? I'm not really doing any synthesizing. Am I following the wrong trail?</p></li>
  </ol>
  
  <p>As an additional note, before someone mentions OpenSL ES, <a href="http://mobilepearls.com/labs/native-android-api/ndk/docs/opensles/">this article makes it quite clear that no improvements in latency should be expected from using it</a>:</p>
  
  <blockquote>
    <p><em>"As OpenSL ES is a native C API, non-Dalvik application threads which
    call OpenSL ES have no Dalvik-related overhead such as garbage
    collection pauses. However, there is no additional performance benefit
    to the use of OpenSL ES other than this. In particular, use of OpenSL
    ES does not result in lower audio latency, higher scheduling priority,
    etc. than what the platform generally provides."</em></p>
  </blockquote>