Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Oboe, a Library for Low Latency Audio Apps on Android

Oboe, a Library for Low Latency Audio Apps on Android

Leia em Português

This item in japanese

Google has released the first production-ready version of Oboe. Oboe is a C++ library for building high performance audio apps on Android, providing the lowest latency possible across 99% of Android devices.

Developers who need to build musical games, audio apps, etc, usually have to deal with latency issues. Oboe aims to address latency issues by providing a simple API that is compatible with API 16+ (Jelly Bean). Under the hood, Oboe takes advantage of the performance and features of AAudio on API 27+ (Oreo MR1) and uses OpenSL ES on API 16+.

AAudio is an Android C API designed for high-performance audio applications that require low latency. It has been introduced in the Android O. Apps communicate with AAudio by reading and writing data to streams.

OpenSL ES on Android is a specific implementation of the OpenSL ES API specification from the Khronos Group. As well the AAudio, this library is designed for high-performance audio applications that require low latency. In addition, OpenSL ES exposes audio features similar to those in the MediaPlayer and MediaRecorder APIs.

To start using Oboe, Android NDK r17 or above is needed. It can be installed via Android Studio SDK manager, or via direct download.

After installed Android NDK r17 or above, clone the GitHub repo and add the following commands to the end of CMakeLists.txt (if you don't have this file, you should add C++ support to the project) file.

cmake_minimum_required(VERSION 3.4.1)

# Build our own native library
add_library (native-lib SHARED src/main/cpp/native-lib.cpp )

# Specify the libraries which our native library is dependent on, including Oboe
target_link_libraries (native-lib log oboe)

# Build the Oboe library
set (OBOE_DIR ../../../oboe)  
add_subdirectory (${OBOE_DIR} ./oboe) 

# Make the Oboe public headers available to our app
include_directories (${OBOE_DIR}/include)

Developers can create an audio stream with a few lines in Oboe:

AudioStreamBuilder builder;
AudioStream *stream = nullptr;
Result result = builder.openStream(&stream);

More details can be found on the documentation, API reference and code sample pages. Furthermore, there is also a codelab where you can build a simple musical game using Oboe; the objective of the game is to copy the clapping pattern you hear by tapping on the screen.

Rate this Article