Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to measure audio latency using OpenSL on Android?

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!

like image 275
Taras Avatar asked Dec 06 '22 06:12

Taras


1 Answers

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.

like image 51
Michael Avatar answered Dec 23 '22 16:12

Michael