AAudio or OpenSL

Hug picture Hug · May 3, 2017 · Viewed 8.9k times · Source

I'm starting to implement my gaming audio part in C++, and I've seen there're 2 audio frameworks available AAudio (https://developer.android.com/ndk/guides/audio/aaudio/aaudio.html) and OpenSL (https://developer.android.com/ndk/guides/audio/opensl/index.html).

Which are the differences between those two?

Answer

Over17 picture Over17 · Jun 9, 2017

OpenSL ES

OpenSL is supported by devices starting from Android 2.3 (Gingerbread). However, the fast mixer for OpenSL (high performance audio) is available since Android 4.2 (or 4.3?), and is not natively supported by all devices.

What does it mean? Based on my observations, when fast mixer is not used, Java AudioTrack is faster (has lower latency) than OpenSL.

When the fast mixer is used, the audio latency is actually nice and low. To make it happen, your device has to support the fast mixer, and the configuration params should match.

Another issue to consider is "crackling" on GearVR, probably because of thread priorities changed.

To implement your audio with OpenSL, you may want to refer to the NDK samples, or even better here https://github.com/Over17/AndroidAudioFastPathSample - it is fixed to actually use the fast path.

AAudio

Will be supported on Android 8 Oreo, which will be released some time this year. Unless you don't want your game to be compatible with Android O only, you probably don't want to go this way.

I don't have much hands on experience with it yet.

Oboe

Oboe is a library developed by Google which uses AAudio or OpenSL as the backend depending on what's supported by the device, and has a C++ interface that wraps the APIs. It makes sense to use it instead of using AAudio directly.

Motivation

Why do you really want a native audio part for your game? If it's not a synthesizer, a professional audio application or a VR game, I would really not bother with the native C++ audio and go for JavaAudioTrack. It's reliable, compatible with all devices and has acceptable latency for non-pro applications.