3D Sound Engine

Interesting. I was using SoundSystemJPCT while you use SoundSystem. I took the version of the files you use, switch to using SoundSystem and now it plays my small .ogg files. I wonder if this means there is a bug with SoundSystemJPCT?

All the same thank you very much for your help gouessej! I can use fades with SoundSystem so I think I’ll stick to just that. I get the jittery sound bug using Java Sound so I think I’ll continue using OpenAL.

Sorry for the late response, I just got back from vacation. CWolf, I expect the problem was because SoundSystemJPCT ships with the CodecJOgg plugin by default rather than CodecJOrbis. The reason for this decision was that although JOgg has several compatibility problems (such as with short .ogg files) it has a much less restrictive license (pretty much do what you want). By comparison, JOrbis is licensed by the LGPL (not as bad as the GPL, but it still requires the developer to provide users with a way to swap out the JOrbic code with other/newer versions). If you can live with those restrictions, you can always tell SoundSystemJPCT to use CodecJorbis instead, using the setCodec method (must be done after SoundSystemJPCT is instantiated, or it will just switch back to CodecJOgg. Alternately, you could just edit the constructor method so it loads JOrbis instead of JOgg) That being said, I personally feel like SoundSystemJPCT is rather bloated, and would recommend using the core library anyway, and just add the features you need for your particular project.

Wow, this library is great, just what I’ve needed. Just one thing: is there any way to load a sound from a normal absolute file path? E.g., “/home/maskull/projects/whatever.wav”? It seems like the only options are to load from a URL (which doesn’t seem to accept file:// URLs) or from within the JAR. Unless I’m missing something obvious (as usual).

You can create an URL from a file path as far as I know.

Yes you can.

http://download.oracle.com/javase/6/docs/api/java/net/URL.html

You can use file:// to get a file from the disk, just like from a browser. You can even use http://localhost:8080/myfile if you want, although I don’t know if the latter always works.

I tried using a file URL, but apparently it only works if you prefixed the file path with “file:/”, NOT if you use “file://”. Or maybe it’s just something strange about my setup? I’m pretty sure that the localhost/port 8080 URL will only work if you’re running a local webserver. Anyway, this works for me:

URL url = new URL("file:/" + path_to_file);
mySoundSystem.backgroundMusic("music", url, "filename.wav", true); // or whatever

That’s probably because the file:// version isn’t a valid URI. The URI spec is file://host/path If you don’t have a host (which most file URIs don’t) you can omit host and just start with file:/ or leave it empty and start with file:///

Or simply put for the majority of cases, 1 or 3 slashes is valid, 2 isn’t.

Got bitten by this one myself a while back.

Best wishes, Neil

Hi Paul, I have a quick question. How well tested is the SoundSystem on Linux (Ubunbu in my case)? I’m trying to test it in Ubuntu and I get a problem with the JOrbis codec initialisation (CodecJOrbis). Would you have any ideas on this issue? Everything works great in Windows.


Starting up SoundSystem...
Initializing LWJGL OpenAL
    (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.org)
OpenAL initialized.

Exception in thread "Thread-3" java.lang.NullPointerException
	at paulscode.sound.codecs.CodecJOrbis.initialize(CodecJOrbis.java:259)
	at paulscode.sound.libraries.SourceLWJGLOpenAL.play(SourceLWJGLOpenAL.java:616)
	at paulscode.sound.Library.play(Library.java:706)
	at paulscode.sound.Library.play(Library.java:675)
	at paulscode.sound.SoundSystem.CommandPlay(SoundSystem.java:2076)
	at paulscode.sound.SoundSystem.CommandQueue(SoundSystem.java:2599)
	at paulscode.sound.CommandThread.run(CommandThread.java:121)

I use Ubuntu as well, so it has been tested more on Linux than in Windows from my end. This is the first time this problem has been reported. Let me put together some tests for you to run to try and track down the source of the problem.

Thank you! I appreciate the help :). I’m not able to work on this until the weekend but I’ll try swapping out Jorbis for Jogg codecs to see if that makes a difference when I get home from being away with work.

