Sound, Linux and software mixing soundcards

Hello all,



I've gone through hard times here… regarding Java + Sound.



Because FMOD crashes on my Linux box and I don't understand the current sound system of JME,

I implemented some sound classes myself (an ogg player and a sound effects player) with

the Java sound api.



It works quite fine under windows, but the whole sound stuff drives me crazy on Linux.



The point is: Like many people i just run an onboard sound chip without hardware mixing…

if you're a windows only user, it's likely you never heard about hardware/software mixing at all…

it just works.



Under Linux, things are more complicated…



The common way is to use ALSA + dmix-Plugin… Most modern Linux-Distributions seem

to set this up correctly, so it works "out of the box"… at least, if your soundcard is supported.



Fine.



But there's an exception. The Java sound api.



I cite

http://www.jsresources.org/faq_audio.html#alsa_mixing


5.5.

How can I enable mixing with the "Direct Audio Device" mixers on Linux?


The "Direct Audio Device" implementation on Linux is based on ALSA. Mixing is available in the Mixer instance if ALSA provides mixing. This is the case if the soundcard can do mixing in hardware and its ALSA driver supports this feature. This is true for some common soundcards like Soundblaster LIFE! and Soundblaster Audigy and cards based on the Trident 4D Wave NX chipset. If this feature is available at all, it needs no special configuration. It is enabled by default.

Using ALSA's dmix plug-in does not work together with Java Sound. The reason is that the "Direct Audio Device" mixer implementation based on ALSA queries the available hardware devices. However, a dmix device in ALSA is no hardware device, so it is not recognized. Discussions about this issue led to the conclusion that there is no easy way to integrate a query for additional devices.

Damned!!!

That means that a whole bunch of Linux users will run in serious problems using Java apps with sound under Linux, because

a) the Java app will grab the sound device exclusively and lock it up or..
b) can't get a lock on the sound device at all.

I've no idea whatsoever I could get around this problem...

What do YOU do to get it REALLY working multi-platform?

OpenAL (and jME's implementation against it) ?

MrCoder said:

OpenAL (and jME's implementation against it) ?


... And you can pass an ogg - stream to open al output?

jme uses JOrbis to decode ogg

http://www.jcraft.com/jorbis/index.html

MrCoder said:

jme uses JOrbis to decode ogg
http://www.jcraft.com/jorbis/index.html


Sigh... Well, I know this.. but that's not the solution for the problem.

Jorbis Website:

To enjoy this player, your JVM must support Java Sound API. (..)


Great, uh? All the way round again...

But as far as I see know, maybe there is a solution using the "AOSS" wrapper script
in conjunction with a modified ".asoundrc" file.....

The java sound api seems to ose OSS if the soundcard (and driver) doesn't support
hardware mixing.... and maybe there's a solution.....

I wonder if one of the folks behind this site: http://www.jsresources.org/  might be able to help. (sorry if you were already aware of them).

Stan

I spent a while with the Java Sound API, and I would have to say I have nothing but contempt for it. I may well be out of date since it must be a year or so since I used it, but back then it was buggy, laggy, hard to install, and supported by half a person at Sun. Well, a whole person, but he was only assigned to JavaSound for half his time, if that.



I did get sound working in my game (not jme based, puzzlebeans.sf.net) but JavaSound proudly played my sounds about 0.5 seconds after I triggered them, completely destroying any illusion that the sounds were connected to what was happening on screen. This was on linux - on windows there wasn't such a large delay. OpenAL by contrast was very easy to get going at least for basic sound playback, and worked fine on everything I tried it on. Plus as people have pointed out there is jme support for it. Even UT 2004 uses it quite successfully on linux.



So… I could be completely wrong, but I think all JavaSound has ever brought anyone is sorrow - it's a typical Sun thing, like JMF, in that it ALMOST looks as if it is going to do something useful, and is all "official", so it puts people off developing and using a system that ACTUALLY works. It's actually almost perfectly pitched to ruin Java sound support now and in the future, just like JMF has ruined media support in general. Maybe things will improve with open sourcing, I don't know.

we had the same experience with javasound 3-4 years ago when we tried to use it…what everyone told us was that javasound was supported by, just like you say, half a person…again showing how much sun really want java to be a good game/media platform…java becoming an ok gaming platform, that's because of you and me, not sun :slight_smile: rant rant


Please note that I didn't say 'use Java Sound'. It does, unfortunately, appear that it may never be ready for prime time. (which is sad, because if it did what it claims reasonably well, I would write several different applications with it myself).

What I did mean to say was that at least one of the people behind that site are deep enough into this area to be of help. In other words, oliver1974 might contact them about possible courses of action. Not that Java Sound was any kind of answer for his issues.

I'll shut up now :)

Stan

Sorry I didn't mean to sound like I was responding directly to you with a big rant stanlogan :slight_smile: I was just commenting on Java Sound in general, I find it hard to restrain my hatred when anyone mentions it :wink:

First, i know www.jsresources.org … but thank you!  :slight_smile:



After a LOT of reading on that site, I figured it out (I think).



(I will call the Java Sound API just "JSA" here… too long to type again and again…  ;))



1.) JSA tries (since Java 5) to get the most direct access to a sound device first… this

means DirectSound under Windows and ALSA under Linux.

2.) If JSA gets a "direct" device, it checks whether this device (and its driver) is capable of hardware mixing.

3.) if yes, everything is fine.

4.) If not, JSA falls back on the pre Java behaviour and starts a Java mixer. This java mixer uses OSS on Linux,

NOT ALSA!

5.) There's no hope trying the "dmix plugin" of ALSA which is responsible for software mixing of the ALSA devices,

JSA simply doesn't get it…

6.) …so, your only chance is to get OSS working nicely besides ALSA… That means that OSS applications and

ALSA applications may play concurrently.

7.) You will have to wrap your Java application in the "aoss" tool, which will take care of routing the

output of JSA to the ALSA software mixer, that means that a) "aoss" has to be installed (or more precisesly, the

package which contains "aoss") and sometimes (not always) the user has to have a prepared ".asoundrc" config

file, which defines the OSS-pseudo device(s).



Short version: Try to call your java game on Linux like

"aoss java (options here) MyGame.class" … at least something like that…



It works for me here…



And don't try to wrap your whole IDE with "aoss", it may crash your system…

(at least my Netbeans IDE freezed over and so did the whole system… I had to

kill all java processes via SSH from a different computer!)



Ahhhh, the joys of the different Linux sound systems, different Linux distributions and the Java Sound API.


There's also a bug (that Sun has claimed to fix twice now) wherein sound playback with JSA on linux will stop working after a specific period of time (I seem to recall it being around 4 hours).  You have to kill the process and restart it.  This is due to some counter overflowing.