Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (788)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (860)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Problem with Java Sound Audio Engine  (Read 6075 times)
0 Members and 1 Guest are viewing this topic.
Offline Scarzzurs
« Posted 2008-10-29 20:43:12 »

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

- Scarzzurs

My games and Projects:,
Old website
Offline erikd

JGO Ninja

Medals: 16
Projects: 4
Exp: 14 years


« Reply #1 - Posted 2008-10-30 11:12:00 »

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 Shocked
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.

Offline Scarzzurs
« Reply #2 - Posted 2008-10-30 11:33:48 »

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

My games and Projects:,
Old website
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gouessej
« Reply #3 - Posted 2008-10-30 15:51:36 »

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()??

Julien Gouesse | Personal blog | Website | Jogamp
Offline Scarzzurs
« Reply #4 - Posted 2008-10-30 17:07:04 »

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 Smiley

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

- Scarzzurs

My games and Projects:,
Old website
Pages: [1]
  ignore  |  Print  

hadezbladez (2109 views)
2018-11-16 13:46:03

hadezbladez (804 views)
2018-11-16 13:41:33

hadezbladez (2080 views)
2018-11-16 13:35:35

hadezbladez (415 views)
2018-11-16 13:32:03

EgonOlsen (3448 views)
2018-06-10 19:43:48

EgonOlsen (3677 views)
2018-06-10 19:43:44

EgonOlsen (2272 views)
2018-06-10 19:43:20

DesertCoockie (3002 views)
2018-05-13 18:23:11

nelsongames (3072 views)
2018-04-24 18:15:36

nelsongames (3852 views)
2018-04-24 18:14:32
Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!