finnkuusisto / TinySound

Simple library for playing sounds and music in Java
http://finnkuusisto.github.com/TinySound
BSD 2-Clause "Simplified" License
99 stars 26 forks source link

TinySound doesn't work on some Linux machines #8

Closed fsmv closed 12 years ago

fsmv commented 12 years ago

When I try to run TinySound from an applet the LineUnavailableException in the init function gets thrown and nothing can load.

finnkuusisto commented 12 years ago

I'm unable to reproduce this problem. What version of Java, OS and browser are you using when you experience this issue?

fsmv commented 12 years ago

I'm using java 1.7.0_03, I'm running Debian, and I'm using Firefox 11.0 the actual applet that was giving me problems can be found here. If you'd really like to, you can look at the source too.

finnkuusisto commented 12 years ago

I'm not getting the LineUnavailableException but it is failing to convert the audio data (at least in Java 6 it is) and I'll see what I can do about that tonight. I'm on Windows right now, but I could probably test it out on a Linux machine tomorrow and see if I can get the LineUnavailableException. I'm really not sure why the applet would behave any different from the application version.

Edit: I've added issue #9 for the conversion problem (which wasn't actually a conversion problem)

finnkuusisto commented 12 years ago

*Fixing issue #9 probably corrected the problem for many users.

I tried it in an applet on two Red Hat machines. It worked on one of them but didn't on the other, though the one it didn't work on was a VM. It wasn't throwing the exception but was failing at the isLineSupported() check (probably would have thrown the exception). I'm really not sure why it isn't supported on some machines as TinySound's base format is the the standard CD format, which is by far the most common format used for audio.

finnkuusisto commented 12 years ago

I changed the title of the issue to reflect what actually appears to be happening.

finnkuusisto commented 12 years ago

@Fsmv Could you compile and run the test at https://gist.github.com/2521119 on your machine where TinySound doesn't seem to be working? It will print some stuff to the terminal and, if you could paste the results here or in a gist, I can perhaps get a better understanding of what is going on. Thanks.

fsmv commented 12 years ago

I ran it and here is the output. If I didn't make it clear though, this issue wasn't happening while running it normally only when I was doing it as a applet.

----------
Audio Line
----------
interface SourceDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian
----------------
Mixers Available
----------------
default [default], version 1.0.21
SB [plughw:0,0], version 1.0.21
SB [plughw:0,1], version 1.0.21
SB [plughw:0,2], version 1.0.21
HDMI [plughw:1,3], version 1.0.21
Port SB [hw:0], version 1.0.21
Port HDMI [hw:1], version 1.0.21
----------------------
Mixers Supporting Line
----------------------
default [default], version 1.0.21
SB [plughw:0,1], version 1.0.21
HDMI [plughw:1,3], version 1.0.21
-------------
Default Mixer
-------------
default [default], version 1.0.21
-----------------------------
AudioSystem.isLineSupported()
-----------------------------
true
-----------
Line Opened
-----------
true

edit: When running it as an applet I get this as the output. Which appears to be no different. Hmm

----------
Audio Line
----------
interface SourceDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian
----------------
Mixers Available
----------------
SB [plughw:0,0], version 1.0.21
SB [plughw:0,1], version 1.0.21
SB [plughw:0,2], version 1.0.21
HDMI [plughw:1,3], version 1.0.21
Port SB [hw:0], version 1.0.21
Port HDMI [hw:1], version 1.0.21
----------------------
Mixers Supporting Line
----------------------
SB [plughw:0,1], version 1.0.21
HDMI [plughw:1,3], version 1.0.21
-------------
Default Mixer
-------------
SB [plughw:0,1], version 1.0.21
-----------------------------
AudioSystem.isLineSupported()
-----------------------------
true
-----------
Line Opened
-----------
true
finnkuusisto commented 12 years ago

Did you run it as an applet through your browser or in an IDE? I don't know if it would produce different results, but it's a thought.

fsmv commented 12 years ago

I ran it in my browser. I changed the main method to init and made it extend Applet and I checked the output in the java console.

finnkuusisto commented 12 years ago

From what I understand, some implementations of Java Sound on Linux only work if they're the only the only thing trying to make use of the sound card. You said that you're using Java 7, but it's entirely possible that your browser uses an older JRE. I'm currently working on some code to make a better choice for opening a line to the speakers, but I did make a small update to TinySound the other night. Could you update your tinysound.jar, make sure nothing is using the speakers and try your applet again?