First off, I want to express my deep appreciation to you (Paul) for not only writing this code and making it available, but also for the well-written documentation. I just finished reading “3D Sound with SoundSystem” and am gung-ho to give the library a try with my puzzle game http://www.java-gaming.org/index.php/topic,23676.0.html which badly needs the ability to use compressed sound resources.

One of the things I intend to do is to loop a continuously-sounding (no silent spots) background of about 30 seconds. However, instead of a direct end-to-end connection for the looping, I intend a slight overlap of approximately a quarter second. The sound was recorded with endpoint fades with this usage in mind. A crossfade overlap minimizes the chance of an audible click or glitch in the sound marking the looping point.

I thought I’d check first to see (1) if you had already implemented something along these lines; and (2) if I succeeded in creating a “simple” version, would it be a useful addition? The function would consume, at the least, for the moment of overlap, two streaming channels. The command might be something along these lines:

mySoundSystem.backgroundOverlap(“Ambient 1”, “ambientPad.ogg”, startOverlapTime [, fadeTime])

Thus, if ambientPad.ogg takes 30 seconds, the startOverlapTime might be set to 29800 msec and the fadeTime might be 200 msec. From 29800 to 30000, the first instance of ambientPad.ogg would be attenuated and reset and a second instance would be faded in. Then, after another 29800 msec, the second instance starts fading out and the first instance restarts with a fade in, the cross fade again taking 200 msec.

The alternative form (omitting the optional fadeTime), would simply start the second instance at the designated time and allow the first instance to end naturally, alternating as before. This form could be used by people who have already built fades into their sounds.

What do you think? I’m quite open to suggestions! I did this in Hexara with .wav “Clip” objects in the javax.sound.sample library. I’m hoping to recreate this with your library, taking advantage of the OGG playback.

philfrei, that is actually a really good idea. The SoundSystem already has a “stream queue” implementation, so it shouldn’t be too difficult to extend that capability to allow a fade out/in between the items in the queue. I’ll look into this when I have the time. Unfortunately, I may not have any time for programming for a couple of weeks, because I am preparing for a six-month deployment in the beginning of March. I am bringing my netbook with me, which has all the tools I need on it, so I should be able to continue further development in my free time while I’m there.

I have fixed my problem. I was using ‘sounds/’ as my package instead of ‘Sounds/’. Since Windows isn’t file system case specific it didn’t have any problem finding my sounds while since Linux is file system case specific it failed to find my sounds. Easily fixed. Thanks.

Oh good, glad to see it is fixed. I do need to handle this better though, so the error message indicates the cause of the problem is that the file was not found.

Hi!

I have no sound on OpenJDK, I get this when I launch my game:

[quote][INFO] All sound files have been loaded successfully
=== checking the Java Sound System: ===
need: interface SourceDataLine supporting format PCM_UNSIGNED 32000.0 Hz, 8 bit, mono, 1 bytes/frame,
need: interface Clip supporting format PCM_SIGNED 32000.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian
no matching Java Sound AudioMixer found.
searching by properties…
default [default], version 1.0.23: 1 lines supported
default [default], version 1.0.23: 1 clips supported
V8237 [plughw:0,0], version 1.0.23: 4 lines supported
V8237 [plughw:0,0], version 1.0.23: 4 clips supported
…match
Java 2 sound startup failed.
[/quote]
Do you have any idea? How can I fix this bug?

It’s been a while since I worked on this part. I’ll have to look at it a little more closely. My guess from the output though is that the mixer it picked only allows a certain amount of lines to be created and I’m not closing them correctly before creating new ones.

Thanks. Let me know whether switching to JOAL + OpenALSoft would be a more viable option than trying to use JavaSound with OpenJDK.

Sorry, that was my fault. The bug is not reproducible with a more recent version of your library.

Oh, cool. Let me know if there are any other problems with OpenJDK. I really should work on finishing my own software mixer. I got a little burned out on the project and never got around to working out all the bugs.

I now systematically test my game both on OpenJDK and Oracle Java :slight_smile: Let me know when your software mixer is ready, I’m impatient to give it a try, especially if it allows to overcome some JavaSound limitations. Thank you very much for your great API.