Sound lag on Linux

When playing sound (both sampled and midi) there is a noticable delay between method call and sound beeing played. It’s very anoying and make it almost impossible to write multiplatform game using core java.

I’m using J2SE 1.5 beta 2 on a Fedora Core 2… can any of you verify this on some other Linux release?

I know I read something about improving sound on linux in the 1.5 release but I’m not sure what it was.

[quote]make it almost impossible to write multiplatform game using core java
[/quote]
Don’t cut yourself up about it - core Java is more or less almost but not quite exactly the wrong technology to try writing a proper game with. Use the right tool for the job! Use LWJGL, or if you feel like making life complicated for yourself, use JOGL/JOAL/JInput, and forget the core libraries for games.

Cas :slight_smile:

What about sound through OpenAL (using LWJGL) then?

Is that working properly on Linux as well as Windows?

If you have timing problems and bad sound with midi, you’ve most likely “forgotten” to install a soundbank (sdk comes with and jre without).

http://java.sun.com/products/java-media/sound/soundbanks.html

And sampled sound… well, there are several ways for playback. Applet’s AudioClip stuff for example performs generally very poor, because the audio data get stored in ram the first time a sample is played (and your game is usually already running then).

What works quite ok-ish is using Clips (not Applet’s of course). The audio data is then already stored in ram and there is no delay (well ok maybe 50msec) if they are played. At the very first time a sample is played there is a small delay, if you hadn’t created a mixer first (the default mixer is then created and everything is fine).

[search for “SoundManager” to get some example code]

That works quite well, but it’s only suitable for rather short samples (eg 150 300-1500msec sfx samples). For background music you usually need something else (streaming).

With OpenAL it’s similar - decode, put it into ram and playback whenever you want to. It’s very fast and you can only use good methods there (all that silly stuff was omitted ;)).

Edit…

Is that working properly on Linux as well as Windows?

Yep, and on Mac, too :slight_smile:

Hear OpenAL in action here:
http://www.puppygames.net/downloads/alienflux-full.jnlp

Requires Java 1.4+, hardware OpenGL drivers and preferably a GPU, 400MHz CPU and 32MB free RAM

Cas :slight_smile:

We had the same experience when we implemented a sound enginge for our Java Quake2 port (http://www.bytonic.de/html/jake2.html). With the java sound api sound is lagging behind the action. :frowning:

So we switched to joal. We had some problems with dll incompatibilities on windows. But now Jake2 sounds great.

Holger