I'm trying to get a game working on Linux (Link: http://www.ludumdare.com/compo/ludum-dare-21/?uid=398 [yes, that's Notch's Ludum Dare entry]) - that is, I want to fix the sound, because the rest seems fine. The sound implementation in the game is very basic, but while trying to tinker with it, I've had trouble getting JavaSound to work with Linux at all (using Linux Mint 11).

So, the sound effects are used like this (taken from the source files):

This actually works, but if you try to play the same sound many times, there's a pretty large delay (about 1 second) between each play. I've noticed that the "Clip.stop()" method takes a very long time on my machine, which it doesn't on Windows. So, because playing the sound is synchronized in the "play()" method (see above), any attempts to play the sound again have to be queued up and wait until that's finished. In the game, if you play the same sound again very quickly, that obviously doesn't work because the action that triggered the sound is long over.

Because I don't know very much about JavaSound, I decided to switch to the Sun JDK 1.6 and see if that works better. No matter if I use the first or second version of the "loadSound()" method, I get this at "clip.open(ais)":

So, I thought, maybe the format actually isn't supported. So I tried with a .wav file of the following format: "PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian". I didn't get any exceptions this time, but there's a problem: I can't hear anything. As I tried out various things from the forums, I looped through all the mixers on my system via "AudioSystem.getMixerInfo()". With the Sun JDK, this gave me:

Now, because sound on Linux is generally a big pile of chaos, I don't really know too much about it and I also don't know what all those mixers are referring to. I do know, however, that I have PulseAudio, so perhaps the missing entries in the Sun JDK list explain why I got no exception, but still couldn't hear any sound.

So, at this point, I'm stuck. To recap, I can't play sound with the Sun JDK at all and with OpenJDK, I don't know how to play the same sound multiple times, quickly. Is there any way I could get this running? I'd really like to stay with JavaSound and avoid any external libraries - the application is extremely simple. I mean, basically, I just want to play some sounds!

I haven't worked with sound specifically on Linux, but I haven't had any Linux users complain about the various Applets I've posted.

Sometimes things that are "slightly incorrect" work on one OS but not on others. Also, there are dozens of ways to slip up and forget a step. I know I've found myself pulling out my hair because I forget something dumb like an open() step or my sound editor decides to export a blank wav and I don't confirm there is actually the expected sound in it before I try to run it in Java. (Not saying you have made such mistakes, just that, in general, a lot of double checking has to be done.)

I'm curious, how long (in frames) are these short sounds?

I suspect that the mixer issue is a red herring.

Not sure I understand your usage, with the static methods and invocation of synchronize on the clip. Do you have code that demonstrates usage that can be run as a test case? I don't see how you select which clip is going to play if the Sound method loads "a bunch more sounds". It looks like each load overwrites clip.

"We all secretly believe we are right about everything and, by extension, we are all wrong." W. Storr, The Unpersuadables

@Riven:I guess I'll try that, however I'm not sure how one would actually do that. Do you have any pointers/tips on how to start? Anyway, I'm going to take a closer look at it tomorrow.

@philfrei:If you've successfully used sound with applets before, could you perhaps demonstrate a working example? I suppose you've used "AudioClip" when working with applets; I don't know in how far that's related to the rest of the JavaSound API, but maybe I can take a look at that as well.

Also, note that the example posted here isn't actually my code - I'm tinkering with an open source game from the Ludum Dare competition (link in the first post) to learn some things and to get it working properly on Linux. By the way, on Windows, there are no problems with the game, and on Linux, everything is fine except for the Sound (which is basically implemented using that single class I posted).

I'd have to check to see how long the sounds are exactly, but they're all shorter than a second. They can also be downloaded (link in the first post) if you need more information.

Concerning the mixer issue, that's just a difference I found between OpenJDK and the Sun JDK. Since I've heard about JavaSound using the wrong mixer before, and because I can get sound with OpenJDK, but not the Sun JDK (with the exact same code), I thought that might be one of the causes (still not sure).

