Question

I use OpenSL for recording and playing audio on Android. Could you please advice me how to measure latency, in order to find the optimal audio configuration (buffers, sample rate).

Thank you in advance!

Was it helpful?

Solution

Here's how I used to measure audio output latency:

  • Create a simple UI for your app with one or more buttons that play sounds when you press them. I'd suggest using sounds with near-instantaneous attack (i.e. ones that reach full amplitude very quickly).
  • Turn the volume up on your Android device and hold it near the microphone of some other device (e.g. your PC or another phone).
  • Use your app to play some sounds by tapping the buttons. Tap them hard enough so that the tap itself is clearly audible.
  • Record all this on the second device.
  • Once you're done, open the recording in a sound editor (e.g. Audacity) and measure the distance (i.e. the time) between the tap sounds and the resulting playback. You may want to take the average or median of several such distances.

This way of measuring has the upside that it's very easy to perform. The downside is that your result will include the touch latency as well. With touch events being generated at 60 Hz this would mean that you could get anywhere up to around 16 ms of extra latency in addition to the audio output latency. This makes it pretty much impossible to measure very small latency differences using this method.


Update: In an message board post by Glenn Kasten of Google he linked to a couple of pages that describe more accurate ways of measuring audio latency. I figured I could add them here for reference. Here's the page that describes measuring round-trip latency, and here's another page that describes measuring only the output latency.

OTHER TIPS

Have you tried this app to measure it? https://play.google.com/store/apps/details?id=com.levien.audiobuffersize The app was created by Raph Levien from Google, and he is creating a database with the results in http://audiobuffersize.appspot.com/ (as you can see, there are many results there already) It is a pretty quick test that calculates the best buffer size and sample rate for your device and the lowest latency achieved. From where I think that if a lot of users upload their results, we'll be able to tell how many/which devices are ready for low latency audio...

Another very good way of testing this is also to use the LED interface that is available through OpenSL|ES. Using this (and with the aid of a LDR) you can record the time between the led coming on and the sound being emitted.

This is one of the methods the google folks used when doing this for their own devices. They go into this, and lots more on the subject of low latency audio in android, in this video.

Adding to @Michael's method or finding out output latency, If you are interested in round trip delay i.e. record to play. Then

1) simply run a simple audio loopback application (make sure the buffersizes and queing is done properly).

2) keep the volume preferably low to avoid feedback echo, but the eccho should still be there and audible

3) now record the output through a different mic (PC) and make a tapping sound, like snapping your fingers

4) import the audio from the second mic(PC) to goldwave or audacity and measure the latency between the snap and the snap played out from device

this will be your round trip delay

Though im replying late, Hope this helps

REgards, Shrish

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top