For the lowest possible audio latency, we recommend you use Oboe.
Oboe
Oboe uses native audio and is built
on AAudio for Android 8.1+ and OpenSL ES for older versions of Android. To achieve the lowest
possible latency for a device, set setPerformanceMode(oboe::PerformanceMode::LowLatency)
and setSharingMode(oboe::SharingMode::Exclusive)
.
See the Getting started guide,
README.md
,
and Full guide for more
information on Oboe. Refer to the Soundboard app
for a sample app using Oboe.
Note: If you use AudioTrack
for creating output audio streams in Java for latency sensitive applications, use the PERFORMANCE_MODE_LOW_LATENCY
mode.
Implementation checklist
To use Android native audio:
- Download and install the Android NDK.
- Follow the Getting started guide for Oboe.
-
Call
setPerformanceMode(oboe::PerformanceMode::LowLatency)
andsetSharingMode(oboe::SharingMode::Exclusive)
on the Oboe builder. -
Use the recommended native buffer size and sample rate returned by
android.media.AudioManager.getProperty(java.lang.String).
Note: The same buffer size and sample rate should also be used for input.
- Keep your callback handlers short, without bursty CPU usage or unbounded blocking. Avoid priority inversion.
- Consider using non-blocking algorithms to communicate between input and output callback handlers, and between the callback handlers and the rest of your application.
Other resources
source.android.com
The site source.android.com is primarily designed for OEMs building Android devices, and the SoC vendors who supply components to these OEMs.
However, there is a wealth of useful information about latency at this site, so you may want to review it. See the articles at Audio latency.
android-ndk
If you have questions about how to use Android native audio, you can ask at the discussion group android-ndk.
Report bugs on Oboe
If you have issues using Oboe, you can file a bug.
Videos
- Getting started with Oboe
- Low Latency Audio - Because Your Ears Are Worth It
- Android Dev Summit 2018.
- Winning on Android - How to optimize an Android audio app
- Android Developer Challenge 2018.
- High performance audio on Android (Google I/O 2013)
- The whole video is about latency.
- Building great multi-media experiences on Android (Google I/O 2014)
- The first 14 minutes are about audio in general and input latency in particular.
- Audio latency: buffer sizes (100 Days of Google Dev)
- Describes the relationship between audio latency, buffer sizes, and task scheduling.