About the code: As I said, the whole game source code is available (it's not huge, the game was made in 2 days) and is not written by me. However, I can explain how it works. An object of the "Sound" class, as it was posted, is supposed to represent a single sound effect that can be played with its only method, "play()" (very simplistic). The "loadSound()" static method loads a sound from a resource, creating a "Sound" object. This could instead be replaced with a constructor, but the author chose to do it like this for some reason. Where I put "load a bunch more sounds...", I just cut out how all the sounds were loaded in the original code, all in the same way:

1

publicstaticSoundsomeSound = loadSound("/snd/someSound.wav");

Whenever a sound is needed, it can be played frome elsewhere in the code with (for example)

1

Sound.someSound.play()

"clip" is not overwritten because each load creates a new sound object, each with its own "clip" field.Regarding "synchronize", this is needed to prevent multiple threads (a new thread is launched each time a sound is played) from accessing the same clip at the same time, which would cause problems. On Windows, this use of synchronization isn't a problem for the game because the sounds are very short and the threads terminate very quickly. WIth OpenJDK, though, the call to "clip.stop()" takes ages for some reason, so if you play the same sound several times in quick succession (e.g. gunshots), it takes far too long to play all the sounds because the threads can't quit quickly enough, and you still hear the queued-up shots with long pauses in between (during which the thread is busy doing "clip.close()") even if the guns have long stopped shooting.

EDIT: I just found this: Java Theremin. Without having looked at any error messages, I'll just quickly say I'm not getting any sound there, either.

I was never tempted by AudioClip. I've always wanted to have some control over volume.

The Theremin isn't working? Interesting. When you drag the mouse upwards, the volume should rise. Are you able to get other sounds via other Java programs? You may have uncovered something that I have not dealt with yet!

Re: synchronize, there are perhaps alternative strategies to consider, such as thread isolation. If the clip is synchronized, how does one get access to stop() it? Maybe try using the getLine() method from one of your Mixers rather than from AudioSystem?

But I guess the first thing to establish (is that your volume knob is on -- just kidding), for my being able to help or not, is whether it can play my Applets. If it can't then I clearly have the same problem as you to solve. I'll take a look at the download link you provided as soon as I get a chance.

"We all secretly believe we are right about everything and, by extension, we are all wrong." W. Storr, The Unpersuadables

I don't hear anything from the Theremin on my Linux box, either. Socob is spot on with "sound on Linux is generally a big pile of chaos", but I'm pretty sure I don't have anything locking my soundcard at the moment.

Thx ptjt33, and Socob, too. I am glad to find this out.I left a query over at a linux forum--but no responses yes.The Notch Ludum Dare entry makes sound on my Windows system, but that was expected. (Now, if I could only figure out how to get out of the starting cell, in that game.)

JavaSound typically being such an unstable can of worms, I advice you to do the following:

Open a 16 bit, stereo audio channel at 44100Hz, and do all mixing yourself.

Yes, it's a lot of work, but at least it works and keeps working throughout your game.

Generally, I'd agree with Riven - do your own software mixing. I'd stay well clear of Clip - they seem highly problematic (and also used to have difficulties playing sounds under 1 sec.) I don't entirely agree that JavaSound is an unstable can of worms though - the direct audio devices generally work well if you use the API as intended. You need to be aware that the direct audio devices are just that though, direct access to the underlying soundcard driver, and can behave quite differently on different systems. eg. there is no hardware mixing on most Linux drivers, unlike Windows, so playing multiple sounds by opening multiple lines / clips will generally fail. A lot of Java games (and Pulpcore) suffer from this issue. The simplest way is to use the direct lines as they were intended - open a single line, keep it open, and mix your sounds into it yourself.

I posted the AudioServers code from my Praxis project up recently - info here http://www.java-gaming.org/topics/jaudiolibs/24574/view.html This abstracts out the actual audio setup code - you just have to implement a callback to fill float buffers as required. The audio routing / mixing stuff from Praxis will be up under a similar license in the near future, but is currently undergoing some API changes. I can point you at a few classes in the repo that will do the mixing bit for you though, if you want.

Crackly?! What does that mean? I am aware of something that I assumed was kind of like anti-aliasing in the high registers, especially the square wave. Is that what you mean? Crackly as a descriptor sounds much worse than that. Does the sine wave crackle, too? That is clear as a bell, over here.

Sorry, Socob, I don't mean to hijack your thread.

As far as mixing, I am kind of disappointed. Windows and Mac systems seem fine with running multiple SourceDataLines at the same time. Are you saying Linux can't handle this, even if we write something that allows the User to pick their preferred sound card?

Writing a live mixing routine seems like it should be doable, but a pain. The main thing, I assume is work out the relative volumes of all the source data, then add the audios, frame by frame. Yes? It's basically just an addition operation with provisions made to keep everything aligned in time and to prevent the sums going out of bounds? I guess there is no reason the inner loop can't have 5 different wav files all being read a buffer at a time.

"We all secretly believe we are right about everything and, by extension, we are all wrong." W. Storr, The Unpersuadables

As far as I know, since Java 1.5, JavaSound tries to use the best direct audio mixer. However, on some Linux machines, when some webcams are plugged, it tries to use the webcam as sound output I wrote a bug report about it. On the other hand, some direct audio mixers are buggy. Some programmers try to use "Java Sound Audio Engine" to get the same behavior everywhere.

As far as I know, there is no "Java Sound Audio Engine" on OpenJDK which means that in this case, you have to use another mixer.

That's why OpenAL (with OpenALSoft) through JOAL (JogAmp) or LWJGL is a better solution in my humble opinion, Riven's suggestion is interesting too. These 2 options are the most viable cross-platform solutions to play sounds in Java.

As far as mixing, I am kind of disappointed. Windows and Mac systems seem fine with running multiple SourceDataLines at the same time. Are you saying Linux can't handle this, even if we write something that allows the User to pick their preferred sound card?

Java Sound is quite badly maintained on Linux, it has nothing to do with Linux itself.

Writing a live mixing routine seems like it should be doable, but a pain. The main thing, I assume is work out the relative volumes of all the source data, then add the audios, frame by frame. Yes? It's basically just an addition operation with provisions made to keep everything aligned in time and to prevent the sums going out of bounds? I guess there is no reason the inner loop can't have 5 different wav files all being read a buffer at a time.

Paul Lamb is already working on its own software mixer, I hope he will succeed.

That's why OpenAL (with OpenALSoft) through JOAL (JogAmp) or LWJGL is a better solution in my humble opinion, Riven's suggestion is interesting too. These 2 options are the most viable cross-platform solutions to play sounds in Java.

If you want to do the actual processing in Java, then Riven's way is the only way.

As far as mixing, I am kind of disappointed. Windows and Mac systems seem fine with running multiple SourceDataLines at the same time. Are you saying Linux can't handle this, even if we write something that allows the User to pick their preferred sound card?

Java Sound is quite badly maintained on Linux, it has nothing to do with Linux itself.

Actually, no, it has as much to do with Linux (well ALSA) as Java. Notwithstanding that Java uses deprecated bits of the Alsa API, JavaSound only supports multiple lines on Linux when ALSA and the soundcard supports hardware mixing, which is not very often. On Windows, this is emulated in the soundcard drivers, but Java doesn't use this feature of ALSA at the moment. IMO this is a good thing - the direct mixers do what they're meant to, and give you direct access to the capabilities of the underlying hardware. That's one reason why Linux has the best JavaSound performance (in terms of latency). The problem is people not using the API properly.

Writing a live mixing routine seems like it should be doable, but a pain. The main thing, I assume is work out the relative volumes of all the source data, then add the audios, frame by frame. Yes? It's basically just an addition operation with provisions made to keep everything aligned in time and to prevent the sums going out of bounds? I guess there is no reason the inner loop can't have 5 different wav files all being read a buffer at a time.

Paul Lamb is already working on its own software mixer, I hope he will succeed.

And there are many other options - Beads, Rasmus, JASS, Toot, RAPL (when I finish extracting it from Praxis), and even Gervill if you hacked it out. Software mixing is not exactly hard, particularly if you use float buffers (which any decent audio API does). As Phil says, it's basically just a summation buffer (possibly with some -1:1 limiting or an auto gain control).

Crackly?! What does that mean? I am aware of something that I assumed was kind of like anti-aliasing in the high registers, especially the square wave. Is that what you mean? Crackly as a descriptor sounds much worse than that. Does the sine wave crackle, too? That is clear as a bell, over here.

The sine wave is actually the worst of the lot. Quite harsh discontinuities in the audio. Any chance you've got some out-of-range numbers in there somewhere? ALSA can be rather unforgiving with that.

Actually, no, it has as much to do with Linux (well ALSA) as Java. Notwithstanding that Java uses deprecated bits of the Alsa API, JavaSound only supports multiple lines on Linux when ALSA and the soundcard supports hardware mixing, which is not very often. On Windows, this is emulated in the soundcard drivers, but Java doesn't use this feature of ALSA at the moment. IMO this is a good thing - the direct mixers do what they're meant to, and give you direct access to the capabilities of the underlying hardware. That's one reason why Linux has the best JavaSound performance (in terms of latency). The problem is people not using the API properly.

Therefore, it is not a problem in ALSA. Non-Java applications and APIs using it work fine, better than OSS. I don't see what you mean because ALSA supports multiple lines only if the underlying hardware supports hardware mixing.

And there are many other options - Beads, Rasmus, JASS, Toot, RAPL (when I finish extracting it from Praxis), and even Gervill if you hacked it out. Software mixing is not exactly hard, particularly if you use float buffers (which any decent audio API does). As Phil says, it's basically just a summation buffer (possibly with some -1:1 limiting or an auto gain control).

Socob only wants to play some sounds like me. Software mixing is not hard for you but it is not the case for me. Paul Lamb has written a nice and easy-to-use API with several plug-ins for JOAL, LWJGL and Java Sound, it supports Ogg Vorbis too. The projects you quote are interesting but in my case, I need an out-of-the box solution, I have no time to hack anything about sound, I cannot spend some time in building all my tools, I have to focus on some things. With Paul Lamb Sound Library, you almost only have to know whether you want to stream your sound or not and which plug-ins you have to use depending on which file formats you need, you can learn how to use it in less than an hour, it is an excellent solution if you do not have any time to tinker existing solutions. Paul Lamb knows the limitations of each APIs he uses, he tries to work around them when possible. Therefore, I think that someone who is not a specialist of sound will have less problems and will waste less time by using it instead of using directly Java Sound or by using the APIs you suggest. I know only some of them, maybe I'm wrong.

The Theremin isn't working? Interesting. When you drag the mouse upwards, the volume should rise. Are you able to get other sounds via other Java programs? You may have uncovered something that I have not dealt with yet!

Unfortunately, I can't seem to get any sound out of any of your applets. I have no idea why it works for nsigma, considering we're both using very similar Linux versions (maybe it's related to the Java plugin - Sun/Oracle vs. OpenJDK - but that shouldn't matter, right?). Regarding the sound approach in the game again (synchronization), you can't really stop the sound once it's playing, that's correct. Keep in mind that the game had to be created within 48 hours, though, and that the sound is extremely simplistic. As I intend to take part in that competition eventually, as well, (with the somewhat self-imposed limit of using "pure" Java), I doubt I'll have time or energy to deal with annoying sound issues or to implement some complex sound system.

@nsigma:So, basically, I seem to have approached the JavaSound API in the wrong way. What I was basically looking for was the way it was used in my first post - you load a file, get a sound clip, let it play when it's needed, and it gets done without much trouble. I don't need any special features or anything (heck, for this, I don't even need volume control). I haven't had time to look at your links/suggestions yet, but I'll see what I can get done. Still, isn't there an easier way to do something relatively simple like this? So far, JavaSound seems terribly non-portable and completely opposite to Java's cross-platform goals.

@gouessej:You've desribed my problem pretty exactly - I don't want/need sophisticated audio due to the circumstances. OpenAL would be a solution, but as I've said, I'd like to avoid native libraries. That doesn't mean it doesn't work, though - in fact, the Slick2D library (which uses LWJGL/OpenAL) does pretty much exactly what I want: you create a "Sound" object, call a "play" method, and you're done. The problem is that I want that, but without native dependencies. I'll have a look at Paul's library, it seems to be pretty popular.

Therefore, it is not a problem in ALSA. Non-Java applications and APIs using it work fine, better than OSS. I don't see what you mean because ALSA supports multiple lines only if the underlying hardware supports hardware mixing.

I didn't say it was a problem with ALSA. Non-Java applications work fine, and so do Java applications when they do what the majority of native applications do, which is software mix to a single line! ALSA (leaving aside dmix for a minute) only supports multiple lines where the soundcard itself provides them. ALSA through dmix, and also PulseAudio, provide software mixing on top of the basic ALSA drivers. However, this is to allow multiple software to play at the same time, not usually to allow any individual software to open multiple lines.

And there are many other options - Beads, Rasmus, JASS, Toot, RAPL (when I finish extracting it from Praxis), and even Gervill if you hacked it out. Software mixing is not exactly hard, particularly if you use float buffers (which any decent audio API does). As Phil says, it's basically just a summation buffer (possibly with some -1:1 limiting or an auto gain control).

Socob only wants to play some sounds like me. Software mixing is not hard for you but it is not the case for me. Paul Lamb has written a nice and easy-to-use API with several plug-ins for JOAL, LWJGL and Java Sound, it supports Ogg Vorbis too. The projects you quote are interesting but in my case, I need an out-of-the box solution, I have no time to hack anything about sound, I cannot spend some time in building all my tools, I have to focus on some things. With Paul Lamb Sound Library, you almost only have to know whether you want to stream your sound or not and which plug-ins you have to use depending on which file formats you need, you can learn how to use it in less than an hour, it is an excellent solution if you do not have any time to tinker existing solutions. Paul Lamb knows the limitations of each APIs he uses, he tries to work around them when possible. Therefore, I think that someone who is not a specialist of sound will have less problems and will waste less time by using it instead of using directly Java Sound or by using the APIs you suggest. I know only some of them, maybe I'm wrong.

I understand all that, and I'm not trying to suggest everyone become an audio specialist (although I don't believe for a minute you'd really find software mixing hard considering what else you've done - it's basically summing arrays of data). Both Beads and JASS could probably work out of the box pretty much for this, though licences would be an issue for some - that's why my intention with RAPL is to be GPL+CPE. There is a definite need for a nice audio library built on top of JavaSound that makes this simple to work with, and I gave some examples of some I already know about. Paul's library has a nice API, but I don't agree with you that he's working around the limitation of the APIs, at least for JavaSound - all the mixers tell you how many simultaneous lines they can support, which on Linux will generally be 1!

@nsigma:So, basically, I seem to have approached the JavaSound API in the wrong way. What I was basically looking for was the way it was used in my first post - you load a file, get a sound clip, let it play when it's needed, and it gets done without much trouble. I don't need any special features or anything (heck, for this, I don't even need volume control). I haven't had time to look at your links/suggestions yet, but I'll see what I can get done. Still, isn't there an easier way to do something relatively simple like this?

Yeah, that's the bit of JavaSound that doesn't work very well! Personally, I'd look for a simple 3rd-party replacement. From my list I'd look at Beads or JASS first, or maybe some of the audio libraries written for Processing.

Not really. The API allows you to query the underlying system for capabilities. You just can't expect the same capabilities on every platform, but I'd rather Java echoed the underlying system than tried to paper over the cracks! Lots of things in Java work differently on different platforms - as long as the API allows you to query the difference, I don't see the problem with that.

@gouessej:You've desribed my problem pretty exactly - I don't want/need sophisticated audio due to the circumstances. OpenAL would be a solution, but as I've said, I'd like to avoid native libraries. That doesn't mean it doesn't work, though - in fact, the Slick2D library (which uses LWJGL/OpenAL) does pretty much exactly what I want: you create a "Sound" object, call a "play" method, and you're done. The problem is that I want that, but without native dependencies. I'll have a look at Paul's library, it seems to be pretty popular.

Ok, you're right. If you want to avoid native dependencies, OpenAL is not the way to go. Paul Lamb Sound Library is even used by Minecraft It would allow you to go on using Java Sound without needing any extra effort to switch to JOAL (except for deployment).

That is the same class used in the AudioServers code you were asking me about a month ago! If you'd bothered to follow up on my long reply to your question you'd have found it.

The other 'conversion' code potentially of use is interpolation to handle pitch changes - not so much to handle dynamic pitch changes but for sample rate conversion. I say potentially because it makes more sense to convert all your samples to the same sample rate beforehand, but I know not everyone does. There is some good code for this in Gervill too, though from recollection the API is not as simple to use externally as it could be.

That is the same class used in the AudioServers code you were asking me about a month ago! If you'd bothered to follow up on my long reply to your question you'd have found it.

Sorry. I remind you that I'm a former participant to a silly reality TV show, it has caused me a lot of troubles and it is sometimes difficult for me to stay focused. I put this link into my bookmarks. Anyway, I still think writing a software mixer is not trivial, at least for me.

Socob, just went to check out Phil's theremin and got no sound this time. I know the reason though - I'd just watched a Flash video. Restarting Firefox fixed this, but I've noticed this before - Flash can have a tendency to not release the soundcard so Java can't get an output line. It probably doesn't cover your issue, but it's another one to be aware of.

@nsigma:Well, that's cool beans, because I come into contact with Flash all the time. Also, having to tell users to avoid Flash if they want sound doesn't sound fun.

As a general update, I've tried out Paul's library. As expected, using it with OpenAL works perfectly without trouble. However, if I use the JavaSound part of Paul's library, I get the exact same problems as before: No sound whatsoever with the Sun/Oracle JDK, and slow/error-prone sound with OpenJDK. I guess I can try some of the other suggested libraries later, but at this point, I don't see how that would change things. To be honest, I'm getting extremely annoyed with this. I mean, what's the point of trying to do something like software mixing or using another library if I can't get a single sound out of the Sun/Oracle JDK at all? I'm not trying to do anything fancy, like opening multiple lines or anything. I tested each of the available mixers by getting a single line from the mixer and trying to play one .wav file with that. Half of them crashed with an exception with even the most basic .wav file (unsupported format - well, what format is supported, then?), while the other half just didn't do anything. The fact that I do get sound with OpenJDK seems to be related to the missing mixers after all - Google found me this link: http://mail.openjdk.java.net/pipermail/sound-dev/2011-May/000115.html, which indicates that with the Sun/Oracle JDK, JavaSound does not seem to provide any mixers on Linux that work reliably. The "Java Sound Audio Engine" mixer, which I've also seen mentioned sometimes, doesn't even seem to exist on my machine.

Really, it's going to take a lot to convince me that JavaSound on Linux is not completely worthless. Actually, it would help if anyone could post a tiny bit of example code that plays a sound on Linux with the Oracle/Sun JDK, because I haven't seen that yet. In particular, it would help because I'm still not sure if I'm using the API the "right" way, since one apparently has to follow a bunch of obscure, undocumented rules to do anything with JavaSound/Linux.

Well, you could try out the audio examples in Praxis (link in sig - also see JAudioLibs thread linked above), but I don't think this would class as a lightweight example! I'd still be interested to know if it has the same issue mind you ...

The best bet is probably to try the JSInfo applet / application at http://www.jsresources.org/apps/jsinfo.html. The applet should be fine for testing output, though doesn't give you access to all of JavaSound (eg. input needs security permissions). Not only does this allow you to query all the mixers, it gives you a GUI for running through all the various line open permutations with test sound output and will tell you of any errors. Source code for it is available, and there are some other simple audio examples on that site.

The message you linked to highlights the issue that Java (Oracle one) always wants to open the soundcard exclusively - Flash used to be (sometimes still is?) the same. It is highly likely that you've got another application accessing the soundcard (try switching off any sound theme for the desktop, checking for any audio apps in system tray, and possibly killing pulseaudio too and see if that helps at all). This is the reason a PulseAudio mixer was added to OpenJDK - not sure if that made its way into Java 7?! Personally, I find PulseAudio to be more trouble than it's worth most of the time though.

@nsigma:At first, I was like "what the heck are you talking about?", then I looked at my post and went "how did THAT happen?".

Anyway, I'm kind of shocked. The Audio example in Praxis seems to work without any trouble at all, even while playing Flash videos at the same time. How did you do that? Does it use anything else other than JavaSound for audio output? If not, I think I'll take a very close look at Praxis/JAudioLibs after all.

As for the JSInfo applet, that is indeed useful, especially if you have no idea what the mixers are actually supposed to do (input or output) (like me). I couldn't get sound output to work with that, but the GUI confused me a little, so I might've been doing it wrong.

Regarding the PulseAudio mixer, I already seem to have that with OpenJDK 6 (-> first post). OpenJDK also has the "default" ALSA mixer mentioned in the link I posted, which doesn't seem to lock the soundcard exclusively and which apparently does work (even on my machine), so even if you don't like PulseAudio, I don't see why this shouldn't be included in both JDKs, as it seems to be (almost?) the only reliable way. Now, of course I could try to close everything I have running, kill PulseAudio and so on and perhaps eventually get sound output with one of the mixers even with the Sun/Oracle JDK, but I can't expect my users to do the same thing. There really needs to be a way to output sound without having to impose any kind of ridiculous, strict set of rules on the users, otherwise they're just not going to bother, even if it's not really the developer's fault.

Anyway, I'm kind of shocked. The Audio example in Praxis seems to work without any trouble at all, even while playing Flash videos at the same time. How did you do that? Does it use anything else other than JavaSound for audio output? If not, I think I'll take a very close look at Praxis/JAudioLibs after all.

* Praxis is currently set up to always open input lines as well (I doubt this is your issue).* Praxis always iterates through the mixers to find one that supports output lines. See the find...Mixer() methods in the above class. I wonder if it's possible that you're experiencing the same issue that gouessej has with JavaSound picking a soundcard (webcam) that is input only. Although I think you said you'd tried all mixers?

As for the JSInfo applet, that is indeed useful, especially if you have no idea what the mixers are actually supposed to do (input or output) (like me). I couldn't get sound output to work with that, but the GUI confused me a little, so I might've been doing it wrong.

It's not easy to find your way around, that's for sure! Use the "Line Lifecycle" tab, and click Line [create -> open -> start] and then Data [start]. There doesn't seem to be a way to select a particular mixer for this though.

Regarding the PulseAudio mixer, I already seem to have that with OpenJDK 6 (-> first post). OpenJDK also has the "default" ALSA mixer mentioned in the link I posted, which doesn't seem to lock the soundcard exclusively and which apparently does work (even on my machine), so even if you don't like PulseAudio, I don't see why this shouldn't be included in both JDKs, as it seems to be (almost?) the only reliable way. Now, of course I could try to close everything I have running, kill PulseAudio and so on and perhaps eventually get sound output with one of the mixers even with the Sun/Oracle JDK, but I can't expect my users to do the same thing. There really needs to be a way to output sound without having to impose any kind of ridiculous, strict set of rules on the users, otherwise they're just not going to bother, even if it's not really the developer's fault.

Don't get me wrong, I'd like to see the PulseAudio mixer and an up-to-date ALSA mixer in the standard Oracle JDK, and I wonder whether it's made it in to 7 (not looked yet). It's just that I've had issues with PulseAudio in the past, and quite frankly don't have much interest in multiple applications playing audio at the same time - I've only one set of ears! I'm all for having the choice though.

I should point out also that on my setup I don't have to jump through any hoops (ie. kill PulseAudio) to get Java sound - I think PulseAudio should auto-suspend when nothing is playing through it.

I'm probably going to be offline for the next week, so good luck with it!

Socob, you can get better results with JavaSound (and Paul Lamb Sound Library) by converting your files to another format or change the rate (or the sample size; if it is 32, set it to 16 bits). I did it for my game and now, it is ... less bad, it works reliably on Oracle JVM but not completely on OpenJDK.

@nsigma (even if you're offline ;-) ):I have the suspicion that Praxis might perhaps be started with OpenJDK instead of the Sun/Oracle JVM for some reason on my computer. I started it with the launch script in the "bin" directory, so I don't really know what it's doing, and I haven't found another way to launch it. Still looking into the code, regardless. Also, PulseAudio does auto-suspend if nothing is playing - it's been enough for me to just get rid of every application that's even remotely related to sound, mainly Firefox/Flash, and then JavaSound actually manages to work even with the Oracle JVM (which doesn't help much, of course).

@gouessej:So, you mean you can play sounds with the Oracle JVM on Linux even if you have, say, a Flash video playing at the same time? That would be strange, because OpenJDK seems to work a lot better for me, and as I said, I can't get sound with the Oracle JVM at all if something else is using sound at the same time. As for the file format, I'm basically already using the most simple file sound format there is. As I wrote in the first post, I'm trying to play uncompressed 44100 Hz, 16bit signed, mono/stereo .wav files, so I don't really know what I should change it to that would work better.

It depends on the mixer you use but relying on the availability of such a mixer is not a good idea.

Maybe Praxis is started with OpenJDK because your Linux is configured to use it by default like mine. You can try to use Praxis with Oracle JVM by modifying the script to use this JVM instead of OpenJDK.

I understand all that, and I'm not trying to suggest everyone become an audio specialist (although I don't believe for a minute you'd really find software mixing hard considering what else you've done - it's basically summing arrays of data).

The best solution is to do software mixing on a single line, as you've pointed out. Unfortunately, there is a little more to it than your characterization if you need to support pitch changes, panning, and mixing multiple formats. Sure, all those can be done as well, but then you also have to get it to run at an acceptable speed to avoid latency. Doing the mixing in native rather than pure java is really the way this should be done.. OpenJDK really should ship with its own native software mixer, like the Java Sound Audio Engine.

Paul's library has a nice API, but I don't agree with you that he's working around the limitation of the APIs, at least for JavaSound - all the mixers tell you how many simultaneous lines they can support, which on Linux will generally be 1!

Personally I wouldn't characterize my library as working around the limitation of the API (thats kind of an oxymoron if you think about it), but rather providing a common API to access various other lower-level APIs.

We love death. The US loves life. That is the difference between us. -Osama bin Laden, mass murderer

The best solution is to do software mixing on a single line, as you've pointed out. Unfortunately, there is a little more to it than your characterization if you need to support pitch changes, panning, and mixing multiple formats. Sure, all those can be done as well, but then you also have to get it to run at an acceptable speed to avoid latency.

I think most people here would love to simply play audio reliably. Mixing different formats in plain Java is 'fast enough', if you keep it at that. After we have something that works, it might be time to add features like pitch changes and panning, although I doubt many of us are even remotely interested in such features => K.I.S.S.

Hi, appreciate more people! Σ ♥ = ¾Learn how to award medals... and work your way up the social rankings!

java-gaming.org 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‑gaming.org