New Experimental Android Audio Renderer (OpenAL Soft)

We’ve recently committed a new audio renderer for Android that is based on OpenAL Soft. This new renderer very closely mimics the desktop OpenAL audio renderer so you should now be able to have the same audio effects as desktop like adjusting pitch, setting the reverb and environment, etc. It also supports audio files in the assets.jar file or in the Android project assets directory.

The new audio renderer uses Android’s OpenSL audio implementation, but Android didn’t start including it until Android 2.3 (version 9). Therefore, this new renderer will not work on devices running on Android 2.2, which is the current target for jME3.

Known Issues:

  1. Only wav and ogg audio files are supported (not mp3)
  2. If you stream ogg files, there is a lot of GC going on
  3. Make sure there is no extra data in the audio file like track name, artist, etc… Audio does not play if there is any extra data.

If you feel up to it, you can try it out and let us know if you have any issues. It will remain optional and experimental until after jME 3.0 releases since it will raise the minimum Android version supported by jME3. We also need some time to make sure it is working completely before switch the main audio renderer to this one.

To try it out, you need to do the following:

  1. Update to the latest SVN / Nightly version of the engine
  2. Add the jME3-openal-soft-natives-android.jar library to your android project. It is located in the /engine/lib/openal-soft directory (or the /engine/dist/opt/native-openal-soft directory after you build the engine). Do not copy it to the android project libs directory because it gets deleted and repopulated each time you hit Play in the SDK.
  3. Add the following line to your file in the Android project
    [java]audioRendererType = AppSettings.ANDROID_OPENAL_SOFT;[/java]

audioRendererType is a new variable in AndroidHarness that is used to switch the android audio renderer. The default is AppSettings.ANDROID_MEDIAPLAYER which uses the current audio renderer.

This is still experimental, so use at your own risk, but we would appreciate any feedback you have.


Awesome work Eric!

About supported android version, I guess we could safely give up android 2.2, because it’s only 3,7% of the market now (
Anyway, we’d always have the soundpool/medialayer fallback, for users that want to keep compatibility with this version.

You’d deserve a lot more thumbs up for this Eric, but I can’t do better than 1 :wink:

I’ll chip in a thumb up even though I do not really care about the android part of the engine (yet). =P

For those using the SDK, here is an example of what I put into build.xml to unzip the jME3-openal-soft-natives-android.jar file in the right place at the right time. As the picture indicates, this assumes you’ve create a global library in Netbeans that includes the same jar files as the provided “android-base” global library, but points to the jar files built in your custom engine build. Make sure you include the jME3-openal-soft-natives-android.jar file in your project libraries as well.

It’s working great! Thank you iwgeric. Your work is priceless.

Is it possible on Android to play sounds with a 3d position or sounds from a 3d direction around the user?

With the new OpenAL Soft Android Audio Renderer, the same effects supported on Desktop are supported on Android, including positional sounds.

Update on Android OpenAL Soft Audio Renderer:

The SDK (jME SDK release 3.0) includes a global library called “android-openal-soft”. If you want to use the new audio renderer on Android, simply add this library to your main project (not the Android project) and the build script for Android will automatically unpack it in the mobile/libs directory for you.

Then only other thing you need to do is add the following to MainActivity:
if (Build.VERSION.SDK_INT >= 9){
logger.log(Level.INFO, “Enabling OpenAL Soft Audio (Android 2.3 or higher)”);
audioRendererType = AppSettings.ANDROID_OPENAL_SOFT;
} else {
logger.log(Level.INFO, “Enabling Android MediaPlayer/SoundPool Audio (Android 2.2)”);
audioRendererType = AppSettings.ANDROID_MEDIAPLAYER;

1 Like


I gave it a try since I was using the Ocean Wave.ogg from test data

simple test worked fine, except the memory usage when we turn on the option
the 2 run are with and without audioRendererType = AppSettings.ANDROID_OPENAL_SOFT;
tested on Iconia A500

D/dalvikvm(24520): GC_CONCURRENT freed 3036K, 24% free 10338K/13575K, paused 2ms+4ms
D/dalvikvm(24520): GC_CONCURRENT freed 997K, 23% free 10560K/13575K, paused 2ms+2ms
V/NvAudioALSA( 84): Initialized ALSA PLAYBACK device music
D/dalvikvm(24520): GC_CONCURRENT freed 768K, 19% free 11130K/13575K, paused 2ms+9ms
D/dalvikvm(24520): GC_CONCURRENT freed 4764K, 43% free 7772K/13575K, paused 5ms+6ms
D/dalvikvm(23650): GC_CONCURRENT freed 734K, 12% free 7621K/8647K, paused 6ms+4ms
D/dalvikvm(23650): GC_CONCURRENT freed 71K, 8% free 8000K/8647K, paused 2ms+4ms
D/Finsky (23650): [1] 5.onFinished: Installation state replication succeeded.
D/dalvikvm(24520): GC_CONCURRENT freed 645K, 45% free 7516K/13575K, paused 6ms+3ms
D/dalvikvm(24520): GC_CONCURRENT freed 387K, 45% free 7515K/13575K, paused 3ms+3ms

D/dalvikvm(24427): GC_FOR_ALLOC freed 0K, 20% free 19467K/24071K, paused 23ms
D/dalvikvm(24427): GC_CONCURRENT freed <1K, 20% free 19469K/24071K, paused 2ms+2ms
D/dalvikvm(24427): GC_CONCURRENT freed 7022K, 41% free 14426K/24071K, paused 2ms+5ms
D/dalvikvm(24427): GC_CONCURRENT freed 616K, 35% free 15840K/24071K, paused 1ms+5ms
D/dalvikvm(24427): GC_CONCURRENT freed 4321K, 45% free 13445K/24071K, paused 3ms+8ms
I/dalvikvm(24427): Jit: resizing JitTable from 4096 to 8192
D/dalvikvm(23650): GC_CONCURRENT freed 602K, 9% free 7935K/8647K, paused 9ms+3ms
D/Finsky (23650): [1] 5.onFinished: Installation state replication succeeded.
D/dalvikvm(24427): GC_CONCURRENT freed 2429K, 47% free 12942K/24071K, paused 3ms+3ms

so we almost double the heap space used… and increase a lot the memory usage

I was about to post a thread about one of my audio nodes not looping properly on the Android… I read this first and tried it out, and I’m pretty impressed. It works better for my game, which involves lots of sounds most of the time. I’ll post back here if I run into any troubles with it, but for now I quite like this.