For the lowest audio latency possible, we recommend you use Android native audio based on OpenSL ES 1.0.1.
To use Android native audio:
Download and install the
In the rest of this document, we'll assume
NDKrootis the directory where you installed NDK.
- Read the supporting documentation.
- Check for API level 9 or higher.
- Check for feature android.hardware.audio.low_latency.
Use the recommended native buffer size and sample rate returned by
Note: the same buffer size and sample rate should also be used for input.
- Usually an OpenSL ES buffer count of 1 is sufficient.
- 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.
OpenSL ES 1.0.1
Use a PDF viewer to review the OpenSL 1.0.1 Specification. This is a rather long reference, and not all of it will be relevant to you; but you will need to consult it for details on the API.
Note: this document describes the full OpenSL ES 1.0.1, but Android native audio is actually based on a subset of OpenSL ES 1.0.1 with some Android-specific extensions.
Documents describing later versions of OpenSL ES, such as 1.1, are not relevant to Android.
OpenSL ES for Android
The document "OpenSL ES for Android" is provided in the NDK installation, and is not currently available online. Open this link in a browser:
You'll want to skim the whole document, but pay special attention to the "Performance" subsection of the "Programming notes" section.
Section "Supported features from OpenSL ES 1.0.1" describes the subset supported by Android.
Section "Android extensions" describes Android-specific extensions that aren't included in base OpenSL ES 1.0.1.
Relationship with OpenSL ES 1.0.1
This Venn diagram shows the relationship between Android native audio and OpenSL ES 1.0.1.
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.
If you have questions about how to use Android native audio, you can ask at the discussion group android-ndk.
- 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.