fsmv commented 12 years ago

I still get output line unavailable! and Tiny sound not initialized! when I try to load sounds. I grabbed the zip archive from the repository but it says the latest commit was 4 days ago. Is that the version you wanted me to try?

finnkuusisto commented 12 years ago

Yeah, that's the latest one. It's unlikely to make a difference though. Perhaps when I get a new version of the Line-opening code I can get you to try it for me. I don't want to become burden, but it would be helpful.

finnkuusisto commented 12 years ago

@Fsmv I have a modified version of TinySound working with your Zombie Siege game at http://pages.cs.wisc.edu/~finn/applet/zombie/. Could you try that out for me? It may work, but there will be some potentially helpful output on the Java console if it doesn't. I'm aware that the applet size is too big; I was just too lazy to change it from my template. I'll also be sure to take it down quickly if you're concerned for your assets.

fsmv commented 12 years ago

Still doesn't work. I get:

-----------------
Mixers Available:
-----------------
SB [plughw:0,0], version 1.0.21
SB [plughw:0,1], version 1.0.21
SB [plughw:0,2], version 1.0.21
HDMI [plughw:1,3], version 1.0.21
Port SB [hw:0], version 1.0.21
Port HDMI [hw:1], version 1.0.21
-------------------
Trying to get line:
-------------------
interface SourceDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian
------------------
Line supported by:
------------------
SB [plughw:0,1], version 1.0.21
HDMI [plughw:1,3], version 1.0.21
Output line unavailable!
TinySound not initialized!

Is this a problem with my sound configuration somehow? Did you say you got it to work with linux? What did you do to make my game run without including the tinysound jar or the sounds in the applet page?

I was interested in the source of your link and found http://pages.cs.wisc.edu/~finn/applet/ and that applet didn't work either. I got this output from it:

Output line unavailable!
TinySound not initialized!
FPS: 42
FPS: 45
FPS: 46
FPS: 43
Exception in thread "Thread-40" java.lang.NullPointerException
    at test.TestScreen.update(TestScreen.java:73)
    at game.Game.run(Game.java:74)
    at game.GameApplet$GameRunner.run(GameApplet.java:44)
    at java.lang.Thread.run(Thread.java:662)

So the same thing that happened in my game happens in that demo applet too.

finnkuusisto commented 12 years ago

So, it looks like there are two mixers supporting the line required, but opening a line on either fails for some reason. I have gotten TinySound to work on multiple Linux machines and the only one that hasn't worked doesn't show any mixers as being available. I suppose it could be a configuration issue, but it's terribly difficult to debug like this. Java Sound in Linux is notorious for being inconsistent.

You could try installing the ALSA packages if you haven't already.

As for getting your game to run without including tinysound.jar or the sounds in the applet's HTML directory, I just included the TinySound source and your sounds in the jar file.

fsmv commented 12 years ago

Weird that didn't work for me when I tried to get it up for the end of Ludum Dare.

I'm fairly sure this is a configuration issue on my part. Pulse volume control lists two devices. 'Internal Audio' and 'Internal Audio Analog Stereo.' Internal Audio I think is attached to the HDMI output which just goes to my monitor and the other is the rear panel output. Normally, applications select Internal Audio initially and I have to set them to Internal Audio Analog Stereo so they play sound.

However Firefox is already set to playback on the correct device and the applet doesn't appear on the list of programs in pulse volume control when I try to run it. Would it attach to Firefox's sound output or try to register its own?

finnkuusisto commented 12 years ago

It tries to get its own line from the mixers, so it could be that the HDMI mixer only has 1 line available and Firefox has it. I guess the other mixer would also have to have given all of its available lines out as well.

Are you saying it worked this time? The reason it may not have worked when you tried to get it up for Ludum Dare may have been different bug (issue #9) that I identified while looking into this issue. Fixing that bug will have corrected applet issues for most users I think.

fsmv commented 12 years ago

No it did not work. I meant that when I had all of the resources inside the jar java couldn't find them. Sorry for the confusion.

Did you test on any systems running pulse audio? I think if its not a issue with pulse audio with the default configuration then it must be something weird going on with my configuration.

finnkuusisto commented 12 years ago

It works on my laptop (Fedora 14) running pulse audio with the default configuration. I actually see a Pulse Audio mixer on mine though.

finnkuusisto commented 12 years ago

I'm closing this issue as it is most likely a configuration issue. If it is not, it still doesn't look like it's anything that can be accounted for in the TinySound code.