Serious stutter in Java Sound

I was reviving and old game I did in 2002, which worked fine at the time. Since then Sun has somehow managed to break Java Sound.
When my character moves around, and a sound is played for each move made, the animation starts to stutter. I have created a simple example that exhibit the same behaviour:
http://matzon.dk/brian/Random%20Junk/SoundTest.zip

Extract and run like this:

[quote]java -cp bin;res SoundTest
[/quote]
It works fine in 1.3 (except the Thread exit bug which was first fixed in 1.5).
1.4 Stutters, and sounds different
1.5 is just as crappy - and required me to FORCE usage of the software implementation since their default implementation sucks, and only plays some of the sounds it sees fit.
I have tried to switch to .au files (using sun.audio.AudioPlayer) - and performance is WAY better - no stutter at all. However this implementation produces some serious artifacts in the stream (clicks and pops).

Could someone please explain to me how people have used Java Sound since 1.3 ??
Or am i misusing the clip interface?

[quote]Could someone please explain to me how people have used Java Sound since 1.3 ??
[/quote]
JavaSound has alwais been crappy… I’ve used it when I was playing with Java 1.1… But it’s pretty slow, buggy on last JDK versions. Now, there are many ways to handle sounds in java, you can use fmod, openal, audiere (very fast native lib) and some others. If you want pure java, there are javazoom player which can play mp3, or jOrbis, the well-known, which can play ogg…
If java is missing something, it’s the sound part… Hope the future version of Java will handle sounds better !

Chman

I know about the native libs :wink: - but I want to do this without signing my applet!
javazoom uses javasound - so will suck equally well - I have no need to play mp3 or ogg vorbis…

Unfortunately I can’t help at the moment, but I’d like to say I’ve got the same problem with my game project and Java sound: it should be a smoothly scrolling game and it is - until I play several wave sounds then it starts to stutter which kills the whole idea of the scrolling game. :frowning:

It’s Java 1.5 and I use Yuri’s workaround to fix the broken standard 1.5 sound system (ie the workaround is to use software sound)…

Chman, do you know where I can find a good tutorial on fmod for java? (http://topresult.tomato.co.uk/~jerome/index2.html)

Thanks!

Sorry for the late reply…

Well the only fmod binding I know is the one included in lwjgl, but I works without all others lwjgl libs. You could take a look at the demos included in for help on initializing fmod in java. Then, using fmod in java is the same as using it with C… Just read a C fmod tutorial, or the official fmod manual and you’ll have all what you need.

I’ve made very simple application that use fmod (lwjgl binding). You can find it here. :slight_smile:

Chman

OK thanks for help! :wink: I will check that.

Rimscape just uses Clips. Check it out… is that considered good?

Clips work fine as long as you keep your sound effects to a minimum. The problem comes in when you need to stop and restart sounds. Stopping and/or restarting Clips force them to drain. The only problem is that draining the sound results in blocking (!), which is a very bad thing in games.

The alternative to using Clips is to use a SourceDataLine. With a SourceDataLine, you can feed it raw audio data as needed. You can even create your own mixer! There’s only one problem with it: If you overflow the internal buffer, the line will block! (Just can’t win, can we?)

GAGESound solves these problems by feeding a SourceDataLine every few milliseconds. It basically guesses as to the amount of audio data that will need to be written in order to cover the next frame. Not only does this avoid blocking, but it decreases latency to nearly unnoticable levels. (i.e. The player notices no lag between hitting the fire key, and hearing the “BOOM” of a cannon.)

I gave up my Java Sound layer and I now use the fmod3 package from LWJGL. It’s so much more easy with LWJGL, very fast and stable too.

I spent too much time trying to get things working nicely by using an OGG SPI for Java Sound and as JBane mentionned the buffer overflow/underrun problems are really tough to solve.

So my conclusion: Java Sound is still crappy for games. With LWJGL you get all of that freely with any sound/music format and it works so well!

Just one issue: if you plan to use it for commercial purposes than you have to know that the fmod licence is very expensive for a small company.