3D Sound System

I agree, list of filenames for files and list of sourcenames for sources.

Hello,



I'm trying to add sound to a simple jME application using your Sound System but I' getting errors like:



Error in class 'CodecJOgg'
    url null in method 'initialize'
Error in class 'SourceLWJGL OpenAL'
    Audio Format null in method 'play'
Error in class 'CodecJOgg'
    url null in method 'initialize'
Error in class 'SourceLWJGL OpenAL'
    Audio Format null in method 'play'



or


Error in class 'CodecWav'
    url null in method 'initialize'
Error in class 'CodecWav'
    Audio input stream null in method 'readAll'
Error in class 'LibraryLWJGLOpenAL'
    Sound buffer null in method 'loadSound'
Error in class 'LibraryLWJGLOpenAL'
    Sound buffer was not created for explosion.wav
Error in class 'LibraryLWJGLOpenAL'
    Source 'Source_-1727962294_1738211282' not found in method 'play'



I've tryed also to copy-paste the example number 2 of your manual just to check if it was my mistake but running the example also prints these errors... Any advice?

Regards

Both of these appear to indicate that the URL you are attempting to load a sound file from is null.  Could you please post the parts of your code where you are calling the loadSound, backgroundMusic, or quickPlay methods?  There are several things that could be causing this problem, but my initial guess (without further information) is that you are doing one of the following:


  1. You are not using the getClassLoader() method:


URL myURL = this.getClass().getResource( "myFile.wav" );


instead of:

URL myURL = this.getClass().getClassLoader().getResource( "myFile.wav" );



2) The string filename or path is misspelled (case-sensitive issues, perhaps)

3) The file is compiled into the JAR in a different package than the program is looking

4) You started an in-JAR path string with "/".

At least those are the most common causes of null URLs, but I'll be able to help you better after I see some of your code.

On another note, if you are using SoundSystem in a jME project, you probably want to use the LibraryJOAL plug-in instead of LibraryLWJGLOpenAL, since jME has its own sound stuff that uses JOAL and might cause conflicts with LWJGL's binding of OpenAL (although I have not actually tested it to be sure -  I have had virtually no time to look at jME due to my new work schedule).

Hello,



Thanks for your answer. First of all, just a little background. I'm trying with the second example of the pdf document posted in the first port. The code where I call backgroundMusic and QuickPlay is as follows:



mySoundSystem.backgroundMusic( "Music 1", "beats.ogg", true );



and


mySoundSystem.quickPlay( false, "explosion.wav", false,
20, 0, 0,
SoundSystemConfig.ATTENUATION_ROLLOFF,
SoundSystemConfig.getDefaultRolloff()
);



Answering your gesses:

