Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (429)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (468)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / Java Sound & OpenAL / Re: JavaSound on Linux on: 2011-09-12 20:43:43
Audio from multiple applications is not ubiquitous.  Phil and I have both given you examples where this is not the case, and I could give you more Linux ones.  It completely depends what the software is used for, and I'm not just talking high-end commercial audio tools (the commercial ones don't even exist on Linux!).  The only person who's ever "looked" at me in disbelief about this is you (and yes I do sometimes do workshops around this area).
Well, this is, of course, a subjective issue (even if I didn't think you'd challenge my claim that "normal" users wouldn't accept single-application audio). My point was simply that it is extremely rare (I like to think of myself as advanced, technically, and even I hadn't experienced issues like this before) and a severe limitation for the user which requires a convincing legitimation.

From a video games / consumer desktop perspective, which is obviously the focus here, then yes it's needed and I'm not disputing that - I fail to see why you're disputing that sometimes it isn't!
I'm not disputing that! I already mentioned high-end audio tools as a legitimate example, and I'm perfectly willing to accept the cases where such limitations are sufficient - again, they're just rare.

Sorry, that was a flippant way of putting it, but it's only fairly recently that Flash has been fixed in this regard, and if you search the Mint forums you'll find people still sometimes having issue with Flash taking exclusive use of their soundcard.
Well, I didn't know that. But as I said in my opening post, Linux audio is still a mess, because there are too many ways to do it. I guess issues like that are just another facet of that (along with poor support from commercial developers in the case of Flash, of course).

