Reputation: 597
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?
Upvotes: 5
Views: 19522
Reputation: 1071
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.
Upvotes: 5
Reputation: 711
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
Upvotes: 5