Starting March 27, 2025, we recommend using android-latest-release
instead of aosp-main
to build and contribute to AOSP. For more information, see Changes to AOSP.
Audio latency for app developers
Stay organized with collections
Save and categorize content based on your preferences.
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)
and setSharingMode(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.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-08-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-08-26 UTC."],[],[],null,["# Audio latency for app developers\n\nFor the lowest possible audio latency, we recommend you use [Oboe](https://developer.android.com/games/sdk/oboe).\n\nOboe\n----\n\n[Oboe](https://github.com/google/oboe) uses native audio and is built\non AAudio for Android 8.1+ and OpenSL ES for older versions of Android. To achieve the lowest\npossible latency for a device, set `setPerformanceMode(oboe::PerformanceMode::LowLatency)`\nand `setSharingMode(oboe::SharingMode::Exclusive)`.\nSee the [Getting started guide](https://github.com/google/oboe/blob/main/docs/GettingStarted.md),\n[`README.md`](https://github.com/google/oboe/blob/main/README.md),\nand [Full guide](https://github.com/google/oboe/blob/main/docs/FullGuide.md) for more\ninformation on Oboe. Refer to the [Soundboard app](https://github.com/google/oboe/tree/main/samples/SoundBoard)\nfor a sample app using Oboe.\n\n**Note:** If you use [AudioTrack](https://developer.android.com/reference/android/media/AudioTrack)\nfor creating output audio streams in Java for latency sensitive applications, use the [`PERFORMANCE_MODE_LOW_LATENCY`](https://developer.android.com/reference/android/media/AudioTrack#PERFORMANCE_MODE_LOW_LATENCY)\nmode.\n\n\u003cbr /\u003e\n\nImplementation checklist\n------------------------\n\nTo use Android native audio:\n\n1. Download and install the [Android NDK](https://developer.android.com/tools/sdk/ndk/index.html).\n2. Follow the [Getting started guide](https://github.com/google/oboe/blob/main/docs/GettingStarted.md) for Oboe.\n3. Call `setPerformanceMode(oboe::PerformanceMode::LowLatency)` and `setSharingMode(oboe::SharingMode::Exclusive)` on the Oboe builder.\n4. Use the recommended native buffer size and sample rate returned by [android.media.AudioManager.getProperty(java.lang.String)](http://developer.android.com/reference/android/media/AudioManager.html#getProperty(java.lang.String)).\n\n **Note:** The same buffer size and sample rate should also be used for input.\n5. Keep your callback handlers short, without bursty CPU usage or unbounded blocking. Avoid [priority inversion.](/docs/core/audio/avoiding_pi)\n6. Consider using [non-blocking algorithms](/docs/core/audio/avoiding_pi#nonBlockingAlgorithms) to communicate between input and output callback handlers, and between the callback handlers and the rest of your application.\n\nOther resources\n---------------\n\n### source.android.com\n\n\nThe site [source.android.com](/)\nis primarily designed for OEMs building Android\ndevices, and the SoC vendors who supply components to these OEMs.\n\n\nHowever, there is a wealth of useful information about latency at this site, so\nyou may want to review it. See the articles at\n[Audio latency.](/docs/core/audio/latency/latency)\n\n### android-ndk\n\n\nIf you have questions about how to use Android native audio, you can ask at the discussion group\n[android-ndk](https://groups.google.com/forum/#!forum/android-ndk).\n\n### Report bugs on Oboe\n\n\nIf you have issues using Oboe, you can\n[file a bug](https://github.com/google/oboe/issues).\n\n### Videos\n\n[Getting started with Oboe](https://www.youtube.com/playlist?list=PLWz5rJ2EKKc_duWv9IPNvx9YBudNMmLSa)\n[Low Latency Audio - Because Your Ears Are Worth It](https://www.youtube.com/watch?v=8vOf_fDtur4)\n: Android Dev Summit 2018.\n\n[Winning on Android - How to optimize an Android audio app](https://www.youtube.com/watch?v=tWBojmBpS74)\n: Android Developer Challenge 2018.\n\n[High performance audio on Android](https://youtu.be/d3kfEeMZ65c)\n(Google I/O 2013)\n: The whole video is about latency.\n\n[Building great multi-media experiences on Android](https://youtu.be/92fgcUNCHic)\n(Google I/O 2014)\n: The first 14 minutes are about audio in general and input latency in particular.\n\n[Audio latency: buffer sizes](https://youtu.be/PnDK17zP9BI)\n(100 Days of Google Dev)\n: Describes the relationship between audio latency, buffer sizes, and task scheduling."]]