Home » Android » How to use Android audio with low latency

How to use Android audio with low latency

Posted by: admin June 15, 2020 Leave a comment

Questions:

Problem:

As you might have heard, Android does not provide with low latency audio API. What I mean by low latency audio is that you should be able to get audio signals from microphone and play the sound without much time gap in-between (e.g., 5-7 ms)

I’ve tried old java (with AudioRecord and AudioTrack) and “new” OpenSL ES. They are terrible and make app unusable.The issue was well documented here. BTW, iOS API can produce about 5-7 ms latency.

Looking for Workarounds:

But I am trying to do the low latency audio anyway. Something like this answer describes.

“However, I was only able to achieve this satisfactorily by writing my
own code that did the mixing internally and accessed the low-level
audio playback API only for playing the final mixed output. The
higher-level ways of playing sounds in the .Net Compact Framework are
theoretically capable of polyphony, but in practice they work horribly
(lots of glitches, stuttering and distortion).”

Does this make sense for Android? An answer is discouraging.

So my question. Is there really no way to achieve 10 ms audio latency with Android?

To be honest, I am not expecting a solution in some time soon but just wish one great mind have answer to this problem.

How to&Answers:

android 4.1+ has low latency audio api which should give you below 10ms latency. however the value varies by hardware (welcome to rich diverse world of android).

also feature descriptor of “android.hardware.audio.low_latency” can be used for filter out devices lacking low latency support.

check out http://www.youtube.com/watch?v=Yc8YrVc47TI&feature=player_de%20tailpage#t=1366s

and this: http://createdigitalmusic.com/2012/07/android-high-performance-audio-in-4-1-and-what-it-means-plus-libpd-goodness-today/

Answer:

There is currently no way to get low latency audio on Android devices without modifying the operating system, and even then a lot of the latency can come from the hardware implementation, so the software can’t fix that. This is sad since the Linux kernel is very capable of <5ms audio latency, and much ARM hardware is capable of decent latency. I had a custom Linux build running on an old Palm TX and that actually had pretty decent latency.

Answer:

as follow up the feature of android.hardware.audio.pro starting in Android 6 promises <20ms round trip times, which we can hope to mean <10ms one-way.