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)!

10 thoughts on “Sound API additions for libgdx!

  1. Sounds good ๐Ÿ™‚

    I can’t wait to finish the visual of my
    game and start adding music and effects…

    Thanks !

  2. Hey guys, sorry if I’m not updated. but why don’t you add support for midi files? I never understood why you didn’t.

    Thanks for all your hard work!

  3. There is no pause and resume. So a long sound and you hit the pause button. So how do you want to resume the sound?

Leave a Reply

Your email address will not be published.