If you look around this great big Internets of ours, you can find endless stories of people complaining about the ill-suited combination of Java, Linux, and sound. I originally set out to fix just my applets, but I think I came up with a way to get ALSA to play nice with all Java I run -- and you can, too~!
Uncovering the Issue
I have done (or had done by others) testing on a plethora of platforms: Windows, Debian, Red Hat, Solaris? I never had a problem with anything until, on a job interview, I was told that one of my applets died shortly after starting. He was using Ubuntu, which I had known to work fine for another unwitting test player.
Over time, I stressed my Debian to the limit, trying to reproduce any sort of error that would only happen on a GNU/Linux OS and not the more common (for desktop use, anyway) Windows. I finally narrowed it down to a null pointer exception being thrown when a sound was supposed to play.
Lazy exception handling on my part, granted, but what was up with that sound? The audio was unable to open. And why did it only happen on some of my kernel configurations?
A Little Background
ALSA (Advanced Linux Sound Architecture) is the "new" sound system for the Linux kernel, and that simply means "the one which isn't deprecated currently." ALSA is the more featureful replacement for OSS (Open Sound System), which has fallen out of favor.
Except for Java's favors, it would seem.
Sound on Java hasn't been the same since ALSA took over. Sun even rolled out a new version of Java without addressing the current sound issue. It isn't even that difficult an issue, one would think. Instead of grabbing the entire hardware audio device, just take a line on the software mixer. Well, it must be difficult to someone, 'cause that bug is from 2005.
The issue that arises from Java attempting to use sound is Java becoming the only process allowed to use sound on a Linux system. Worse yet, whichever audio line it first opens becomes the only audio line allowed to be opened! Putting a stranglehold on the sound card even prevents Java from opening more sounds. When playing Kirbj with only basic ALSA support, you get the first sound buffered (typically the "hit" effect) and that's it.
How can this be overcome for open source types who want to have their Java and listen to it, too?
OSS Kernel Emulation: One may compile the Linux kernel for backwards-compatibility with the older sound system. (This is the reason, I suspect, why I was seeing various results with Java and Linux OSes.) Java will be able to open more than one audio line with this configuration option, but it will still lock out any other process from touching the audio device.
And if you already have some music playing, as I often do with my last.fm while programming? Wellsir, then no audio at all loads for your Java. It is all or nothing for Java going this route, which is still more than the one or nothing with plain ALSA.
OSS Software Emulation: This one takes a bit more effort, but the results are far superior. The alsa-oss package contains a wonderful little wrapper called aoss. Whatever you run through this script will receive an emulated OSS treatment on a system running ALSA, and much better than the kernel option, from my experience. Of course, my sole criteria is "Does other audio play when I'm using Java audio?"
The answer is yes.
Usage, however, is a bit more tricky. Normally, one would simply prepend an li'l somethin' on the command line like so:
Works like a charm!... for debugging. What command do you type to execute the applet plug-in? Oh, right, you don't! But somebody does, somewhere on the system. And a little digging shows that there isn't one simple answer to that question.
So, in case, you are a lazy and half brain-dead mess like me but do not want to make the frequent mistakes along the way that I did ("Oh, right, the executable needs executable permissions!"), here is everything spelled out for you nice and simple:
No discussions exist yet for this. You can start one if you would like.
|Copyright © 1999-2017|