1.- I'm not using URL's... (as the example didn't), should I? and which method is used to load/play from URL? I've also tryed this.getClass().getClassLoader().getResource( "explosion.wav" ).toString() and returns the full path if executed from the .class file without packaging into a jar file.

2.- The files are correctly spelled (I copy-pasted the filenames just to be sure of that :P). I also tryed full-path, url.toString() and everything I thought of.

3.- As said before, I'm not using jar's (at least for this test)

4.- The same as before...

In this test I'm not using jME but I've also tryed with LibraryJOAL and LibraryJavaSound and got the same results...

Any more ideas???

Thanks

Ok, gotcha.  No, you don't need to use URLs, filenames will work fine.



From your explanation, it looks like the problem may be that "beats.ogg" and "explosion.wav" are not compiled into the JAR in a package called "Sounds".  When using filenames, the file must be compiled into the JAR, and the default location is "Sounds/".



If this is your problem, then there are a couple of ways to solve the problem:


  1. Compile your sound files into the JAR in a package called "Sounds", or set another location using the SoundSystemConfig.setSoundFilesPackage( String location ) method.  Either way, the sound files will need to be compiled into the JAR somewhere.


  2. Use URLs instead of filenames.  This will allow the files to be external rather than inside the JAR.



    If this is not your problem, let me know, and I'll try and think of some other possible causes.  Looking at the code you posted, though, it seems like you are using the loading methods correctly…

Thanks! It's now working I didn't know about the default path for the sound files… Finally I changed it as SoundSystemConfig.setSoundFilesPackage("") :stuck_out_tongue:



Just a quick question, what about if I want to load a sound from a website? f.e. http://www.mysite.com/sound1.wav is there any URL version method or loadSound/QuickPlay(… "http://www.mysite.com/sound1.wav"…) with SoundSystemConfig.setSoundFilesPackage("") could work?



Thank you again.



— EDIT —

Forget the question, I've found the answer in the javadoc…



Anyway, I've found that if I try to play twice the same source, it will sound only once… I mean, for example, 1 source that is 5seconds long. If I try to play it now and after a second, I'm not hearing it twice… I've tested with LWJGLOpenAL and JOAL. Should this work this way?

For the play question, that is one that has been asked before.  Basically, there are two possible behaviors that I could have implemented for calls to the play() method when a source is already playing:


  1. Restart the clip playing at that source from the beginning.


  2. Ignore the call, since the clip is already playing.



    I debated this issue for some time during development, and got feedback from programmers for both sides of the argument.  I eventually went with the latter, for honestly no other reason than that is what OpenAL does by default (technically, so does JavaSound - calls to start() are ignored if a Clip/SourceDataLine instance is already running).



    That being said, the way to get the behavior you want is simply to call stop() immediately before calling play() if you want to restart a source.  Anyway, I think most of the time for 3D sound you would want to create another source (via the quickPlay() method), rather than restarting an existing playing one.



    On the other hand, if you know your clip has reached the end and it still is not replaying, let me know - that would be a bug.



    On a completely unrelated topic - man that cursor position bug with Microsoft IE 8 and percentage-width textareas is really anoying.  I never remember to click the "Compatibility View" button before I start typing.  There is a really simple fix that SMF could implement until Microsoft addresses the problem (someday) - hopefully they do soon.  I can barely read what I am typing (forgive me for any typos in this post!)

Thank you for your answers. I didn't follow the development stage, but this behavior seems to make sense (as equal to joal and javasound) :wink: As I'm using those sources for really small sound effects I'll use the stop()-play() option.


Only the helicopter demo produces sound for me (running ubuntu here). Should they all work?

BitBlt said:

Only the helicopter demo produces sound for me (running ubuntu here). Should they all work?

Thanks for the heads-up.  It appears that JavaSound may not be compatible on your machine but OpenAL is (usually it is the other way around).  Just to check, could you run the "Sound Effects Player" demo again and try pressing the "S" key to switch to OpenAL, then see if it plays sounds there (you'll have to wait a couple of seconds for OpenAL to initialize).  Also, could you copy any messages you see in the Java console?  I'd like to find out if I am able to detect that JavaSound doesn't work on your machine, and throw an exception in that case.  If you are getting an overload of console messages, I'll make a simpler test case for you to run so we can track down where the problem first appears.

I'm using sound library built in jme.

It has many problems so I wanna transfer to your new sound system.

But It seems that there is no event dispatching system for sound stop.

Is there any plan to add this kind of functionalities?

It will be perfect if this framework has these functionality.

Appreciate your great job. XD

I see. Then I have to use checking code for that.

I think, generally, streaming source is used to play long sound such as music

and it sometimes needs 'end event' handling. ( to play another music after that)

But memory source is used to play short sound that doesn't needs 'end event' handling.

But it is just from my experience.

Thanks you for the detailed and kind reply.

mulova said:

I think, generally, streaming source is used to play long sound such as music
and it sometimes needs 'end event' handling. ( to play another music after that)
But memory source is used to play short sound that doesn't needs 'end event' handling.


SoundSystem does have "queueing" methods for streaming sources, which are designed for music "lead ins" and transitions between music.  As I mentioned above, I can easily add in end events for streaming sources if that would be helpful (just not for non-streaming sources, for the aforementioned reasons).

Hi!



I finally use your system in another engine. I will have to find a fix to stop sounds. It would be fine if you provided something to work with Maven.



It is very easy to use, thank you. I needed less than 5 minutes to understand how to play a music in background, the documentation is fine.

gouessej said:

I finally use your system in another engine.

Hey, sorry for taking so long writing an extension that meshes easily with JME.  Between work, school, and my new son, I haven't had free time for much more than bug fixes and simple updates.  What functionality do you need for stopping sounds?  Is there something I should add to the library that would help?  I haven't heard of Maven before - is that an audio library or something?  Do you have a link to information about it?
PaulLamb said:

gouessej said:

I finally use your system in another engine.

Hey, sorry for taking so long writing an extension that meshes easily with JME.  Between work, school, and my new son, I haven't had free time for much more than bug fixes and simple updates.  What functionality do you need for stopping sounds?  Is there something I should add to the library that would help?  I haven't heard of Maven before - is that an audio library or something?  Do you have a link to information about it?

Hi!

Apache Maven is a higher level build tool, the successor of ANT. If you mavenized you own repository, it would ease the integration of your library in other engines. However, I will look at what you do in JMonkeyEngine and do something similar in Ardor3D.

I succeed in stopping background musics. For short sounds, I will play them fully.

I have a problem of performance, there are some slowdowns (the frames per second are dropping) when playing a background music even on a recent machine (I have just tested with a PC with Intel Xeon 2.93 Ghz, NVIDIA Quadro FX 1800, Microsoft Windows Vista Pro). The file is in ogg format and I use CodecJOrbis. You can see the source code here:
https://tuer.svn.sourceforge.net/svnroot/tuer/pre_beta/engine/Ardor3DGameServiceProvider.java

Is there any way of improving this situation? I will try to preload the sound.

Do you allow me to mention your name in the readme.txt file as I use your library? I would like to put your name and the URL of your website to allow people who use my source code to find your project easily.

It is somewhat problematic to preload background music, for a couple of reasons.  Firstly, the decoded audio data tends to be quite large, depending on the length of the cut.  Secondly, the built-in method for pre-loading audio files is only used for non-streaming sources, so you'd have to make your background music a non-streaming source.  This isn't a problem when using OpenAL, but unfortunately JavaSound has a maximum length for Clip's (usually around 5-10 seconds of playback, depending on the sample rate and channels).



On the other hand, if memory is not a concern in your project, it should be possible to pre-load the music and set up a system for feeding the raw data directly to a stream channel (rather than reading it in chunks during playback).  I'll add a couple of methods to make this easier to do, and post an update for you.



That being said, the chunk-reading is done on a seperate stream-thread, so I'm not sure that it should slow down your FPS by a whole lot, but it can never hurt to try and see if using the above method improves performance for you.  I'm actually really surprised that streaming a single audio cut reduces performance by much in the first place (there isn't a whole lot going on except reading in small chunks of data and moving them around on a seperate thread).  I should probably write a performance test program for people to run on various systems to see how much overhead my library adds for various tasks.

On my computer I only notice a lag in performance when I attempt to play too many sources simultaneously (more than 20 or so), but it doesn't become a serious lag problem until they reach the hundreds.  On the other hand, though, I hadn't noticed any lag when playing background music either.  I suppose it is possible that the decoding part is eating up enough processor power on the stream thread, that you notice the performance decrease on your game thread.

Thank you. I would like to attenuate this slowdown a bit and I may avoid using a background music inside the game itself, I hope I won't have such problems with short preloaded sounds.

But I was playing a single background music and this lag is reproducible even on modern computers :frowning: