Hello all,
I'd like to announce my port of OpenAL to Android. This one includes a Java interface, which will allow you to add OpenAL to your Android projects without having to play around with c/c++ and JNI. It should work on all versions of Android back to 1.5.
For those familiar with using OpenAL under normal Java, the interface for this port is probably closer to JOAL rather than LWJGL's interface. There are a few differences from JOAL, however (mainly in the methods that take array/ buffer parameters, the way the context is created and destroyed, and the lack of a direct interface to ALC with device and context objects Java-side). That being said, code written for JOAL or LWJGL is pretty simple to make work with my interface (it's all OpenAL when you get right down to the nuts and bolts, after all).
Everything is accessed statically through the class paulscode.android.sound.ALAN. Before creating any sources and what-not, first connect with the Android audio device and create an AL context by calling:
From there, you can access whatever AL functions you need through ALAN. For example:
And when you're finished, destroy the AL context and disconnect from the Android audio device by calling:
In case you haven't caught on, ALAN isn't a personal name like some AI alias - it's just an abbreviated form of "OpenAL for Android" (fewer keystrokes than OpenALAndroid). On a humorous note, I was actually forced to rename a hundred or so references to my project's original title "Android OpenAL", which I was horrified to realize became "ANAL" when abbreviated. THAT was a real pain in the butt ;D
Anyway, here is a very basic app to demonstrate streaming an .ogg file:
ALAN Demo (source code)
I normally drop in the source code to my projects, but you should be able to just unzip the above APK file, grab the contents of the "lib" folder, and paste them into your own project's "lib" folder. If you prefer to compile the source code yourself, you can unzip the source code archive above and either run the following commands from the terminal/command prompt:
Or you can "create a new project from source" in Eclipse (requires the Android SDK and NDK to be installed, as well as the ADT plug-in and Sequoyah Android Native Code plugin from the update site plug-ins). Once you've created the Eclipse project, just right-click on it in the left panel and navigate to "Android Tools->Add Native Support".
The above demo utilizes the Tremolo library for decoding the .ogg file. It is a popular library for use on Android because it is extra light-weight and optimized for the ARM architecture, but there are plenty of other decoder libraries out there you could use if you have problems with that one. In theory, you could even use any of a number of pure-Java audio decoders as well, including the ones included with my SoundSystem library. This demo is really low-tec.. I just threw everything into the activity's onCreate method, and the thread blocks there in the stream loop until playback finishes. It is just for demonstration purposes - you wouldn't normally write an app that way. You'll also notice that the make-shift ogg decoder I threw together is really inefficient (takes encoded buffers from Java, decode them in native, sends then back to Java, then Java sends them back to native to be played). I wouldn't recommend copying any part of that demo in a real-world app - it is entirely a proof of concept.
One final note: OpenAL Android is licensed by the LGPL (since that is what OpenAL and Tremolo are licensed under). While I normally shy away from this license, it actually meshes really well with Android apps, because the end user can use any of a number of free backup programs (such as ASTRO) to create a backup APK of your app. From there, they can plug in a different version of the library into the APK, and simply reinstall it. All you have to do is mention somewhere in your documentation where they can acquire the sourcecode for OpenAL Android (feel free to mention my website if you don't want to host the files yourself). Please let me know if you encounter any bugs (logcat output is always helpful). This is the first release, so there are bound to be a few glitches to work out.
I'd like to announce my port of OpenAL to Android. This one includes a Java interface, which will allow you to add OpenAL to your Android projects without having to play around with c/c++ and JNI. It should work on all versions of Android back to 1.5.
For those familiar with using OpenAL under normal Java, the interface for this port is probably closer to JOAL rather than LWJGL's interface. There are a few differences from JOAL, however (mainly in the methods that take array/ buffer parameters, the way the context is created and destroyed, and the lack of a direct interface to ALC with device and context objects Java-side). That being said, code written for JOAL or LWJGL is pretty simple to make work with my interface (it's all OpenAL when you get right down to the nuts and bolts, after all).
Everything is accessed statically through the class paulscode.android.sound.ALAN. Before creating any sources and what-not, first connect with the Android audio device and create an AL context by calling:
Code:
ALAN.create();
Code:
int[] ALBufferIDs = new int[BUFFER_COUNT];
int[] source = new int[1];
int[] state = new int[1];
ALAN.alGenSources( 1, source );
ALAN.alGenBuffers( BUFFER_COUNT, ALBufferIDs );
ALAN.alBufferData( ALBufferIDs[i], format, buffer, buffer.length, rate );
ALAN.alSourceQueueBuffers( source[0], c, ALBufferIDs );
ALAN.alSourceQueueBuffers( source[0], c, ALBufferIDs );
ALAN.alSourcePlay( source[0] );
ALAN.alGetSourcei( source[0], ALAN.AL_SOURCE_STATE, state );
if( state[0] != ALAN.AL_PLAYING )
whatever();
Code:
ALAN.destroy();
Anyway, here is a very basic app to demonstrate streaming an .ogg file:
ALAN Demo (source code)
I normally drop in the source code to my projects, but you should be able to just unzip the above APK file, grab the contents of the "lib" folder, and paste them into your own project's "lib" folder. If you prefer to compile the source code yourself, you can unzip the source code archive above and either run the following commands from the terminal/command prompt:
Code:
ndk-build
ant debug
ant install
The above demo utilizes the Tremolo library for decoding the .ogg file. It is a popular library for use on Android because it is extra light-weight and optimized for the ARM architecture, but there are plenty of other decoder libraries out there you could use if you have problems with that one. In theory, you could even use any of a number of pure-Java audio decoders as well, including the ones included with my SoundSystem library. This demo is really low-tec.. I just threw everything into the activity's onCreate method, and the thread blocks there in the stream loop until playback finishes. It is just for demonstration purposes - you wouldn't normally write an app that way. You'll also notice that the make-shift ogg decoder I threw together is really inefficient (takes encoded buffers from Java, decode them in native, sends then back to Java, then Java sends them back to native to be played). I wouldn't recommend copying any part of that demo in a real-world app - it is entirely a proof of concept.
One final note: OpenAL Android is licensed by the LGPL (since that is what OpenAL and Tremolo are licensed under). While I normally shy away from this license, it actually meshes really well with Android apps, because the end user can use any of a number of free backup programs (such as ASTRO) to create a backup APK of your app. From there, they can plug in a different version of the library into the APK, and simply reinstall it. All you have to do is mention somewhere in your documentation where they can acquire the sourcecode for OpenAL Android (feel free to mention my website if you don't want to host the files yourself). Please let me know if you encounter any bugs (logcat output is always helpful). This is the first release, so there are bound to be a few glitches to work out.