Sign in to follow this  
overeasy

[java] Least laggy Java sounds

Recommended Posts

hey all. whats the least laggy way to play sounds in java? and play the same sound multiple times at once. currently i'm using a wrapper i borrowed for some audioclip class but it lags horribly and cannot play the same sound many times at once. help

Share this post


Link to post
Share on other sites
Try searching for a Java wrapper around native FMOD.

I did create a low latency Java sound handler a few years ago. It might be "out of date" but worked really good for a remake of "Deflektor" I did.

At the moment of writing I cannot find the source for it, but will dig deeper if you still cannot find a solution.

Share this post


Link to post
Share on other sites
Quote:
Original post by Jompe71
Try searching for a Java wrapper around native FMOD.

I did create a low latency Java sound handler a few years ago. It might be "out of date" but worked really good for a remake of "Deflektor" I did.

At the moment of writing I cannot find the source for it, but will dig deeper if you still cannot find a solution.


I'm still looking for a solution. Java is such a love/hate relationship. Things like this should be integrated well...

Share this post


Link to post
Share on other sites
Java wrapper for FMOD which are native libraries.
http://jerome.jouvie.free.fr/Fmod/NativeFmod/index.php

If you still wanna go with your own build low latency code on traditional Java sound API I found my source code but it's to many rows to just give away.

It really isn't rocket science and I'll be glad to help you out if you tell me exactly what you're stumbling on.

To summarize the trick you need to query the DataLine on how many bytes can be sent without blocking the buffer causing overruns. You can on the other hand not send too few bytes to the buffer which causes underrun and then you get ticks and crappy noices in your sound.

Then in your main game loop (or whatever you're building) always call the update method of your sound handler which sends the bytes to the data line.

It worked really well for me with WAV/OGG sounds using an OggInputStream class I found somewhere on the net, think it was this one:

http://bob.newdawnsoftware.com/WebSVN/filedetails.php?repname=Slick&path=%2Ftrunk%2FSlick%2Fsrc%2Forg%2Fnewdawn%2Fslick%2Fopenal%2FOggInputStream.java&rev=1185&sc=0

PM or mail me if you need further help and/or code snippets.
// Jompe71

Share this post


Link to post
Share on other sites
Quote:
Original post by overeasy
I'm still looking for a solution. Java is such a love/hate relationship. Things like this should be integrated well...


I was looking into this same sort of thing the other day -- quite a coincidence! :)

In his book Developing Games in Java, David Brackeen describes a method whereby the audio file is read into memory and stored as a byte array. This is then used as the input to the AudioStream (IIRC). I can dig up the relevant text if you'd like.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this