3D Sound System

Started by paulscode, March 11, 2008, 02:38:51 AM

Previous topic - Next topic

paulscode

SoundSystemSmall has no dependencies when playing .wav or .mid.  To play .ogg, you must include the j-ogg library.

Oops - I just noticed that I forgot to include that JOgg.jar file in the above SoundSystemSmallSource.zip, so I re-uploaded it (thanks for reminding me by mentioning .ogg!)

fireside

What's different about midi, it says that would be covered in a later tutorial in the pdf?
click here->Fireside 7 Games<-

paulscode

I am working on a more in-depth tutorial right now, but until then, you basically create MIDI sources just like any other sources, using any of the source creation methods (doesn't matter if you use a normal or streaming source method, both do the same thing when you specify a MIDI file).    Easiest method to use would probably be BackgroundMusic().  The file must have the extension '.mid' or '.midi'.

You can manipulate the MIDI source just like any other source (for example, you can change the volume of the MIDI source using the SoundSystem.SetVolume() method.  Attenuation and 3D Panning effects do not apply to MIDI sources.

So that is MIDI in a nut-shell (the tutorial will go a little more in-depth, but that should be enough to get you started).

paulscode

Oops, I just realized that I never uploaded the changes I made to that PDF Tutorial.  The most important difference is that the old version stated that all files are pre-loaded into memory, including those used by streaming sources - THAT IS NO LONGER TRUE!  I hope nobody was confused if they read that.  Streaming sources are actually streamed, not read in all at once.  I also decided to go ahead and add a short section on MIDI into the tutorial before I re-uploaded it.

My next tutorial will go much more in depth into source creation, manipulation, and various settings, and it will explain a little more about what is going on behind the scenes.  The first tutorial was more of a "getting started" type of guide.

paulscode

I got an interesting suggestion today from someone using the SoundSystem.  He wanted to be able to queue up a MIDI loop to play immediately after the end of an intro/lead-in.  I am thinking a function like this would actually be usefull for all types of sources, not just for MIDI (since background music could be in any format).  The way it should work is you specify a sound that you want to play from a particular source as soon as the sound it is currently playing finishes.  You would also indicate if the new sound should loop or play only once.

Only thing I am not sure about is how to handle calls to stop and play in the following situations:

1) The source is stopped before the first sound finishes.  Should a subsequent call to play restart the first sound, then switch to the second sound, or would some other behavior be expected in this case?

2) The first sound finished, and the new sound is playing away when the source was stopped.  Should a subsequent call to play start the new sound or the first sound?  Maybe it should play the new sound, since this would normally be used for background music, and the main music loop is likely to be the new sound?

I think it is a good idea, but I thought I would get some suggestions before I actually implemented it.

fireside

I don't really have enough experience with it yet.  Actually, I haven't gotten a chance to try out your sound program yet.  I've been playing around with a free midi composer right now.  I think being able to specify the next song after the current one is finished would be a good idea if that's what you mean.
click here->Fireside 7 Games<-

elias4444

Hey Paul, I've been looking for a good sound system to plop down into my own game engine. How have you licensed your code? Is it free to use?

paulscode

Yes, it is free to use and alter any way you like, in any commercial and/or non-commercial product or otherwise.  You are not required to give me credit, but of course it would be nice.  Since one of the classes in the library (AudioData) is based on source code from the lwjgl library, if you decide to redistibute the library or source code in its current form or in a modified form, you must include the lwjgl license agreement, which basically says, "this library is offered as is, and we are not responsible for any damages ... etc".  To read the full text of the agreement, see the JavaDoc for the AudioData class, or read the comments in the AudioData class's source code.

paulscode

After looking into the sound-queuing idea more closely, I have decided to only implement this for streaming sources and MIDI sources, not for normal sources.  Reason is that there is no way to know when a playing normal source has reached the end, other than to continuously check if it is still playing.  On the other hand, it is easy to know when a streaming source reaches the end, and at that time the StreamThread can start feeding in audio data from the next sound in the queue.  It is also easy to know when MIDI reaches the end, since an "end of sequence" event occurs, at which point the next sequence in the queue can be loaded into the sequencer.

I think this is an acceptable compromise, since sound queuing is mostly going to be used for background music, which will generally be streaming or MIDI.

zammbi

#279
Hey I think this great work, finally been able to use your library.
I been testing quite a few sound libraries to play ogg for my 2d game and each one has its own problems or rarely gets updated.
Which I'm hoping you can fix the bugs I'm having with Sound System Small.
I am loading a ogg (music) which plays fine.
Then there's some clicking noises in the middle.
After the song finishes it will keep playing a soft sound, small part of my ogg.
It then sucks my ram up.
If I try to loop it, it wont loop.
Also seems I'm having trouble playing my ogg sounds...

paulscode

From you post, it seems you are having the problems only with .ogg files, is this correct?  Could you email me the .ogg file(s) you are having problems with, or post links to them?

Also, could you please let me know the details about your computer (speed, memory, audio hardware, os)? 

