I just finished off gdx-audio, our newest extension. Features:

  • Decoders for mp3, ogg Vorbis and wav, using Mpg123, Xiph Tremor
  • KissFFT and Java FFT by Damien Di Fede for comparison
  • SoundTouch for pitch shifting, time stretching and playback rate modification

To use the extension add the gdx-audio.jar and gdx-audio-natives.jar to your desktop project. For your android project add the gdx-audio.jar and copy the files to your libs/armeabi and libs/armeabi-v7a folders.

For usage examples see:

  • Mpg123Test, shows how to decode an mp3 with the Mpg123Decoder class
  • VorbisTest, shows how to decode an ogg with the VorbisDecoder class
  • WavTest, shows how to decode an wav with the WavDecoder class
  • SoundTouchTest, shows how to apply pitch shifting to a PCM stream

Caveat: the vorbis and mp3 decoder can only decode files stored on the external storage. I might be able to work around that limitation in the future. For most practical purposes it shouldn’t be to limiting.

Sound API additions for libgdx!

It’s taken me quite some time to get to this, but here it is: All new Sound methods! Let’s get to the core of it.

Every time you call Sound#play() you will get a long. This long identifies that instance of the Sound being played back at the moment. You can use this id to manipulate that sound instance while its playing: loop it, change it’s pitch, volume and panning!

And here is the Sound interface for the lazy

Pretty simple eh? I’ll clean up the small inconsistencies in the Javadocs asap when we do our Javadoc sweep next week.

Three things:

  • setPan() takes the volume as well. Why? Cause i can’t get a hold of the volume of a stream (==sound instance) via Android’s SoundPool and keeping a list is tedious and bound to create leaks and GC invocations.
  • There is not Sound#isPlaying(long soundId). Why? Cause SoundPool doesn’t give me that information. There is no good work around for that (e.g. figuring out the sound length in seconds, and meassuring how long the sound’s been played back does not work as we don’t have an idea about latency on Android)
  • If a sound id is no longer valid and you pass it to any of the methods above… nothing will happen 😀
  • I might have mixed up linear and logarithmic gain/volume along the way for panning. If you find a problem let me know. The OpenAL implementation of panning is kinda hackish but is “good enough”(tm)

One more thing while i’m here: i haven’t been to the forums for a week, i’m sorry. Things are crazy at the moment and on top of that Stef came to SF. This means i won’t be back to the forums for another week.

Enjoy (and test)!