1
votes

I've been working on using OpenSL for a low latency audio app for Android. So far the lowest latency I've managed to achieve is 200ms on a Samsung Galaxy S5 (touch-to-sound, measured by tapping and recording tap sound followed by app sound). I think I can bring it down to 160ms by improving some internal app logic. Right now there is upto 40ms of delay between the app receiving the touch and getting the callback for that audio. I think this is because I'm constantly queueing empty buffers when there is no audio. Is this bad practice? I get audio artifacts though when I try approaches that only queue when there is audio for some reason.

Anyway, my question is, what is the lowest achievable latency using openSL from touch to audio output on any of the newest Android devices? (I know it differs from device to device, but I was wondering what is the best device for low latency if there is one, and what is the value of this lowest latency? or perhaps the average obtainable minimum for recent devices?).

Android: sound API (deterministic, low latency)

The above link from about a year ago states that it is around the 180ms range. Is this still the lowest possible for OpenSL? The recommended answer says that Music Synthesizer for android obtains a "total output latency" of under 30 ms. But when I run it on a Samsung Galaxy S5 it has a touch to sound latency of 200ms. What is that "total output latency" referring to? Am I missing something?

How do I decrease the latency further?

Thanks for any help you can give me!

Edit: I'm doing everything stated here Low-latency audio playback on Android except NEON or SSE instructions but my processing time is less than the 15% stated there so that shouldn't be a problem. I am enqueuing a buffer with 2*PROPERTY_OUTPUT_FRAMES_PER_BUFFER shorts for stereo sound. Is that too high?

2
This question is likely to attract anecdotal answers based on personal experiences with a limited set of devices, rather than definitive answers that are demonstrably right or wrong. Therefore it doesn't really seem suitable for StackOverflow since this isn't a discussion forum. Anyway, those numbers you quote sound a bit high. Using the same method of measuring I got times under 100 ms on an XPeria Z when I was running latency tests about a year and a half ago.Michael
Using openSL? Is there some fast mode I have to activate? I am using the simplebufferedqueueplayer with (PROPERTY_OUTPUT_FRAMES_PER_BUFFER * 2) shorts in the buffer that is enqueued and PROPERTY_OUTPUT_SAMPLE_RATE for the audio data as well as the player. I'm using stereo sound that's why the * 2 for the number of shorts. The only thing I can think of that I'm not doing is using NEON or SSE instructions, but my processing time is less than 15% of the playback time and the delay is still high.Faraz Sherwani

2 Answers

3
votes

It seems the device I am testing on, the Galaxy S5 does not have android.hardware.audio.low-latency. Which means that openSL cannot use fast track with it and will result in high latency. This is really surprising because the device is pretty new so it should support a new feature such as this. But despite doing everything required to have low latency in my app, it will have high latency on the device I am testing on.

From the android ndk openSL docs: "These improvements are available via OpenSL ES for device implementations that claim feature "android.hardware.audio.low_latency". If the device doesn't claim this feature but supports API level 9 (Android platform version 2.3) or later, then you can still use the OpenSL ES APIs but the output latency may be higher. The lower output latency path is used only if the application requests a buffer count of 2 or more, and a buffer size and sample rate that are compatible with the device's native output configuration."

For anyone wondering if your app is the problem. Be sure to check if the device you are testing on supports this feature. Also check out the Performance section of the (ndk)/docs/opensles/index.html and the links in the question

0
votes

There is an audio-echo sample, you may check it out to see if it helps. When you create a player for fast audio, certain signal processing interfaces are not supported; if you request for un-supported interfaces, fast audio will be off even you are asking with device default sample rate. The sample works on android L and M [ not tested on others ]