Problem with Java Sound Audio Engine

So, i took a look at my game engine’s sound utilities, as i’ve had a lot of bug reports on this in particular.

It seems the world is entirely different once you change from mixer to mixer. This ofcourse makes it almost impossible to make something cross-platform as each system has it’s own mixer. Yet, it seems that all have the mixer called Java Sound Audio Engine, so i made it possible to select a mixer in my program and started to test…

On my windows vista machine i got a fatal error that crashed the entire jvm.
It did however get even worse on my friend’s apple mac laptop. Here it not only crashed, but it crashed with a segmentation error!

I tested a could of times on my windows vista machine and here it seemed that calls to drain sometimes would start an infinite loop, draining the cpu rather than my SourceDataLine :stuck_out_tongue:
It also seemed that the LineListener i added didn’t always get the update calls i’d expect.

Right now i have the feeling that the java sound api is some kind of joke as long as there aren’t atleast one proper mixer available on all systems…
The only possitive thing i can say is that i actually got sound playing on all systems, before they eventual crashed.

So my question is, how do i get crossplatform audio in my games, preferably using the standard java API?
If more information is needed about my system, setup and code, please let me know and i’ll try to supply it :slight_smile:

  • Scarzzurs

JavaSound is not without it’s problems, but it’s the only way to get sound in pure java and IME it’s pretty stable if you use it as intended. I never ever had JavaSound crash on me like that myself :o
I’d file a bug report if I were you.

Maybe you could post some code that demonstrates the problem?

You could also take a look at OpenAL (using JOAL or LWJGL). It’s faster and supports 3D sound, but IMHO the API is nowhere near as nice as JavaSound, and you’ll have to deal with .dll’s, .so’s, code signing, etc.

Thanks for the reply. Just less than an hour ago i found a possible solution to the problem…
I did some test on windows only for now:

It seems that the drain method of SourceDataLine only acts properly if the start event of the line has been fired. It doesn’t matter if the fire event was fired and the data was drained by itself underway, but the drain method is totaly unreliable if the start event was fired first. I’ll hopefully be testing on my friends mac again later today, and i’m really hoping this is the problem.

I was afraid it would be a problem on my side, but i couldn’t find where it says that the start even must be fired before a call to drain.
Does the api state this anywhere?
In either case i think it’s wrong that pure java gives segmentation fault, and the crash i got on windows vista.

I’ll be testing it further and will be uploading a new version of my latest game featuring this workaround update to my engine.

Btw. i did consider OpenAL and other libraries, but like you said it’s not as clean as Java Sound…

  • Scarzzurs

Maybe use another mixer. I loop on all mixers and I choose the mixer that supports my line and that supports the highest count of simultaneously opened lines, I do it for each OggClip so that each sound sample might use a different mixer if required. Why do you need to call drain() before start()??

I wanted to check that i could play sound on all systems. My friend (on mac) and i (on windows) seemed to both have this mixer. That’s why i tried to test that. Also, i want to give the user the ability to select a device, rather than selecting a (otherwise) random mixer on each machine…

I don’t want to call drain() before start(). I want to call drain() after open(), start() and write(), and then after the drain() i want to close() the line. However if the drain() is called before the start event (started some time after some data has been written to the line), it acts all up. Sorry if i sounded all confusing, hope i cleared it up somewhat…

Thanks for the suggestion though :slight_smile:

Edit:
My friend tested the game, and the sound was playing perfectly, sounding exactly as on my machine. :slight_smile:

  • Scarzzurs