Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AAudio or OpenSL

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?

like image 739
Hug Avatar asked May 03 '17 08:05

Hug


People also ask

Which is better OpenSL ES vs audiotrack?

With OpenSL ES you code everything in Native library and does not need calling Java layer for Audio, which adds some performance advantages in Gaming. And it is more Platform independent than any other API in Android.

What is OpenSL on VLC?

OpenSL ES (Open Sound Library for Embedded Systems) is a royalty-free, cross-platform, hardware-accelerated, C-language audio API for 2D and 3D audio. It provides access to features such as 3D positional audio and MIDI playback.

What is OpenSL audio?

The OpenSL ES™ standard exposes audio features similar to those in the MediaPlayer and MediaRecorder APIs in the Android Java framework. OpenSL ES provides a C language interface as well as C++ bindings, allowing you to call the API from code written in either language.

What is AAudio in Android?

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


2 Answers

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.

like image 91
Over17 Avatar answered Sep 21 '22 17:09

Over17


If you need a native audio interface for Android then we currently recommend using Oboe. Oboe calls AAudio on newer devices and OpenSL ES on older devices. The Oboe API is a direct mapping of the C AAudio interface into C++.

Oboe includes workarounds for various Open SL ES issues on different Android platforms.

Source is available on GitHub and is actively developed.

https://github.com/google/oboe

like image 28
philburk Avatar answered Sep 20 '22 17:09

philburk