Both Riven and I have said in this thread, don't do this!  The drivers and hardware underlying the mixer implementation are not designed to have lines continually opening and closing.  Open a line and keep it open.  This may involve you using a 3rd-party audio library like one of the ones I suggested earlier, or waiting for Paul to finish his software mixing project.
I didn't intend on actually doing it, namely because of all the problems that have been mentioned - it's just another thing I noticed while experimenting (also, it still feels weird to me to be told to just never use certain parts of the API). The concrete problem I was having is that with very short sound effects, even if I wrote the entire sound effect data to the line's buffer, it wouldn't play because the buffer was bigger than the data itself (at least I think that's what happened). Thus, I needed a way to flush the buffer, but as I mentioned, the methods related to that took ages, defeating the purpose. I think what I ended up doing was just writing more data to the buffer until it was full. So that's the story behind that Wink
2  Java Game APIs & Engines / Java Sound & OpenAL / Re: JavaSound on Linux on: 2011-09-11 13:45:58
Well, Phil's examples aren't Linux applications, but you'll find the same sort of thing with many Linux applications that are aimed at a more pro-audio user base.  You'll find that sort of thing more and more as you head along the consumer-audio -> pro-audio continuum (I say continuum, because it's not an either / or thing).  JACK takes over the soundcard so you'll get the same scenario on Linux with any application that relies on JACK for example, and there are a lot of them.  Sorry, but saying you wouldn't use such program because it interferes with Flash is a daft statement if you don't know what the program is for or why it functions the way it does.  The reason these applications do this is because the performance is better, and depending on what you're trying to do sometimes performance is more important.
Good, and now explain that to someone with no technical experience. They're just going to look at you in disbelief, because audio from multiple applications is ubiquitous. We're talking about video games here, not high-end commercial audio tools. Also, I didn't say "intereferes with Flash", but "needs exclusive access to the sound card". Unlike JavaSound (in its current state on the Oracle JVM), even Flash doesn't need exclusive access, it just tends to keep its lines open (which triggers ALSA/PulseAudio/whatever to keep a lock on the soundcard) longer than necessary.

Bear in mind though that these mixers are already in OpenJDK, and almost all distributions except Mint ship OpenJDK as the default, so I don't necessarily see it as big an issue in the Linux consumer space as you do at the moment!
The mixers are in OpenJDK, but they, too, have problems. As I've mentioned before, certain methods of Lines (like drain() or stop()) take ridiculous amounts of time to return, making things like repeating a short sound effect in quick succession very difficult. Also, Linux Mint does ship with OpenJDK, so I guess you're right when you say that it's not a huge problem - I just don't want to keep going knowing that something is broken.
3  Java Game APIs & Engines / Java Sound & OpenAL / Re: JavaSound on Linux on: 2011-09-10 10:20:34
@philfrei:
Well, I've never heard of either of those programs, so I guess my point still holds Wink
Either way, my first reaction now is that I probably wouldn't use those programs due to the issues they seem to have - which is obviously not the reaction I would want my own users to have.
4  Java Game APIs & Engines / Java Sound & OpenAL / Re: JavaSound on Linux on: 2011-09-09 21:46:06
Grin  I'm not trying to "defend" anything, definitely not JavaSound, just pointing out its limitations (some of which stem from the underlying system) and how to work with them.
Fair enough, even if I don't find the limitations very workable. Grin

I can't remember you specifying you needed multiple applications to play audio at the same time initially, otherwise I'd have made this point a bit stronger earlier.
Uh, well, I didn't even think of mentioning that. I've never heard of a game or even any application that needs exclusive access to the soundcard, especially not in 2011. "Can play audio with multiple applications" just isn't something that I'd put on a feature list; rather, I'd take it for granted.
5  Java Game APIs & Engines / Java Sound & OpenAL / Re: JavaSound on Linux on: 2011-09-08 22:35:05
Damn!  Do you mean you get no sound full stop, or no sound if anything else is playing?
Same issue as with everything else - I can only get sound as long as nothing else is using audio.
You'll never be able to play sound with the Oracle JDK (at least on Java 6) while anything else is playing audio or grabbed the soundcard - remember that Java 6 predates a lot of the improvements made in this area on Linux.
Again, this is what I was talking about - if I can't even play sound at all as long as the soundcard is used, JavaSound is worthless to me. I would be okay with having a GUI for the user to select the correct audio mixer, but telling them to close everything that could even remotely involve sound (even if there is no sound actually playing, as in the case of Flash) is unacceptable. I appreciate javaSound and see why you would defend it, but as long as you can't solve this seemingly simple problem, you're not going to convince me of JavaSound. Wink
Hopefully Java 7 might have corrected some of this - I must check.
I'm also still secretly hoping that things have changed with Java 7, but until that starts hitting the standard repositories (those of Debian/Ubuntu/Linux Mint in my case), there's no point for me to try anything.
Java is quite capable of doing all this without resorting to native code.  I've been coding pure-Java audio DSP projects for 7 years, sometimes on hardware that was 10+ years old, and never had any performance issues doing far more complex things than we're talking about here.
That may be true, and I don't doubt what you're saying. However, the fact that it can be done doesn't mean it can be done easily or without restrictions.
6  Java Game APIs & Engines / Java Sound & OpenAL / Re: JavaSound on Linux on: 2011-08-31 16:19:20
@paulscode:
That's kind of where I'm at in the thought process as well.  If you had even a single line that you could reliably play on, then mixing would be possible, but without that I really can't think of what alternative there is.  Fingers crossed they fix at least one of those issues in the next release of Java.
I hope so, too, but from experience, I'm a little pessimistic about things like that. Either way, the current situation still is what it is.


@gouessej:
It's just extremely annoying that you can't use applets without security warnings if you want sound at all. Sure, if you're working with 3D, the impact is "eased" a little because you're probably already using native libraries anyway, but that's not really an excuse.



So, at this point, I sort of ran out of things to say. It looks to me like we've pretty much reached a consensus on the situation - I guess there's just nothing we can do about it. The sad thing is that on Windows, all of this is trivial and works without issues. I suppose when it comes to JavaSound, I'll have to differentiate between users of different platforms after all (this is what I meant by JavaSound being non-portable). Then again, as Linux users tend to be more knowledgeable anyway, maybe they'll be more accepting and less confused by things like security exceptions. Still, the situation is far from desirable.
7  Java Game APIs & Engines / Java Sound & OpenAL / Re: JavaSound on Linux on: 2011-08-31 10:16:23
Is there only one program (you mentioned Flash video) that causes the problem, or is it caused by anything that plays sound?  Once the offending program(s) are shut down, does sound start working again, or do you have to reboot to get sound back?
As far as I can tell, everything that plays sound causes the problem. I tried a few more programs, and so far, I haven't found anything that didn't cause it. Sound does start working again once I close all of the offending programs, so I don't have to reboot.

Also, for clarification, when NVidia [plughw:0,1] was used, you didn't even hear the first sound play, correct?
Yes.

All that being said, this will only help you if Flash, etc. are not playing.  I'll have to think about this one some more..
I don't know how much (if any) of this changed with Java 1.7, but so far, it does look like JavaSound really is impossible to use reliably on Linux, especially now that the "Java Sound Audio Engine" seems to be gone on some machines for some reason. I guess the only way to solve this at all would be to open a bug report on Java development or something (again, as long as this still happens with Java 1.7)? I really don't see any other way as long as you can't even get the most basic sound output.
8  Java Game APIs & Engines / Java Sound & OpenAL / Re: JavaSound on Linux on: 2011-08-31 02:38:57
@paulscode:
Are those mixers recent additions?  I don't recall those being available in the past (it has been a while since I worked on this though).  I guess even if they are a recent addition, you can't really count on your target audience to have them depending on what version of OpenJDK they're running.
I have no idea how recent they are, but a link I've brought up earlier in this thread suggests that they're at least fairly recent. Even if it is a hindrance, I think it's fair to tell users to update their JRE version. At least it's better than having to tell them to specifically use either an Oracle JRE or OpenJDK, which is what I've been dealing with so far.


Anyway, thank you for posting a test. I'm using Linux Mint 11 32bit with the Oracle JVM 1.6 update 26. First, I tried the Bullet/Target Collision applet with nothing else running (i.e. no Flash or anything) and got sound:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
Starting up SoundSystem...
Initializing Java Sound
    (The Java Sound API.  For more information, see http://java.sun.com/products/java-media/sound/)
Mixer 'NVidia [plughw:0,0]'
    Exists: true
    Minimum Sample Rate: 4000
        Acceptable: true
    Maximum Sample Rate: 48000
        Acceptable: true
    Maximum Lines: 32
        Acceptable: true
    Gain Control: false
    Pan Control: false
    Sample Rate Control: false
    Total Rank: 9
Mixer 'NVidia [plughw:0,1]'
    Exists: true
    Minimum Sample Rate: 4000
        Acceptable: true
    Maximum Sample Rate: 48000
        Acceptable: true
    Maximum Lines: 32
        Acceptable: true
    Gain Control: false
    Pan Control: false
    Sample Rate Control: false
    Total Rank: 9
Mixer 'NVidia [plughw:0,2]'
    Exists: true
    Minimum Sample Rate: 4000
        Acceptable: true
    Maximum Sample Rate: 48000
        Acceptable: true
    Maximum Lines: 0
        Acceptable: false
    Gain Control: false
    Pan Control: false
    Sample Rate Control: false
    Total Rank: 0
Mixer 'Generic [plughw:1,3]'
    Exists: true
    Minimum Sample Rate: 4000
        Acceptable: true
    Maximum Sample Rate: 48000
        Acceptable: true
    Maximum Lines: 32
        Acceptable: true
    Gain Control: false
    Pan Control: false
    Sample Rate Control: false
    Total Rank: 9
Mixer 'Port NVidia [hw:0]'
    Exists: true
    Minimum Sample Rate: 4000
        Acceptable: true
    Maximum Sample Rate: 48000
        Acceptable: true
    Maximum Lines: 0
        Acceptable: false
    Gain Control: false
    Pan Control: false
    Sample Rate Control: false
    Total Rank: 0
Mixer 'Port Generic [hw:1]'
    Exists: true
    Minimum Sample Rate: 4000
        Acceptable: true
    Maximum Sample Rate: 48000
        Acceptable: true
    Maximum Lines: 0
        Acceptable: false
    Gain Control: false
    Pan Control: false
    Sample Rate Control: false
    Total Rank: 0
Attempting to use Mixer 'NVidia [plughw:0,0]'
JavaSound initialized.

Java version is: 1.6.0_26
-> support for BufferedImage
Version helper for 1.5+ initialized!
-> using BufferedImage
Software renderer (OpenGL mode) initialized
Software renderer disposed
Software renderer (OpenGL mode) initialized
Adding Lightsource: 0
Software renderer disposed



Next, I tried the same with a Flash video running at the same time; no sound here:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
Starting up SoundSystem...
Initializing Java Sound
    (The Java Sound API.  For more information, see http://java.sun.com/products/java-media/sound/)
Mixer 'NVidia [plughw:0,0]'
    Exists: true
    Minimum Sample Rate: 4000
        Acceptable: true
    Maximum Sample Rate: 48000
        Acceptable: true
    Maximum Lines: 0
        Acceptable: false
    Gain Control: false
    Pan Control: false
    Sample Rate Control: false
    Total Rank: 0
Mixer 'NVidia [plughw:0,1]'
    Exists: true
    Minimum Sample Rate: 4000
        Acceptable: true
    Maximum Sample Rate: 48000
        Acceptable: true
    Maximum Lines: 32
        Acceptable: true
    Gain Control: false
    Pan Control: false
    Sample Rate Control: false
    Total Rank: 9
Mixer 'NVidia [plughw:0,2]'
    Exists: true
    Minimum Sample Rate: 4000
        Acceptable: true
    Maximum Sample Rate: 48000
        Acceptable: true
    Maximum Lines: 0
        Acceptable: false
    Gain Control: false
    Pan Control: false
    Sample Rate Control: false
    Total Rank: 0
Mixer 'Generic [plughw:1,3]'
    Exists: true
    Minimum Sample Rate: 4000
        Acceptable: true
    Maximum Sample Rate: 48000
        Acceptable: true
    Maximum Lines: 32
        Acceptable: true
    Gain Control: false
    Pan Control: false
    Sample Rate Control: false
    Total Rank: 9
Mixer 'Port NVidia [hw:0]'
    Exists: true
    Minimum Sample Rate: 4000
        Acceptable: true
    Maximum Sample Rate: 48000
        Acceptable: true
    Maximum Lines: 0
        Acceptable: false
    Gain Control: false
    Pan Control: false
    Sample Rate Control: false
    Total Rank: 0
Mixer 'Port Generic [hw:1]'
    Exists: true
    Minimum Sample Rate: 4000
        Acceptable: true
    Maximum Sample Rate: 48000
        Acceptable: true
    Maximum Lines: 0
        Acceptable: false
    Gain Control: false
    Pan Control: false
    Sample Rate Control: false
    Total Rank: 0
Attempting to use Mixer 'NVidia [plughw:0,1]'
JavaSound initialized.

Java version is: 1.6.0_26
-> support for BufferedImage
Version helper for 1.5+ initialized!
-> using BufferedImage
Software renderer (OpenGL mode) initialized
Software renderer disposed
Software renderer (OpenGL mode) initialized
Adding Lightsource: 0
Software renderer disposed


Note that the "NVidia" mixers seem to be related to my soundcard (it's an onboard soundcard). "NVidia [plughw:0,0]" is able to play sound from my speakers, but as you can see, if sound is already running, the maxmimum number of lines is zero. I have no idea what "NVidia [plughw:0,1]" is, but I can't hear anything when that's used.

The mixer called "Generic" is the HDMI port of my graphics card, so I wouldn't want to use that.


Also, I seem to have the same problem that I can only hear the first sound (even in the first test). After I shoot the second laser in the applet, I get this on every shot:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
Error in class 'ChannelJava Sound'
    Unable to attach buffer to clip in method 'attachBuffer'
    ERROR MESSAGE:
        line with format PCM_UNSIGNED 11025.0 Hz, 8 bit, stereo, 2 bytes/frame,  not supported.
    STACK TRACE:
        com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(DirectAudioDevice.java:494)
        com.sun.media.sound.DirectAudioDevice$DirectClip.implOpen(DirectAudioDevice.java:1280)
        com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:107)
        com.sun.media.sound.DirectAudioDevice$DirectClip.open(DirectAudioDevice.java:1061)
        com.sun.media.sound.DirectAudioDevice$DirectClip.open(DirectAudioDevice.java:1028)
        paulscode.sound.libraries.ChannelJavaSound.attachBuffer(ChannelJavaSound.java:278)
        paulscode.sound.libraries.SourceJavaSound.play(SourceJavaSound.java:311)
        paulscode.sound.Library.play(Library.java:706)
        paulscode.sound.Library.play(Library.java:675)
        paulscode.sound.SoundSystem.CommandPlay(SoundSystem.java:2076)
        paulscode.sound.SoundSystem.CommandQueue(SoundSystem.java:2599)
        paulscode.sound.CommandThread.run(CommandThread.java:121)

This error applies to both tests.



For comparison, on OpenJDK (version 1.6 update 22), everything seems to be working fine. Here is the console output:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
Starting up SoundSystem...
Initializing Java Sound
    (The Java Sound API.  For more information, see http://java.sun.com/products/java-media/sound/)
Mixer 'default [default]'
    Exists: true
    Minimum Sample Rate: 4000
        Acceptable: true
    Maximum Sample Rate: 48000
        Acceptable: true
    Maximum Lines: 32
        Acceptable: true
    Gain Control: false
    Pan Control: false
    Sample Rate Control: false
    Total Rank: 9
Mixer 'NVidia [plughw:0,0]'
    Exists: true
    Minimum Sample Rate: 4000
        Acceptable: true
    Maximum Sample Rate: 48000
        Acceptable: true
    Maximum Lines: 0
        Acceptable: false
    Gain Control: false
    Pan Control: false
    Sample Rate Control: false
    Total Rank: 0
Mixer 'NVidia [plughw:0,1]'
    Exists: true
    Minimum Sample Rate: 4000
        Acceptable: true
    Maximum Sample Rate: 48000
        Acceptable: true
    Maximum Lines: 32
        Acceptable: true
    Gain Control: false
    Pan Control: false
    Sample Rate Control: false
    Total Rank: 9
Mixer 'NVidia [plughw:0,2]'
    Exists: true
    Minimum Sample Rate: 4000
        Acceptable: true
    Maximum Sample Rate: 48000
        Acceptable: true
    Maximum Lines: 0
        Acceptable: false
    Gain Control: false
    Pan Control: false
    Sample Rate Control: false
    Total Rank: 0
Mixer 'Generic [plughw:1,3]'
    Exists: true
    Minimum Sample Rate: 4000
        Acceptable: true
    Maximum Sample Rate: 48000
        Acceptable: true
    Maximum Lines: 32
        Acceptable: true
    Gain Control: false
    Pan Control: false
    Sample Rate Control: false
    Total Rank: 9
Mixer 'Port NVidia [hw:0]'
    Exists: true
    Minimum Sample Rate: 4000
        Acceptable: true
    Maximum Sample Rate: 48000
        Acceptable: true
    Maximum Lines: 0
        Acceptable: false
    Gain Control: false
    Pan Control: false
    Sample Rate Control: false
    Total Rank: 0
Mixer 'Port Generic [hw:1]'
    Exists: true
    Minimum Sample Rate: 4000
        Acceptable: true
    Maximum Sample Rate: 48000
        Acceptable: true
    Maximum Lines: 0
        Acceptable: false
    Gain Control: false
    Pan Control: false
    Sample Rate Control: false
    Total Rank: 0
Attempting to use Mixer 'default [default]'
JavaSound initialized.

Java version is: 1.6.0_22
-> support for BufferedImage
Version helper for 1.5+ initialized!
-> using BufferedImage
Software renderer (OpenGL mode) initialized
Software renderer disposed
Software renderer (OpenGL mode) initialized
Adding Lightsource: 0
9  Java Game APIs & Engines / Java Sound & OpenAL / Re: JavaSound on Linux on: 2011-08-30 02:18:11
@gouessej:
I actually have the Oracle JVM set as default for testing. I was right, however - Praxis was (for some reason) still started with OpenJDK. With the Oracle JVM, I have the same issues as before (no sound even with Praxis). So I guess I'm back at the start.


@paulscode:
Nice to have you in this thread! Your library is great (and works fine as long as I avoid JavaSound Wink )! I'm curious, have you ever had reports of similar issues on Linux with current versions of your library, or am I the only one having these kinds of problems with JavaSound?

The best solution is to do software mixing on a single line, as you've pointed out.
My problem with this is that I can't even get a single line on my computer with the Oracle JVM and Linux! Well, I can, but it doesn't do anything if anything is already playing sound. All of the available output mixers (cf. first post) on my machine are affected by this. I mean, I would consider doing software mixing, but before that, I need to be able to output sound at all.

OpenJDK really should ship with its own native software mixer, like the Java Sound Audio Engine.
Now, this is the thing: I don't actually have any problems with sound on Linux with OpenJDK (except that methods like DataLine.stop() or DataLine.drain() take ages to return for some reason). This is because OpenJDK provides additional mixers (like the "default" mixer and the "PulseAudio" mixer). However, even with the Oracle JVM (version 6 update 26), the "Java Sound Audio Engine" mixer is not available on my machine. This only leaves me with what I assume to be mixers with direct access to the soundcard, so if I use those, I either lock up the soundcard or it is already locked, both of which is undesirable. Do you perhaps have any clue why I don't have the "Java Sound Audio Engine" or how I could get away without using it?
10  Java Game APIs & Engines / Java Sound & OpenAL / Re: JavaSound on Linux on: 2011-08-29 16:20:23
@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.
11  Java Game APIs & Engines / Java Sound & OpenAL / Re: JavaSound on Linux on: 2011-08-27 17:21:38
@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.
12  Java Game APIs & Engines / Java Sound & OpenAL / Re: JavaSound on Linux on: 2011-08-27 03:41:45
@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.
13  Java Game APIs & Engines / Java Sound & OpenAL / Re: JavaSound on Linux on: 2011-08-25 16:07:37
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!

My other Applets with sound are http://hexara.com/game.html (warning, slow load) and http://hexara.com/VSL/VSL2.htm
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.
14  Java Game APIs & Engines / Java Sound & OpenAL / Re: JavaSound on Linux on: 2011-08-25 02:29:41
@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  
public static Sound someSound = 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.
15  Java Game APIs & Engines / Java Sound & OpenAL / JavaSound on Linux on: 2011-08-24 23:24:46
Hello everyone,

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):
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
package com.mojang.escape;

import javax.sound.sampled.*;

public class Sound {

   public static Sound altar = loadSound("/snd/altar.wav");
   // load a bunch more sounds...

   public static Sound loadSound(String fileName) {
      Sound sound = new Sound();
      try {
         AudioInputStream ais = AudioSystem.getAudioInputStream(Sound.class.getResource(fileName));
         Clip clip = AudioSystem.getClip();
         clip.open(ais);
         sound.clip = clip;
      } catch (Exception e) {
         System.out.println(e);
      }
      return sound;
   }

   private Clip clip;

   public void play() {
      try {
         if (clip != null) {
            new Thread() {
               public void run() {
                  synchronized (clip) {
                     clip.stop();
                     clip.setFramePosition(0);
                     clip.start();
                  }
               }
            }.start();
         }
      } catch (Exception e) {
         System.out.println(e);
      }
   }

}

The input files are very short .wav files of the type "PCM_SIGNED 44100.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian" (according to "ais.getFormat().toString()").

While this works fine on Windows, it fails on my Linux machine using OpenJDK 1.6 at the line "clip.open(ais);":
1  
2  
3  
4  
5  
6  
7  
8  
java.lang.IllegalArgumentException: Invalid format
        at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.createStream(PulseAudioDataLine.java:143)
        at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.open(PulseAudioDataLine.java:100)
        at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.open(PulseAudioDataLine.java:289)
        at org.classpath.icedtea.pulseaudio.PulseAudioClip.open(PulseAudioClip.java:402)
        at org.classpath.icedtea.pulseaudio.PulseAudioClip.open(PulseAudioClip.java:453)
        at com.mojang.escape.Sound.loadSound(Sound.java:33)
        at com.mojang.escape.Sound.<clinit>(Sound.java:6)

So, I changed the "loadSound()" method to the following:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
   public static Sound loadSound(String fileName) {
      Sound sound = new Sound();
      try {
         AudioInputStream ais = AudioSystem.getAudioInputStream(Sound.class.getResource(fileName));
         Clip clip = (Clip) AudioSystem.getLine(new DataLine.Info(Clip.class, ais.getFormat()));
         clip.open(ais);
         sound.clip = clip;
      } catch (Exception e) {
         e.printStackTrace();
      }
      return sound;
   }

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)":
1  
2  
3  
4  
5  
6  
7  
8  
javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian not supported.
        at com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(DirectAudioDevice.java:494)
        at com.sun.media.sound.DirectAudioDevice$DirectClip.implOpen(DirectAudioDevice.java:1280)
        at com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:107)
        at com.sun.media.sound.DirectAudioDevice$DirectClip.open(DirectAudioDevice.java:1061)
        at com.sun.media.sound.DirectAudioDevice$DirectClip.open(DirectAudioDevice.java:1151)
        at com.mojang.escape.Sound.loadSound(Sound.java:33)
        at com.mojang.escape.Sound.<clinit>(Sound.java:7)

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:
1  
2  
3  
4  
5  
6  
NVidia [plughw:0,0], version 1.0.23
NVidia [plughw:0,1], version 1.0.23
NVidia [plughw:0,2], version 1.0.23
Generic [plughw:1,3], version 1.0.23
Port NVidia [hw:0], version 1.0.23
Port Generic [hw:1], version 1.0.23

while with OpenJDK, I got:
1  
2  
3  
4  
5  
6  
7  
8  
PulseAudio Mixer, version 0.02
default [default], version 1.0.23
NVidia [plughw:0,0], version 1.0.23
NVidia [plughw:0,1], version 1.0.23
NVidia [plughw:0,2], version 1.0.23
Generic [plughw:1,3], version 1.0.23
Port NVidia [hw:0], version 1.0.23
Port Generic [hw:1], version 1.0.23

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!
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

theagentd (6 views)
2014-04-24 23:00:44

xsi3rr4x (83 views)
2014-04-15 18:08:23

BurntPizza (75 views)
2014-04-15 03:46:01

UprightPath (86 views)
2014-04-14 17:39:50

UprightPath (69 views)
2014-04-14 17:35:47

Porlus (86 views)
2014-04-14 15:48:38

tom_mai78101 (109 views)
2014-04-10 04:04:31

BurntPizza (169 views)
2014-04-08 23:06:04

tom_mai78101 (265 views)
2014-04-05 13:34:39

trollwarrior1 (216 views)
2014-04-04 12:06:45
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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
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!