Additionally, could you please run the following applet:
http://www.paulscode.com/demos/SoundSystem/01FEB2009/SoundSystemPlayerApplet.html
With the JavaSound library loaded, please stream the file "beats.ogg" (using the space bar), and let me know if the music has the same problems you were experiencing and if it loops correctly.  If you do experience problems, then try the same test in OpenAL to see if there is a problem there as well.

zammbi

#281
The demo posted the sound is perfect hm...
I'm sure I'm not doing anything wrong in my code as I basically follow your examples. But I will test it tomorrow on a plain app (heading to bed now).

Stats:
Duel core 2ghz, 3Gigs of ram, Realtek High definition, Windows 7.

I'll send you the files.

Edit: sent.

paulscode

Ok, great, I got the .ogg files.  I'll run some tests to see if I can track down the problem.  Good to hear the demo applet works for you  - I should be able to just focus on the files themselves.  I'll let you know what I find out.

paulscode

Ok, I've had a little time to look into this.  First of all, the problem happens in both JavaSound and OpenAL, so we can rule out anything specific to JavaSound or SoundSystemSmall.  My initial best-guess is that there may be a problem with the j-ogg library loading process for these specific .ogg files.  The reason I think this, is because for both of these files, the ogg loader is getting into an infinite loop during load time.   A very similar bug, which I've known about for some time, will often occur when loading more than one .ogg file simultaneously (such as when streaming two .ogg files at once).  I can track the problem down to a call to the OggInputStream.read() method, but I don't know enough about how the j-ogg decoding process works to get any closer to the problem than that.

Here's my best explanation of what's happening with your two files:

1) For Intro.ogg, most of the file loads correctly, but the loader gets stuck near the end, loading the same chunk of data over and over again and never reaching EOF.  So when you stream this file, it sounds like the end repeats over and over again.  Also, as you mentioned before, there seems to be some random clicking during playback, which could also be symptomatic of a problem during load-time.

2) For Login Sound.ogg, the exact same problem happens near the beginning of the sound.  The sound effect is silent at this part, so that is why you don't hear anything playing, whether you try to stream the file or pre-load it for a normal source.  It doesn't get very far into the file before the infinite loading loop begins, so it is impossible to tell if this sound would have the same clicking problem as Intro.ogg.

That's all I the information I have for the moment.  I am going to create a small test program much more simple than SoundSystem, so I can hopefully get some help from other programmers who have used the j-ogg library more extensively than I have.  If possible, I'll also try to get in touch with the j-ogg library's developer Jarnbjo.

One more thing that might be useful - do you know what program was used to create these two .ogg files?  It might possibly give me an idea what is special about these two .ogg files as compared to the .ogg files I have been using in all my previous test cases.

paulscode

#284
Progress update:

I have put together my test program and posted the question on a couple of forums.

I have been experimenting with various file converter programs to see if I could produce .ogg files that consistantly have the load-problem, and I found a couple that do - "VLC Media Player" and "MP3 Converter Simple".  Both of these programs have a lot of settings to choose from when saving the .ogg file, so I am going to try and play around with these settings to see if I can figure out what causes the j-ogg loader to choke.  Hopefully that might help in tracking down the source of the problem.  At the very least, it will provide a work-around until I can figure out what is causing the problem (changing the settings on the existing .ogg files to make them compatible with SoundSystem).

--UPDATE--
I have been playing around with converter settings, and I can not seem to find any discernable pattern.  The settings in one converter will produce a file that can't be loaded, while the exact same settings in another converter will produce a file that works fine.  The clicking problem also seems to be completely random from one converter to another.

I did however discover one important thing:  very small .ogg files almost NEVER load properly, no matter what their settings are or which converter was used to create them.  I'm pretty sure that is why your Login Sound.ogg file will not load.

So, until I figure this problem out, here are some work-arounds that you can use:

1) For the larger music sounds that you stream, until I get this problem fixed, just run your files through a converter which produces .ogg files that are compatible with SoundSystem.  A simple freeware one that I like is called "Free Audio Converter", which you can download from http://www.free-audio-editor.com/FreeAudioConverter.exe.  It seems to do best when converting from .wav to .ogg, so I would recommend converting the original .ogg into a high-quality .wav, then convert that back into a .ogg with whatever compression level you want (otherwise it will sometimes add in small random clicks and scratches).

2) Use the .wav format for any small sound effects that you are not streaming.  Note that the actual audio data itself is the same size whether you loaded it from a .wav or a .ogg, so unless you are streaming the audio, there is no advantage to using .ogg files over .wav files.  Of course memory is often a concern for applets, so in order to avoid the memory required to compile your .wav files directly into the JAR, just pre-load their audio date from online URLs instead, by using the loadSound() method.  Just make sure the filename you pass to SoundSystem begins with "http://" (that is how it knows to look online rather than inside the JAR).  Hmm.. I just now realized that I never provided an unloadSound() interface method (I'm sure I did, but it must have disappeared somehow).  Anyway ... I will correct that in the next release.

Sorry for all the .ogg problems.  Hopefully this will be enough to at least get you up and running - I have no idea if I will be able to solve this.  If I can't get j-ogg to work, I may have to end up looking for other alternative ogg libraries.