Android high performance game audio with oboe header
Android high performance game audio with oboe header


Written by Dan Galpin

High performance game audio with oboe graphics

We added the Oboe C ++ audio library to the Android Game SDK. Oboe’s support for high-performance, low-latency audio across a wide variety of Android devices is the right choice for most game developers.

Single API

On Android devices running Android 8.1 (API level 27) and above, Oboe takes advantage of the improved performance and features of AAudio while maintaining backward compatibility (with OpenSL ES) with Android 4.1 (API level 16) and above. In addition to the platform APIs, Oboe adds key features to enhance the audio developer’s experience, such as: B. resampling, format conversion and dynamic latency optimization. It performs audio data transformations if necessary, e.g. For example, channel count conversion to improve performance on select devices, and provides workarounds for other device-specific behaviors that improve the robustness of your audio code. In short, oboe is now the recommended method for writing audio code in C / C ++ on Android.

Integrate oboe

There are two ways to incorporate oboe library prebuilts into your project. If you are using the Android Gradle plugin version 4.1.0 or higher together with CMake and can use or enable shared STL, enabling oboe is as easy as adding oboe to your gradle dependencies, enabling prefabs, and that Add a few lines to your CMakeLists file.

You can also integrate oboe by statically linking using the Android Game SDK. First, download the library and check it into your version control system. You must use minSdkVersion 16 or higher with NDK Release 18 or higher. Then add a compiler include path in the following form to indicate the version of the game SDK to be linked that was compiled for the specified combination of ABI, API level, NDK, and STL:

gamesdk/libs/[architecture]_API[apiLevel]_NDK[ndkVersion]_[stlVersion]_Release
Example: gamesdk/libs/arm64-v8a_API24_NDK18_cpp_static_Release

Then add -loboe_static to your linker command. Since you don’t have to bundle the shared library liboboe.so, you get a smaller code footprint through static linking. Alternatively, if a precompiled version for your settings is not available for the combination of ABI, API level, NDK and STL, you can link to the shared library. For more guidance, including configuring CMake for static libraries, see our developer documentation.

Oboe basics

To output audio, first create a stream with the necessary properties, including a callback that is used when the stream needs new data.

oboe::AudioStreamBuilder builder;
builder.setPerformanceMode(oboe::PerformanceMode::LowLatency) ->setSharingMode(oboe::SharingMode::Exclusive) ->setDataCallback(myCallback) ->setFormat(oboe::AudioFormat::Float);

Then fill in the audio in the callback. If the stream was created successfully, it means you received the type of stream you requested. If you haven’t specified these types, you’ll need to query to see what format was returned.

class MyCallback : public oboe::AudioStreamDataCallback {
public: oboe::DataCallbackResult onAudioReady(oboe::AudioStream *audioStream, void *audioData, int32_t numFrames) { // We requested AudioFormat::Float auto *outputData = static_cast<float *>(audioData); // TODO: populate audioData here return oboe::DataCallbackResult::Continue; }
};

For detailed information on using the oboe, see Read the documentation, code samples, and API references. There’s even a codelab that shows you how to create a simple rhythmic game.

If you have any problems, please submit them here. We’d love to hear from you.



LEAVE A REPLY

Please enter your comment!
Please enter your name here