PaulsCode Forum

General => Paul's Projects => Topic started by: Paul on May 01, 2009, 08:46:45 PM

Title: 3D Sound System
Post by: Paul on May 01, 2009, 08:46:45 PM
-- This slot is reserved for the most recent working releases --

Downloads:

Sound System (http://www.paulscode.com/source/SoundSystem/07JAN2012/SoundSystem.zip)  Version date:  January 7, 2012
The core SoundSystem library, independent from 3rd-party libraries.  It is stripped down to the bare essentials, and designed to be easily customizable with various sound library and codec plug-ins.  If memory is a concern (such as in an applet) this may be a good option, because it allows you to choose as many or as few plug-ins as you require for your project.  NOTE: The core SoundSystem library without any plug-ins is only capable of playing MIDI files.  Additional plug-ins should be added for more capabilities.  The source code and license are included in the .zip file.

Sound System jPCT (http://www.paulscode.com/source/SoundSystem/07JAN2012/SoundSystemJPCT.zip)  Version date:  January, 2012
The jPCT-friendly 3D sound library.  The SoundSystemJPCT class overrides the core SoundSystem libray, and provides a number of methods to make adding 3D sound to any jPCT project easy.  It includes methods for binding Listener to Camera and Sources to Object3Ds, as well as using SimpleVector parameters.  SoundSystemJPCT utilizes the LWJGL binding of OpenAL (with JavaSound as a backup option), and the J-Ogg library for .ogg support.  NOTE: The core SoundSystem library, source code, and all relevant licenses are included in the .zip file.

SoundSystem Utils (http://www.paulscode.com/source/SoundSystem/SoundSystemUtils.zip)  Version date:  August 9, 2009
Includes a SoundSystem loader, and an example XML file.


Plug-ins:

JavaSound library plug-in (http://www.paulscode.com/source/SoundSystem/07JAN2012/LibraryJavaSound.zip)  Version date:  January 7, 2012
Interface to the Java Sound API.  More compatible than OpenAL, but not as high quality and fewer features.  This plug-in utilizes JavaSound's panning and volume control methods to simulate an reasonable-quality 3D sound system.  Known bug: quickPlaying sounds will begin playing them at full volume for a split second, before switching to the correct volume.  This is a bug with the Java Sound API itself, and therefore beyond my control to correct.  An easy workaround is to add 0.02 seconds of silence to the beginning of each sound effect (the free Audacity sound editor (http://audacity.sourceforge.net/) works well for this).

LWJGL OpenAL library plug-in (http://www.paulscode.com/source/SoundSystem/17APR2013/LibraryLWJGLOpenAL.zip)  Version date:  April 17, 2013
Interface to the LWJGL binding of OpenAL.  The LWJGL library (http://www.lwjgl.org (http://www.lwjgl.org)) is required for this plug-in to work.  This library sounds much better than Java Sound, but is not as compatible.  I recommend using the JavaSound library plug-in as a backup option.  NOTE: Please read the included LWJGL license.

JOAL library plug-in (http://www.paulscode.com/source/SoundSystem/17APR2013/LibraryJOAL.zip)  Version date:  April 17, 2013
Interface to the JOAL binding of OpenAL.  The JOAL library (http://jogamp.org (http://jogamp.org/)) is required for this plug-in to work.  As mentioned previously, this library sounds much better than Java Sound, but is not as compatible.  I recommend using the JavaSound library plug-in as a backup option.  NOTE: Please read the included JOAL license.

WAV codec plug-in (http://www.paulscode.com/source/SoundSystem/23OCT2010/CodecWav.zip)  Version date:  October 23, 2010
Adds support for .wav files.

JOgg codec plug-in (http://www.paulscode.com/source/SoundSystem/24AUG2010/CodecJOgg.zip)  Version date:  August 24, 2010
Adds support for .ogg files using the J-Ogg library.  This codec is less compatible than the JOrbis codec, but the license is less restrictive.  Sometimes running incompatable .ogg files through a converter will make them compatable.  NOTE: Please read the included JOgg license.

JOrbis codec plug-in (http://www.paulscode.com/source/SoundSystem/23NOV2010/CodecJOrbis.zip)  Version date:  November 23, 2010
Adds support for .ogg files using the JOrbis library.  More compatible than the JOgg codec, but reads data more slowly (it may not be possible to stream more than one file simultaneously when using this codec).  This plug-in is licensed by the LGPL.  NOTE: Please read the included LGPL document.

IBXM codec plug-in (http://www.paulscode.com/source/SoundSystem/24AUG2010/CodecIBXM.zip)  Version date:  August 24, 2010
Adds support for Protracker, Fast Tracker 2, and Scream Tracker 3 (.s2m, .mod, and .xm) files using the IBXM library.  File sizes for these formats tend to be quite small, so this may be a good option for background music.  This plug-in is based on or using the IBXM library, which is bound by the BSD License.  NOTE: Please read the included license document.

JSpeex codec plug-in (http://www.paulscode.com/source/SoundSystem/24AUG2010/CodecJSpeex.zip)  Version date:  August 24, 2010
Adds support for .ogg or .wav files encoded with Speex (a compression optimized for human voice).  See http://www.speex.org/ (http://www.speex.org/) for more information.


Documentation:

JavaDoc (http://www.paulscode.com/docs/SoundSystem/)  Version date:  November 8, 2011
Also includes the JavaDocs for SoundSystemJPCT and all library and codec plug-ins, and the utils library.

3D Sound with SoundSystem (http://www.paulscode.com/tutorials/SoundSystem/SoundSystem.pdf)  PDF (download the example programs (http://www.paulscode.com/tutorials/SoundSystem/SoundSystemTutorialsSource.zip))
A tutorial-style guide to using the core SoundSystem library (last updated: April 14, 2009).

Guide to SoundSystemJPCT (http://www.paulscode.com/tutorials/SoundSystem/SoundSystemJPCT.pdf)  PDF (download the example programs (http://www.paulscode.com/tutorials/SoundSystem/SoundSystemJPCTTutorialsSource.zip))
Another tutorial-style guide to using SoundSystemJPCT. (last updated: April 14, 2009).


Demos:


Sound Effects Player (http://www.paulscode.com/demos/SoundSystem/21AUG2010/SoundSystemPlayerApplet.html)  (download the Source Code (http://www.paulscode.com/demos/SoundSystem/21AUG2010/SoundSystemPlayerAppletSource.zip))
Demonstrates library switching on the fly, streaming background music, playing MIDI, and playing multiple sources simultaneously.  Last updated August 21, 2010

Bullet / Target Collision (http://www.paulscode.com/source/BulletTargetCollision/)  (download the Source Code (http://www.paulscode.com/source/BulletTargetCollision/BulletTargetCollisionSource.zip))
Demonstrates the LibraryJavaSound plug-in.  Last updated March 30, 2009

Holy Bouncing Helicopter Balls! (http://www.paulscode.com/demos/SoundSystem/21AUG2010/Helicopter.html)  (download the Source Code (http://www.paulscode.com/demos/SoundSystem/21AUG2010/HelicopterSource.zip))
Demonstrates moving through a world with multiple sources.  Last updated August 21, 2010


What's new?

- Fixed raw data stream repeating bug in LibraryLWJGLOpenAL and LibraryJOAL
- Fixed raw data stream millisecond position bug in LibraryLWJGLOpenAL and LibraryJOAL
Title: Re: 3D Sound System
Post by: Paul on May 01, 2009, 08:55:27 PM
Project Overview:

This project began as a problem posted on the jPCT forum about OpenAL being extremely complicated, and that there needs to be a 3D sound library that is easy to understand and use.  I decided to create a class that does all the tedious stuff and simplifies OpenAL.

This project has evolved a lot since then.  I have since added in a plug-in infrastructure for interfacing with multiple 3rd-party sound and codec libraries, the ability to switch between OpenAL and JavaSound on the fly, automatic compatibility checking, and much more.  And of course, I extended the base library to make a version that is easily compatible with jPCT.

If you are interested in reading about the early development of the library, check out the original thread here (http://www.jpct.net/forum2/index.php/topic,1057.0.html).

If anyone has any ideas for improving the library, let me know!


The SoundSystem License:

You are free to use this library for any purpose, commercial or otherwise.
You may modify this library or source code, and distribute it any way you
like, provided the following conditions are met:

1) You may not falsely claim to be the author of this library or any
   unmodified portion of it.
2) You may not copyright this library or a modified version of it and then
   sue me for copyright infringement.
3) If you modify the source code, you must clearly document the changes
   made before redistributing the modified source code, so other users know
   it is not the original code.
4) You are not required to give me credit for this library in any derived
   work, but if you do, you must also mention my website:
   http://www.paulscode.com (http://www.paulscode.com)
5) I the author will not be responsible for any damages (physical,
   financial, or otherwise) caused by the use if this library or any part
   of it.
6) I the author do not guarantee, warrant, or make any representations,
   either expressed or implied, regarding the use of this library or any
   part of it.

Author: Paul Lamb
http://www.paulscode.com (http://www.paulscode.com)
Title: Re: 3D Sound System
Post by: Paul on May 03, 2009, 06:18:57 PM
Today I discovered some delay problems when trying to put together some demos.  This problem didn't exist in earlier versions of SoundSystem, so it must be a problem with something I've added recently.  It appears to be a thread synchronization issue at first glance.  I will post an update after I've solved the problem.
Title: Re: 3D Sound System
Post by: Paul on May 04, 2009, 03:19:19 PM
I haven't been able to solve this problem yet, but I have discovered a couple of interesting things.  Firstly, the problem only appears when running jPCT via the LWJGL Applet Loader, and only for the LibraryLWJGLOpenAL plug-in (LibraryJavaSound works fine, even when loaded via the Applet Loader).  In other words, I can only replicate the problem when mixing the LibraryLWJGLOpenAL plug-in with jPCT in an applet.  Since jPCT relies on the LWJGL, as does the LibraryLWJGLOpenAL plug-in, I suspect there is a thread synchronization problem in my code related to the LWJGL that is conflicting with jPCT.  The confusing thing is that the problem only appears in applets and not applications (due to limited resources, perhaps?)

I am currently working on porting the helicopter demo applet to the JMonkey Engine so I can mix OpenAL and OpenGL in an applet without the LWJGL Applet Loader.  This should either strengthen or refute my theory that the problem is a thread synchronization issue related to the LWJGL.  If the problem exists there as well, then I will start looking at other possible causes, such as memory leaks and the like.  I will post further information as I progress.
Title: Re: 3D Sound System
Post by: Paul on July 28, 2009, 04:17:14 PM
I thought I would share a recent conversation I had with a developer, in case anyone else was having a similar issue.

Quote from: Howard
hey Paul,

I extended your Sound System and added this class/function. My goal is to load all sounds on startup and associate them with a string identifier for play/pause/stop later. I'm not really sure what ManageSources really does but it only works with the QUICK_PLAY option. The question is, is the below correct for what I'm trying to do?

Also, I noticed a minor problem. Sometimes when a sound starts to play, a split second into that sound, the sound starts again. This happens randomly but every so often. It's very slight so you really have to listen for it. After running a bunch of tests I can only assume the CommandThread is going to sleep right after the sound just starts to play and then when the thread is awaken, it finishes off what it started. I don't know. Your thoughts please.

Any help would be greatly appreciated.

howie
Code: [Select]
public class NinjaSound extends SoundSystem
{

    public void loadSound( String sourcename, String filename,
                           boolean toStream, boolean toLoop )
    {
        if( toStream )
        {
            newStreamingSource( true, sourcename, filename, toLoop, 0, 0, 0,
                                SoundSystemConfig.ATTENUATION_NONE, 0 );
        }

        ManageSources( new CommandObject( CommandObject.QUICK_PLAY, true,
                           true, toLoop, sourcename, filename, 0, 0, 0,
                           SoundSystemConfig.ATTENUATION_NONE, 0, false ) );

        if( !toStream )
        {
            loadSound( filename );
        }
    }
}
Quote from: Howard
never mind. I figured it out. I was basing my code on your backgroundMusic function. The newStreamingSource and ManageSources basicly do that same thing so you end up with two calls in the sourceMap.

Code: [Select]
    public void backgroundMusic( String sourcename, String filename,
                                 boolean toLoop )
    {
        newStreamingSource( true, sourcename, filename, toLoop, 0, 0, 0,
                            SoundSystemConfig.ATTENUATION_NONE, 0 );
        // Queue a command to quick stream this new source:
        ManageSources( new CommandObject( CommandObject.QUICK_PLAY, true,
                           true, toLoop, sourcename, filename, 0, 0, 0,
                           SoundSystemConfig.ATTENUATION_NONE, 0, false ) );
        CommandQueue( new CommandObject( CommandObject.PLAY, sourcename) );
       
        commandThread.interrupt();
    }

here's my new function for loading sound.

Code: [Select]
public class NinjaSound extends SoundSystem
{

    public void loadSound( String sourcename, String filename,
                           boolean toStream, boolean toLoop )
    {
        CommandNewSource( false, toStream, toLoop, sourcename,
                          filename, 0, 0, 0,
                          SoundSystemConfig.ATTENUATION_NONE, 0 );

        commandThread.interrupt();
    }
}


Quote from: Paul
Howard,
 
Yes, I can see how this part of the code might be confusing.  I originally made it so quickPlay and backgroundMusic both created a temporary source and then immediately played it (seems logical).  All commands, including these two, were processed in order from the "CommandQueue" method via the Command Thread.
 
However, I later wanted the ability to "cull" and "activate" sources.  This feature is so that developers can extend the SoundSystem and manage which sources should play and which shouldn't based on their own rules.  For example, one might create a game where there are hundreds of simultaneously playing sources, and they only want the closest ones to play on whatever channels are available.
 
This seemingly simple update ended up requiring a significant change to the CommandQueue infrastructure.  All source creation, deletion, cull, and activate commands now needed to be processed first before play commands could be processed (this is the only way to ensure that only the active sources would play and not the culled ones).  So I created a new method called ManageSources, which is basically the same as CommandQueue, except it is called before CommandQueue is called.  This method processes the creation, deletion, cull, and activate commands that needed to be processed first.  The Command Thread processes all commands in the ManageSources queue first, then those in the CommandQueue.  Additionally, the ManageSources method is used in extended classes to sort the sources (by distance, for example), and to cull and activate the proper ones.  After all of those commands in the ManageSources queue are done, the commands in the CommandQueue are processed.
 
This change also required me to change the quickPlay and backgroundMusic methods, because I could no longer have these methods automatically play the new source (cull and activate stuff had to be figured out first via ManageSources).  So I changed it so quickPlay and backgroundMusic queues one command to create the source (via ManageSources), and a second command to play the source (via CommandQueue).
 
Now, I have tested this new infrastructure quite a bit since I wrote it, but I will go back and take another look to make sure two calls to "play" are not happening from the quickPlay and backgroundMusic methods.  I should also add in more comments to that section of the code to explain what is going on and why there are two methods that look virtually the same.
 
Thanks for the insight!
 
-Paul
Quote from: Paul
Howard,

After reviewing the source, you are correct - there is a bug in the backgroundMusic method (not in the quickPlay method, though) -- I am creating two sources with the exact same information.  Nice catch!  I will have this corrected in the next release.

-Paul
Title: Re: 3D Sound System
Post by: Paul on August 08, 2009, 12:36:57 PM
Sound System, Cumulative Updates/Bug-Fixes

Sound System jPCT (http://www.paulscode.com/source/SoundSystem/SoundSystemJPCT.zip)
Sound System (http://www.paulscode.com/source/SoundSystem/SoundSystem.zip)
Sound System Utils (http://www.paulscode.com/source/SoundSystem/SoundSystemUtils.zip)

JavaSound library pluggin (http://www.paulscode.com/source/SoundSystem/LibraryJavaSound.zip)
LWJGL OpenAL library pluggin (http://www.paulscode.com/source/SoundSystem/LibraryLWJGLOpenAL.zip)
JOAL library pluggin (http://www.paulscode.com/source/SoundSystem/LibraryJOAL.zip)

JOrbis codec pluggin (http://www.paulscode.com/source/SoundSystem/CodecJOrbis.zip)

-Made it so initializing OpenAL plug-ins will notify when AL_PITCH is not supported
-Fixed vorbis-header compatability issue with OGG files generated by Audacity
-Improved error-handling in multiple classes
-Updated and added multiple classes to allow user to specify either String filenames or URL instances
-Added new class to associate filename/identifier with URL
-Improved MIDIChannel class - searches for alternate sequencer/synthesizer if defaults don't work
-Added a new method for feeding raw audio data directly to a channel through streaming sources
-Added a new source-creation method to produce streams that can be fed directly with raw audio data
-Added a new SoundSystemUtils library which includes an XML loader
-Corrected problem in LibraryJavaSound plug-in where sources would only play once
-Corrected channel-source association bug which caused rare odd behaviors

Title: Re: 3D Sound System
Post by: Paul on November 08, 2011, 04:43:59 PM
Sound System, Streaming Optimizations


Sound System (http://www.paulscode.com/source/SoundSystem/08NOV2011/SoundSystem.zip)
Sound System jPCT (http://www.paulscode.com/source/SoundSystem/08NOV2011/SoundSystemJPCT.zip)

- Improved transition time between loops of a streaming source
- Added hack to improve streaming performance if files are all the same audio format
Title: Re: 3D Sound System
Post by: Dane on December 14, 2011, 11:45:49 PM
Thank you so much for this, I'll make sure to mention your website in the credits of my project after I get it to work! =)
Title: Re: 3D Sound System
Post by: Enerccio on January 06, 2012, 01:19:13 PM
I came here to download the bugfix on LibraryJavaAudio (about the non looping sources), however, the download links seems to point to nothing. Where is the new download location?
Thanks in advance.
Title: Re: 3D Sound System
Post by: Paul on January 06, 2012, 08:19:49 PM
Just grab the one in the first post of this thread (it is the newest version, and will have that bugfix incorporated).  I'll have to see why those other links went dead (I don't recall changing anything on the server)
Title: Re: 3D Sound System
Post by: Paul on January 07, 2012, 03:02:12 PM
Sound System, Bug Fix

Sound System (http://www.paulscode.com/source/SoundSystem/07JAN2012/SoundSystem.zip)
Sound System jPCT (http://www.paulscode.com/source/SoundSystem/07JAN2012/SoundSystemJPCT.zip)

- Fixed looping stream stutter bug when StreamQueueFormatsMatch is set to true
Title: Re: 3D Sound System
Post by: Enerccio on January 07, 2012, 09:03:14 PM
Unfortunately, that is the version I have. And songs will still not loop at all with Java Sound.
Title: Re: 3D Sound System
Post by: Paul on January 07, 2012, 09:20:04 PM
Hmm, maybe I uploaded the wrong version..  Here try this one (I just tested it, and it works for me):

JavaSound Library Plug-in (http://www.paulscode.com/source/SoundSystem/07JAN2012/LibraryJavaSound.zip)

If it still has the problem, could you upload one of the files you are having troubles with so I can see if there is anything with the file that might be causing this?  Also, is this happening with streaming sources or normal sources (or both?)
Title: Re: 3D Sound System
Post by: Enerccio on January 07, 2012, 10:34:25 PM
It still doesnt work. Here is the testing sound: http://www.sendspace.com/file/pat7cb

I also had to fix one bug in the de.jarnbjo.ogg, which was causing the infinite loop while loading small oggs: http://pastebin.com/L1XDpzPh
Title: Re: 3D Sound System
Post by: Paul on January 08, 2012, 10:14:21 AM
It works fine on my computer.  I'd be just about willing to bet your problem the JavaSound bug that only lets you create a limited number of lines (often either 1 or 32), after which no more can be created even if you close and destroy the other ones.  If this is what you are experiencing, then you would only be able to play 1 source (or possibly 32 in sequence), after which sound would stop working all together.  Is this what you are experiencing?  If not, I'll keep looking to see where your problem is located.

Unfortunately, the line problem is a limitation with JavaSound not the SoundSystem.  The only way around it is to write my own software mixer rather than using the ones available in JavaSound (so I can just open a single line and use it to play everything).  I've started developing one, but it may be some time before I get back to finishing it (my other project will be taking up most of my free time for a while).  I know other folks have been developing mixers for JavaSound, so you might do a little searching to see if you can find something you can use, otherwise I'd recommend switching to one of the other Library plug-ins for now.

--EDIT--
Also, the only change I could see in the CachedUrlStream.java code you posted was:
Code: [Select]
      while(!loaderThread.isBosDone() || pageOffsets.size()<5) {
         try {
            Thread.sleep(5);
         }
         catch (InterruptedException ex) {
         }
      }
(specifically, changed the number in the while loop and the length of the thread sleep).  Are those really the only changes, or did I miss something?
Title: Re: 3D Sound System
Post by: Enerccio on January 08, 2012, 03:41:29 PM
It happens every time I play music, doesn't matter how many sounds were before. It will simply stay. Closer inspection will give me that underlining DataLine is reporting it to be active.

The reason why I switched to JavaSound was, that LWJGL one was incredibly choppy and laggy playback.

As for the CachedUrlStream, yes, the change was the amount from 20 to 5 (thread sleep was probably just a testing change), because without it, small oggs, would be stack at  7 pages, looping forever.

I also have an user question, how can you play same source more than one time simultaneously? Possibly with one source, because having multiple names for many sources is inconvenient.

Because right now, with preloaded sound, I use quickPlay every time, but sometimes it lags before playing in the quickPlay method for some reason:

it will lag between
HERE
and
THERE

this is my player:

http://paste.pocoo.org/show/ok7jOd0qmHZfkkkiBhYa/
Title: Re: 3D Sound System
Post by: Paul on January 08, 2012, 04:17:43 PM
That is very strange.  Since you mention it is just music, I assume this is only streaming sources that are having the problem?  I'll see if I can come up with a verbose test for you to run to figure out whats going on.  Could you also try a couple other formats/ codecs if you haven't already? (just to rule out a problem with CodecJOgg)

QuickPlay will lag when having to load the sample into memory for the first time.  If you call loadSound for the file (or url + identifier) in your initialization code, then subsequent calls to quickPlay should not have any delay before playing.

It is not possible to play a single source multiple times simultaneously with the way the library is currently designed.  A source is assigned to at most one channel at a time, so only one instance of it can play at a time.
Title: Re: 3D Sound System
Post by: Enerccio on January 08, 2012, 04:36:27 PM
I see. The lag with HERE and THERE happens randomly, and by that I mean randomly by runs, one time it will go, other time it will lag, with most time it will go ok.

Btw, is it possible to stop add sounds (not music) altogether in one command?
Title: Re: 3D Sound System
Post by: Paul on January 08, 2012, 04:40:50 PM
is it possible to stop add sounds (not music) altogether in one command?

Not yet.  That sounds useful though, so I'll add it.
Title: Re: 3D Sound System
Post by: Enerccio on January 12, 2012, 11:07:57 PM
any news on the debugging version?
Title: Re: 3D Sound System
Post by: Paul on January 13, 2012, 04:32:33 AM
I'll write it tomorrow.

In the mean time, could you let me know a couple more things (so I know where to put the most debug messages):

1) Does this only happen when playing music using CodecJOgg, or do CodecJOrbis and CodecWav do the same thing?
2) If the music is set to "looping", does it loop or only play once and get stuck?
3) If you queue more than on sample to the stream, do all the queued samples play, or only the first one?
4) If you call "stop()" on the stream before calling "play()", does it restart to the beginning, or does it stay stuck?
Title: Re: 3D Sound System
Post by: Paul on January 17, 2012, 05:03:19 AM
This has a lower priority at the moment until I get the next Mupen64Plus AE update out the door, so I'll wait for your answers to write the test build.
Title: Re: 3D Sound System
Post by: Enerccio on January 22, 2012, 01:29:40 AM
sorry for the late reply, but I was swamped with the exam period work.

The same happens with JOrbis and CodecWav doesn't play anything at all.

It means that the song will play once, but never repeats.

More than once seems to play at least with music and sound fx, it works correctly.

I don't have a stream, I was using the backgroundMusic feature, with loop set on.
Title: Re: 3D Sound System
Post by: Paul on January 22, 2012, 03:40:06 AM
Ok, I'll write a couple tests for you to answer the other questions.  backgroundMusic creates a streaming source, and it sounds like the problem is with looping.  I'll start with figuring out if it affects the stream queue first, and if it only affects the looping streams or also with stop/ play, so I know where to put the debug messages.

Not related to your  problem, but weird that CodecWav doesn't work for you, though, could you post a link to a WAV file that doesn't work?
Title: Re: 3D Sound System
Post by: Paul on January 22, 2012, 03:41:25 PM
Ok, please run the following test applet:

Test Applet (http://www.paulscode.com/source/JavaSoundBugTestApplet)

Perform the following procedures and let me know the results:

1) Press "1" to run the OGG Stream Loop.  Let me know if it loops or only plays once.
2) Press "2" to run the OGG Stream Sequence.  Let this one play for a while, and let me know if it makes it through the sequence (you will know it made it through the sequence if it eventually plays the music loop from #1 above.  Also let me know if the looping works or if the last music clip in the sequence only plays once.
3) Press "3" to run the WAV Stream Loop.  Let me know if it plays, and if so if it loops or only plays once.
4) Press "Esc" and close the browser window.

This should give me a better idea where to focus the comments to locate the two problems you are having

NOTE: I don't think you mentioned what OS you are running.  The above applet might not work on Linux (it won't detect the key events), so if that happens I'll have to come up with a different test.  You might need to click on the applet's canvas for it to gain focus.
Title: Re: 3D Sound System
Post by: Enerccio on January 30, 2012, 11:33:22 AM
Yes, I have arch linux 64 bit with openjdk. And it doesnt do anything.
Title: Re: 3D Sound System
Post by: Paul on January 30, 2012, 11:40:58 AM
Ok, sorry, I'll write a different one (applets need to have a canvas to pick up the key events.. really dumb bug that only affects Linux)
Title: Re: 3D Sound System
Post by: Enerccio on February 07, 2012, 10:27:20 AM
Okay, I will wait then.
Title: Re: 3D Sound System
Post by: Desmaster on March 02, 2012, 11:22:54 AM
Where can I find paulscode.sound.codecs.CodecJOrbis ?
Title: Re: 3D Sound System
Post by: Paul on March 02, 2012, 02:00:40 PM
Where can I find paulscode.sound.codecs.CodecJOrbis ?

First post of this thread (JOrbis codec plug-in)
Title: Re: 3D Sound System
Post by: Desmaster on March 02, 2012, 03:54:16 PM
That only reaches till paulscode.sound.codecs :o
Title: Re: 3D Sound System
Post by: Paul on March 02, 2012, 05:35:03 PM
CodecJOrbis.java contains the CodecJOrbis class.  Either drop the source files into your project, or link with the pre-compiled JAR and add the line "import paulscode.sound.codec.CodeJOrbis" to the top of your source file that needs it.
Title: Re: 3D Sound System
Post by: gouessej on June 11, 2012, 02:27:03 PM
Hi

At first, don't worry about the sound sample that can only be played once with OpenJDK, it comes from its poor support of JavaSound, it is not a bug of your library. That one was the main reason forcing me to switch to JOAL 1.1.3.

However, I have a small problem. I use an in-memory sound, I get its source name, I can play it only if it is not yet already played. This is problematic because it is a gun shot, the second bullet should start making some noise before the first one ends doing so. I don't want to create several sources for a single sound sample. How can I make it work? The only workaround I know consists in shortening sound samples to avoid overlaps but it is annoying and crappy, it won't be fine when an opponent shoots me while I shoot him. Thank you for your good library. Best regards.
Title: Re: 3D Sound System
Post by: Paul on June 11, 2012, 04:09:59 PM
This sounds like a bug that I thought I had fixed, but maybe not.. do future calls to play() do nothing?  As I recall a workaround was to call stop() on the source before calling play(), so you might try that.  If it doesn't work, please send me one of the audio files that is having the problem (and let me know which codec you are using).  If you want to email me, my address is just paul at paulscode dot com (I didn't post the actual link, to avoid the spam bots).

That being said, the quickPlay() method is typically better for sound effects like gunshots, explosions, etc anyway.  With quickPlay you do not have to keep track of source names since they are handled internally by the library.  On the other hand, for longer-duration sounds, quickPlay is not always the best option if it is supposed to be attached to something that moves quickly, so it really all depends on the application.
Title: Re: 3D Sound System
Post by: gouessej on June 12, 2012, 03:12:00 AM
Hi

The future calls to play does something if I use another sound sample than the current one or once the current sound sample has ended being played. You can reproduce this bug by running the demo of the pre-beta version of TUER available here, just take the pistol (9mn) and the ammunition in the green box, reload with the right click and shoot with the left click:
http://tuer.sourceforge.net/very_experimental/tuer.jnlp (http://tuer.sourceforge.net/very_experimental/tuer.jnlp)
If you keep pressing the left mouse button, you shoot correctly but you hear the sound sample only half of the time. You can get the sound sample here:
http://tuer.svn.sourceforge.net/viewvc/tuer/pre_beta/sounds/pistol9mn_shot.ogg (http://tuer.svn.sourceforge.net/viewvc/tuer/pre_beta/sounds/pistol9mn_shot.ogg)

I'm going to look at the source code of your library, I thought you simply prevented the same sourcename to be used several times at the same time.

Thank you for your help. I have to show my demo Tuesday, August, 7th, I hope it will just work fine.

Edit.: I should update the JARs of your library because I use those of 2010  :-X except for JOAL. I use JOrbis plugin, does the problem come from it?
Title: Re: 3D Sound System
Post by: gouessej on June 12, 2012, 03:40:26 AM
Ok maybe I'm not using correctly the library because several bullets at different locations at the same time should use different source names. Is there a way of loading the sound sample once in memory and using it in several sources?

In Library.play(Source), you check that this source is not in use, that's what I thought. It is not wrong, this is not a bug, I misuse your library or an option should be added to allow skipping this test:
Code: [Select]
if( !source.playing() )
Edit.: I'm silly. Several sources can use the same identifier if they use the same sound sample from the same URL. Can I use loadSound once per file and then quickPlay with the identifier to play the same sound several times at different locations without loading them each time? I want to avoid useless I/O operations at runtime.
Title: Re: 3D Sound System
Post by: Paul on June 12, 2012, 04:41:42 AM
Several sources can use the same identifier if they use the same sound sample from the same URL. Can I use loadSound once per file and then quickPlay with the identifier to play the same sound several times at different locations without loading them each time? I want to avoid useless I/O operations at runtime.

Right, the library uses the identifier to identify whether a particular sample has been loaded yet or not.  Once a sample has been loaded and given a particular identifier, then that is the sample used any time that identifier is referenced-- it is not reloaded every time.  So for instance, say you were to try to load a second URL or file, but accidentally used the same identifier, the first one that was already loaded would be used, not the second one (people have actually reported this as a bug, but it is the intended behavior to prevent unnecessary I/O operations).


--EDIT--
But to answer your particular question, in order to play more than one instance of a sample simultaneously, you must have more than one source.  Otherwise, you would just be stopping the currently playing one and restarting it in a different location.  For sound effects like what you are using, quickPlay() is almost always the best choice, as I designed it specifically for this type of scenario (i.e. a video game with lots of rapid sound effects like gunshots and explosions).  And it doesn't reload the sound effects every time it is called either (the same sample/ identifier rules I mentioned still apply).  That's not to say that doing your own source pool and management schemes might not be better for some cases-- just pointing out that it is there in case you don't need to reinvent the wheel.
Title: Re: 3D Sound System
Post by: gouessej on June 12, 2012, 10:10:03 AM
There is a spelling mistake in the documentation of quickPlay:
"The new sorce's name"
The "u" is missing.

People can still explicitly unload a sound if they want to load another one with the same identifier.

Thank you for your reply. When a bullet does not exist anymore in the game, its source should not go on existing, quickPlay is nice for this use case. Your explanation is fine, you're right about source pool and management and such things would be particularily useless in my case because I don't need to keep a given source after using it once, quickPlay doesn't keep it, this method just does what I need. Your source code is commented enough and quite clean, reading it really helped me to realize I was doing something wrong.
Title: Re: 3D Sound System
Post by: scoude on September 25, 2012, 04:32:35 AM
Hello Paul,

Just this message to indicate you that I joined a few days your environment SoundSystem in our software suite 'TbiSuite' and thank you for all the hard work!
In fact, I used another environment previously not working quite correctly and with your SoundSystem, it works perfectly!
For the moment, only TbiQuizzSonore software use your  environment. But with the next versions of other software, it will be extended!
TbiSuite is a suite of free and open software for school (children aged 2 ~ 8 years) using the interactive whiteboard we create me and my wife. I am a computer engineer and my wife is teacher with toddlers children!
If you're interested, here's the address of our suite:

http://caroline-et-serge.coude.net/tbisuite/

But it's only in french, sorry  ::)

Thank you again for your work!

Serge
Title: Re: 3D Sound System
Post by: musikele on October 10, 2012, 04:32:13 PM
Hello,
Sorry If I don't read all the thread but I have no time unfortunately :( so maybe my question has already been answered.
I'm searching for a java audio project that can be used in java and has this features:
- play multiple files at the same time (stereo or mono)
- use panning (for example, 75% on the right channel, 25% on the left)
- loop files or part of files (for example, if I have 10 clips loaded and playing altogether, and set start and stop loop points, it should loop only that part)
- most important of all ... do time shifting (slow down the music that is playing - even the group of files).
All this parameters might be changed at runtime.
Does your library do this?
It's ok for me to sponsor this project if it will support these features.
Please answer me by email because I don't know if tomorrow I'll find you again.

Cheers!
Title: Re: 3D Sound System
Post by: Paul on October 10, 2012, 05:04:41 PM
Please answer me by email because I don't know if tomorrow I'll find you again.

I'm not too hard to find (top hit for the Google search "java 3d sound", and fifth hit for "java sound system").  That said, I sent you an email just to be sure  ;)

Here's what I sent, for anyone else with a similar question:

Quote
I do not think my library will fit your needs, unfortunately.  It does not have direct methods for looping parts of an audio file, or for time shifting.  There are hooks into the underlying library plug-in, so in theory these could be used to do the required functions through OpenAL or JavaSound directly (or better yet modifying the existing code since it is open-source).  However, since it sounds like you need a quick solution, these are probably not the best options in your case.
Title: Re: 3D Sound System
Post by: bgroenks96 on December 08, 2012, 10:31:35 PM
I posted an issue under support about this.

The 3D sound mapping in LibraryJavaSound doesn't work on Linux Mint 13 OpenJDK 6.  I will try installing the standard JDK later and see if it works on that (then it would be a Linux Mint issue).
Title: Re: 3D Sound System
Post by: Paul on December 09, 2012, 08:15:22 AM
Thanks, I suspect it is a limitation with the available mixers.  Updating to Oracle probably won't solve it because they decided to remove their default software mixer from the library.  I started writing my own software mixer some time ago, but have been too busy to finish it.  If you come across an open source project like that someone else has done, let me know and I'll look into writing a Library plug-in for it.Otherwise things will probably still be on hold for a while.  Sorry!
Title: Re: 3D Sound System
Post by: bgroenks96 on January 30, 2013, 08:09:34 PM
Thanks, I suspect it is a limitation with the available mixers.  Updating to Oracle probably won't solve it because they decided to remove their default software mixer from the library.  I started writing my own software mixer some time ago, but have been too busy to finish it.  If you come across an open source project like that someone else has done, let me know and I'll look into writing a Library plug-in for it.Otherwise things will probably still be on hold for a while.  Sorry!

Using Oracle's Java distribution for Linux does actually fix the problem.  The sound mixer appears to function normally.

Interestingly, I've just now discovered that OpenJDK 7 works as well.  It appears this must have been a bug with OpenJDK 6.
Title: Re: 3D Sound System
Post by: bgroenks96 on January 31, 2013, 04:19:08 PM
Scratch that.  Eclipse wasn't actually running OpenJDK.  The JavaSound Mixer for OpenJDK 7 is broken too.  The SoundSystem only works on Sun VMs then.
Title: Re: 3D Sound System
Post by: Paul on January 31, 2013, 05:04:58 PM
Scratch that.  Eclipse wasn't actually running OpenJDK.  The JavaSound Mixer for OpenJDK 7 is broken too.  The SoundSystem only works on Sun VMs then.

Yes, that is because Sun/ Oracle used to (and may started again in version 7) including the "Java Sound Audio Engine" software mixer.  Without it, you are at the mercy of available hardware mixers (which tend to suck).  I'll get back to looking at this problem again soon.  Surely someone has written a good open-source software mixer.  I know there is an excellent one that is licensed by the GPL (not a good solution for many applications, but it could help a few folks).  I'd like to find one with a more liberal license.
Title: Re: 3D Sound System
Post by: techwiz24 on February 10, 2013, 07:14:45 PM
Is there any way to detect when a Streaming Source has finished playing? I'm trying to figure out if my sources have finished so I can clean up after them. When I mark them as temporary, I get null-pointer exception when calling millisecondsPlayed(source), but playing(source) still returns true...

EDIT: It might be an issue with LibraryJavaSound, upon inspecting a bit, javax.sound.sampled.SourceDataLine.isActive() always returns true on my system.
Title: Re: 3D Sound System
Post by: Paul on February 10, 2013, 07:24:27 PM
If you have a class that implements IStreamListener, you can call SoundSystemConfig.addStreamListener( this );  Then when any stream finishes playing, endOfStream( sourceName, queueSize ) will be called, notifying you that the stream has ended.
Title: Re: 3D Sound System
Post by: techwiz24 on February 11, 2013, 06:04:07 AM
Handy! That helps a ton, thanks!
Title: Re: 3D Sound System
Post by: cgomezr on February 17, 2013, 03:21:57 AM
I'd like to chime in for a couple of things.

First, to congratulate Paul for the great work done in this 3D Sound System. I checked it some days ago and it's really easy to use, powerful and well-documented. I think this was very needed in the Java world, I was using another audio library but it ceased to be maintained around 2006.

And second, to say that if at some point you implement that non-GPL Linux mixer at some point, I (and some other people I know) would be really, really grateful. I maintain a BSD-licensed system that people can use to create text adventures in a relatively easy way. But I have been getting bug reports for years about simultaneous sounds not working under Linux. Over the years, I have checked several audio libraries in search of the holy grail of simultaneous sounds with Java on Linux, but none solves this. In the light of your posts, I suppose this is because none of them implements a software mixer. Having a library that solved this without having to resort to native code or shipping specific versions of the software for each OS (which sets me back a lot) would be a real godsend. And judging by Google searches, not only for me and my users - there are lots of reports of "Java program X doesn't mix sounds under Linux distro Y".

As I said, thanks for the good work and keep it up!
Title: Re: 3D Sound System
Post by: gouessej on March 01, 2013, 08:45:49 AM
Hi Paul

The JOAL library plug-in requires an update as some constants and methods have been moved. Moreover, JOAL now supports OpenAL-Soft too.

You can find an example of which changes I had to do recently here  (http://code.google.com/p/jmonkeyengine/source/diff?spec=svn10452&r=10452&format=side&path=/trunk/engine/src/jogl/com/jme3/audio/joal/JoalAudioRenderer.java)and here (http://code.google.com/p/jmonkeyengine/source/diff?spec=svn10453&r=10453&format=side&path=/trunk/engine/src/jogl/com/jme3/audio/joal/JoalAudioRenderer.java).

Best regards

P.S: I can contribute if you want.
Title: Re: 3D Sound System
Post by: Paul on March 01, 2013, 08:59:46 AM
Thanks for the help!  I'll take care of this and post an update (shouldn't take too much since you did all the work!)  ;D
Title: Re: 3D Sound System
Post by: gouessej on March 07, 2013, 04:53:54 PM
Actually, your plugin already works as is with the latest version as you don't use OpenAL extensions.

However, can you decrease the delay used in this plugin in case of failure please? I have to wait for 30 seconds when OpenAL can't be loaded which often occurs under Windows :(
Title: Re: 3D Sound System
Post by: Paul on March 07, 2013, 05:00:54 PM
I'll take a look at it this weekend.  I can't remember where it is spending all the time.  As I recall, it attempts to create a context, and if it catches an exception then it reports to have failed.  Perhaps that is where all the time is being spent, not sure?
Title: Re: 3D Sound System
Post by: gouessej on March 08, 2013, 12:27:54 PM
I think you're right. I would only use a try catch in which I would call Alut.init() without adding a timeout, I don't know if it is feasible in your case.

Edit.: Look at SoundSystem.java line 1487.
Title: Re: 3D Sound System
Post by: msiggy on March 11, 2013, 05:50:14 PM
Hey Paul,

I have an .ogg file which is about 3k in size and 3 minutes in length. When I load this file with 'soundSystem.loadSound(filename)' It takes up a huge amount of memory ( 800mb) in my application. Whats weird is if I just play it with soundSystem.backgroundMusic() without loading it first, it takes up a normal amount of memory. This activity only seems to happen with certain .ogg files, some other ones I have work fine. It seems like there is something weird in the loadSound() method. Or perhaps my file has some funny attribute that isn't playing nice. Let me know if you want a copy of the .ogg file and I will send it to you. I cant put a link here because the sound is proprietary.

Thanks,
Mike
Title: Re: 3D Sound System
Post by: Paul on March 11, 2013, 06:13:46 PM
That is way too large to pre-load.  Use a streaming source for it instead of a normal source (that's what backgroundMusic does behind the scenes). That way the entire decoded audio doesn't have to be loaded in memory at once.
Title: Re: 3D Sound System
Post by: gouessej on March 15, 2013, 07:27:58 AM
Hi Paul

Sorry to disturb you once more. I have only found the line of code that displays the message: SoundSystem.java line 1487

I haven't found a way of decreasing or removing the annoying delay (30 seconds). Please can you help me? OpenAL works reliably on lots of Windows machines, I don't want to use Java Sound under Windows in all cases just because of this delay.
Title: Re: 3D Sound System
Post by: Paul on March 15, 2013, 07:59:43 AM
Sorry for the delay.. things have been really hectic between work and my main project.  I promise I'll look at the SoundSystem this weekend.
Title: Re: 3D Sound System
Post by: gouessej on March 15, 2013, 08:52:13 AM
Don't be sorry, you already do your best. I'm going to investigate a bit more in order to give you some complementary indications so that you will spend less time in fixing that.
Title: Re: 3D Sound System
Post by: Paul on March 17, 2013, 01:53:44 PM
It seems to take close to 30 seconds to initialize.  If it takes longer than that, the SoundSystem reports failure and tries the next library plug-in if one was specified.

Initialization consists of only two lines:

Code: [Select]
ALut.alutInit();
al = ALFactory.getAL();

Since these lines are a necessary first step to use OpenAL, I don't see any way of reducing the amount of time it takes to initialize when OpenAL is compatible on the user's system.  I'm not sure how your specific application is set up, but you might be able to extend (or alter) SoundSystem and override/ modify the newLibrary method so that instead of blocking the process until initialization succeeds or fails, instead do that check on a separate thread and handle it with a callback (failure, switch to the next library, success print out a message or whatever).  The basic idea would look something like this (UNTESTED!):
Code: [Select]
    // (new member if extending SoundSystem, otherwise just add to SoundSystem)
    public static interface OnInitCompleteListener()
    {
        public void onInitComplete( boolean success );
    }


...


    // (override if extending SoundSystem, otherwise just modify)
    @Override
    public boolean newLibrary( Class libraryClass )
                                                     throws SoundSystemException
    {

        final Class fLibraryClass = libraryClass;
        final OnInitComplete fListener = new OnInitCompleteListener()
        {
            public void onInitComplete( boolean success )
            {
                if( success )
                {
                    // Set a varriable, etc to indicate initialization was successful for 'fLibraryClass'
                }
                else if( fLibraryClass == paulscode.sound.libraries.LibraryJOAL.class )
                {
                    newLibrary( paulscode.sound.libraries.LibraryJavaSound.class );
                }
                else if( fLibraryClass == paulscode.sound.libraries.LibraryJavaSound.class )
                {
                    newLibrary( Library.class );  // (no sound)
                }
                else
                {
                    // Complete and utter failure on all levels
                }
            }
        };

        new Thread()
        {
            @Override
            public void run()
            {
                initialized( SET, false );
                CommandQueue( new CommandObject( CommandObject.NEW_LIBRARY,
                                                 fLibraryClass ) );
                commandThread.interrupt();
                for( int x = 0; (!initialized( GET, XXX )) && (x < 100); x++ )
                {
                    snooze( 400 );
                    commandThread.interrupt();
                }
                fListener.onInitComplete( initialized( GET, XXX ) );
            }
        }.start();
        return true;
    }

In cases where OpenAL is not compatible there might be some other sanity checks that could be made prior to attempting to initialize OpenAL.  Where are you noticing the problem mainly - when OpenAL is compatible or when it is not compatible?
Title: Re: 3D Sound System
Post by: gouessej on March 18, 2013, 07:49:57 AM
I notice the problem when the loading of OpenAL fails on a laptop under Windows 7 64 bits. When the loading doesn't fail, it doesn't take 30 seconds whatever the operating system (tested under Mac OS X 10.6.8, Mageia Linux 2 and Windows 7). I will have to debug your source code to verify what you say. Maybe an exception is not catched and then SoundSystem really has to wait for 30 seconds.

Edit.: The stack trace is here:
https://jogamp.org/bugzilla/show_bug.cgi?id=699#c0 (https://jogamp.org/bugzilla/show_bug.cgi?id=699#c0)
Title: Re: 3D Sound System
Post by: Paul on March 18, 2013, 08:02:16 AM
Oh, that's good then.  Maybe there is another check that could be made prior to attempting to load the JOAL library.  I'd be interested to know if an exception is ever getting caught too (I don't have any way of testing that from my computer though).  You are probably correct - if it doesn't catch an exception, then it certainly wouldn't know there was a problem, and would just wait the 30 seconds until it times out.
Title: Re: 3D Sound System
Post by: gouessej on March 18, 2013, 08:24:21 AM
You could catch all Throwable instances or ExceptionInInitializerError instances in line 159 in LibraryJOAL. We can't always wrap exceptions into ALException instances.

Edit.: I will fix it in JOAL:
https://jogamp.org/bugzilla/show_bug.cgi?id=708 (https://jogamp.org/bugzilla/show_bug.cgi?id=708)
Title: Re: 3D Sound System
Post by: Paul on March 18, 2013, 11:23:00 AM
Good point.  I'll change it to catch any throwable.
Title: Re: 3D Sound System
Post by: gouessej on March 19, 2013, 04:49:56 AM
I fixed the bug in JOAL yesterday, I just wait for the integration of my fix as soon as possible.
Title: Re: 3D Sound System
Post by: Paul on April 17, 2013, 08:48:03 PM
Sound System, Raw Data Stream Bugfixes


LibraryLWJGLOpenAL (http://www.paulscode.com/source/SoundSystem/17APR2013/LibraryLWJGLOpenAL.zip)
LibraryJOAL (http://www.paulscode.com/source/SoundSystem/17APR2013/LibraryJOAL.zip)


- Fixed raw data stream repeating bug in LibraryLWJGLOpenAL and LibraryJOAL
- Fixed raw data stream millisecond position bug in LibraryLWJGLOpenAL and LibraryJOAL
Title: Re: 3D Sound System
Post by: techwiz24 on April 21, 2013, 08:05:09 PM
Trying to use this library again for a project, and I'm running into some errors that I'm not sure if I had the last time (a few months ago). I can't play any sources. More specifically:

Code: [Select]
Error in class 'CodecJOgg'
    url null in method 'initialize'
Error in class 'ChannelJava Sound'
    AudioFormat null in method 'resetStream'
Error in class 'ChannelJava Sound'
    SourceDataLine null in method 'preLoadBuffers'.
Error in class 'ChannelJava Sound'
    SourceDataLine null in method 'processBuffer'.

Here is my main method:
Code: [Select]
public static void main(String[] args) throws SoundSystemException {
Test t = new Test();
t.ss = new SoundSystem(LibraryJavaSound.class);
SoundSystemConfig.setCodec("wav", CodecWav.class);
SoundSystemConfig.setCodec("ogg", CodecJOgg.class);
SoundSystemConfig.addStreamListener(t);

//t.ss.newStreamingSource(false, "a", "C:/test.wav", false, 0,0,0, 0, 0);
t.ss.newStreamingSource(false, "a", "C:/test.ogg", false, 0,0,0, SoundSystemConfig.ATTENUATION_NONE, 0);

t.ss.play("a");
//t.ss.play("b");

while(t.ss.playing("a") || t.ss.playing("b")){
try{Thread.sleep(10);}catch(Exception ignore){}
}

t.ss.cleanup();
}

My choice for using this library is because it appears to support extra codecs with little work, but I only need the sounds to play in 2D. Is this overkill? Should I search for something else? Note that I get the above error also with the CodecWav.
Title: Re: 3D Sound System
Post by: Paul on April 21, 2013, 09:54:44 PM
The problem is that the library assumes the sound files are compiled into the JAR in a package named Sounds.  To use external sound files, use the alternate methods that take URL+identifier parameters instead.
Title: Re: 3D Sound System
Post by: techwiz24 on April 22, 2013, 07:52:43 PM
Alright, that works (for some formats, probably my converter messing up). With the application I am developing, it is critical that the program knows when a sound finishes playing. Maybe I have implemented my listener wrong, but here is the class that I'm using:

Code: [Select]
import java.io.File;
import java.net.MalformedURLException;

import paulscode.sound.IStreamListener;
import paulscode.sound.SoundSystem;
import paulscode.sound.SoundSystemConfig;
import paulscode.sound.SoundSystemException;
import paulscode.sound.codecs.CodecWav;
import paulscode.sound.libraries.LibraryJavaSound;

public class Test implements IStreamListener {

private SoundSystem ss;

/**
* It's messy, I know. Just for testing.
* @param args
* @throws SoundSystemException
* @throws MalformedURLException
*/
public static void main(String[] args) throws SoundSystemException, MalformedURLException {
Test t = new Test();
t.ss = new SoundSystem(LibraryJavaSound.class);
SoundSystemConfig.setCodec("wav", CodecWav.class);
SoundSystemConfig.addStreamListener(t);
t.ss.newStreamingSource(false, "a", new File("C:\\test.wav").toURI().toURL(), "C:\\test.wav", false, 0, 0, 0, SoundSystemConfig.ATTENUATION_NONE, 1);

t.ss.play("a");

try{Thread.sleep(10000);}catch(Exception ignore){};



t.ss.cleanup();
}

@Override
public void endOfStream(String arg0, int arg1) {
System.out.println(arg0 + " has finished.");
}

}

The endOfStream method is never getting called. The effect is only about 2 seconds long...
Title: Re: 3D Sound System
Post by: Paul on April 22, 2013, 09:25:10 PM
Is the problem only happening for specific files, or all of them?  I'll run some tests when I have time (if you could upload one of the problem files somewhere, I'll use it specifically in the tests).
Title: Re: 3D Sound System
Post by: techwiz24 on April 23, 2013, 06:02:36 AM
It seems to happen with every file I've tried...
Title: Re: 3D Sound System
Post by: Paul on April 23, 2013, 07:49:20 AM
Ok, great.  Hopefully it will be easy to reproduce then.  I should have some time this evening to look at this.
Title: Re: 3D Sound System
Post by: techwiz24 on April 23, 2013, 09:19:01 AM
Cool, thanks for your help!
Title: Re: 3D Sound System
Post by: techwiz24 on May 01, 2013, 10:21:17 AM
Do you have the project in source control somewhere? I want to make sure I have the latest source to try and figure out why my listeners aren't being notified. The archive on the first page is from January, so I'm not sure it that is up to date or not.
Title: Re: 3D Sound System
Post by: techwiz24 on June 04, 2013, 08:38:15 PM
Bump
Title: Re: 3D Sound System
Post by: Paul on June 05, 2013, 01:54:39 PM
Thanks for the bump.. forgot to look into that stream listener problem.

Do you have the project in source control somewhere? I want to make sure I have the latest source to try and figure out why my listeners aren't being notified. The archive on the first page is from January, so I'm not sure it that is up to date or not.

Not currently in any source control.  I might do that at some point.  The links on the first page should be current (the project hasn't had any major updates for a while).
Title: Re: 3D Sound System
Post by: Smith61 on June 24, 2013, 02:48:32 AM
There exists a bug within the JavaSound library plugin. When using Raw Streams with the plugin it fails to check how much of the data is actually written into the SourceDataLine. This causes data to be dropped when the queued buffer is bigger than the internal buffer of SourceDataLine. The problem is around line 714 of ChannelJavaSound. This can usually be fixed by passing in small amounts of data at a time but there is no way to find out the size of the buffer used in SourceDataLine as it is undefined according to the JavaDoc.
Title: Re: 3D Sound System
Post by: Paul on June 24, 2013, 07:59:02 AM
I wonder if it would be feasible to use the value returned by sourcedataline.getBufferSize() as the maximum, and either internally chop down buffers that are too large, or produce an error or something.
Title: Re: 3D Sound System
Post by: Smith61 on June 24, 2013, 11:17:34 AM
You could do that or the write method returns the amount of bytes actually written. You could keep track between writes how much is left of the audio has not been written to the line and keep writing from the buffer until it is fully written. Using SourceDataLine.getBufferSize() would return the size of the buffer but that could still cause problems as there might be data remaining in the line when you go to write.

Also another bug I found was that you do not copy from the buffer's passed in into an internal buffer. Making it so we have to create a new buffer when we are say reading from a stream. If we use the same buffer there is a chance that we overwrite the previous data before the SoundSystem has a chance to write it to the SourceDataLine. I'm not sure if this was intended or not but the Docs do not mention it and it can cause some annoying bugs when it happens

Edit: And a feature request if the last one was a bug would be a feedRawData method that accepts start and length parameters similar to how IO streams work

Edit 2: After some further thinking your idea of splitting up the buffer while it is passed in should solve atleast the second issue. You would still need to take into account how much is actually written to the line. You never can be to safe with that. Then to reduce the amount of buffers that need to be created when a large buffer is passed in you could use an internal buffer cache that caches byte arrays the same size as the SourceDataLine's internal buffer. That way when large amounts of audio are passed in at once it is quick to grab already existing buffers and copy into them then recycle them after they have been fully written to the SourceDataLine
Title: Re: 3D Sound System
Post by: Smith61 on June 24, 2013, 05:27:39 PM
Another bug in a different library. This one is in the LibraryLWJGLOpenAL library. I'm not sure if it's the library or OpenAL acting up, but with raw streams you need to pass in atleast two buffers to get any sound to play. Passing in just one does not play anything and ends with an OpenAL error when stopping the SoundSystem.

Error in class 'ChannelLWJGL OpenAL'
    Invalid enumerated parameter value.


Since it is an OpenAL error I am leaning towards that it is an OpenAL problem and not a problem with the library, but figured I would point it out.


A second one is not so much a bug but AudioFormats with signed as true should not be allowed when using the OpenAL library. It should throw an error when trying to create a raw stream or convert the buffers before sending them to OpenAL. Another possible bug would be endianess. From what I've read of OpenAL it uses the native order of the system which may not be the format the audio is in. Not sure if you would want to error there or convert the buffers when they are passed in
Title: Re: 3D Sound System
Post by: Smith61 on July 17, 2013, 04:10:45 AM
Going round three with more bugs in the SoundSystem library. This is in the LibraryLWJGLOpenAL library. Maybe in other libraries to but only tested and confirmed on this one. This has to do with raw streams with no attenuation. It may work on other streaming sources but again only tested and confirmed on raw streams. When moving a source around there is no change in volume which is expected but when the listener is moved around the volume and position change as if there was attenuation on the source.

Here (http://pastebin.com/BmZtd6tE) is a link to working code that shows this problem. The only thing that needs to be changed is the location of the sound file or you may provide your own audio data that is in the given format. This first creates a large amount of buffered audio in the system depending on the size of the audio passed in. It will then wait 10 seconds before moving to the next step. It will first move the listener, then the source to the listeners position, then the listener back to the origin.



A fix for one of the previous bugs that I currently have working can be found here (https://github.com/smith61/VoiceOverMinecraft/blob/master/Parent/Client/src/main/java/me/smith_61/client/audio/java/JavaAudioFrame.java). This is my fix for the first bug I mentioned.
Title: Re: 3D Sound System
Post by: Paul on July 17, 2013, 09:09:31 AM
I'm guessing you are using stereo data for your stream.  OpenAL requires you to use mono data for 3D affects such as attenuation.

--EDIT-- NM, I missed that you said it works when moving the listener, just not the source.  I'll look into it.

--EDIT2--  I noticed this line.  I assume you have tried with other values besides ATTENUATION_NONE, and provided a rolloff factor or fade distance, right?
Code: [Select]
system.rawDataStream(format, false, sourceName, 0, 0, 0, SoundSystemConfig.ATTENUATION_NONE, 1f);
Title: Re: 3D Sound System
Post by: Smith61 on July 17, 2013, 11:55:41 AM
I am trying not to have any attenuation and the data is in mono format. You can check the format up near the top of the code in the paste. That is the same format that I used when recording the audio I was playing. The project I am using this for is a voice chat mod for the game Minecraft. Currently I do not want them to be 3D sounds but instead be a sort of Global chat room.

The 1f shouldn't/doesn't need to be there. It was leftover from trying to find a fix. I have not tried with any other value besides ATTENUATION_NONE since the only other two options are not what I was looking for. I also believe that using any normal streams are also affected by this bug. I'll edit back once I confirm it though.

Edit: Normal streams seem to work as expected. I can move both the source and the listener and the audio is not diminished in volume. Raw streams are the only ones that does not allow the source to be moved or placed in a certain location. Raw streams only want to be placed at (0, 0, 0) and will not move from there. Even creating a new source at (5, 5, 5) acts the exact same as the one placed at (0, 0, 0).

Edit 2: None of the attenuation types allow raw stream sources to be moved from the origin. I have tried to look through the source to find a problem but I can not find one.
Title: Re: 3D Sound System
Post by: Steveice10 on July 17, 2013, 02:18:54 PM
UPDATE: Turns out my problem has to do with my copy of LWJGL.

A suggestion: Better error reporting? For example, if a bit of reflection throws an InvocationTargetException, it doesn't let you know where it came from or what its wrapped exception is.
Title: Re: 3D Sound System
Post by: Paul on July 17, 2013, 07:30:40 PM
Oh, I thought you wanted attenuation.  In that case I'd use a rolloff factor of zero (sounds like you solved the issue though).  Also for ambient sources, I recommend using stereo.  WRT better error handling, that is something I've been planning just haven't had the time.
Title: Re: 3D Sound System
Post by: Smith61 on July 17, 2013, 08:35:51 PM
I didn't get it working on raw streams. The normal streams from files work as intended but it does not work when I provide that audio data myself. I have tried the ATTENUATION_ROLLOFF with a rolloff of zero but it acts the same as using ATTENUATION_NONE. Try running the code I sent you and you can hear the difference with raw streams. A couple of changes and you can use regular streaming sources from the same file and it will work normally. The problem is that raw sources can not be moved from the origin while all other sources can be.

I want to use raw streams as I will be creating the audio at runtime and the act of writing it out to play it correctly or creating a custom codec to read from a stream I am providing just to get around the issue doesn't seem like a good way when I should be able to just use raw streams.
Title: Re: 3D Sound System
Post by: Paul on July 17, 2013, 09:22:33 PM
I don't understand the difference between a raw stream and a normal one.  They are the same on the OpenAL side.  Only difference is you are providing the data instead of SoundSystem providing it.  Pretty stumped on this one.
Title: Re: 3D Sound System
Post by: Smith61 on July 17, 2013, 10:00:45 PM
That is exactly why I am confused by it to. They should act the same way but they don't.
Title: Re: 3D Sound System
Post by: Paul on July 17, 2013, 10:10:08 PM
I see the problem.  From line 688 in Library.java:

Code: [Select]
        // raw data streams will automatically play when data is sent to them,
        // so no need to do anything here.
        if( source.rawDataStream )
            return;

Then playing the raw stream happens from ChannelLWJGLOpenAL.java line 458:
Code: [Select]
            // restart the channel if it was previously playing:
            if( !playing() )
            {
                AL10.alSourcePlay( ALSource.get( 0 ) );
                checkALError();
            }

Which is missing a key block of logic that is in the normal play function, SourceLWJGLOpenAl.java from line 550:
Code: [Select]
        // Make sure the channel exists:
        // check if we are already on this channel:
        if( newChannel )
        {
            setPosition( position.x, position.y, position.z );
            checkPitch();
           
            // Send the source's attributes to the channel:
            if( channelOpenAL != null && channelOpenAL.ALSource != null )
            {
                if( LibraryLWJGLOpenAL.alPitchSupported() )
                {
                    AL10.alSourcef( channelOpenAL.ALSource.get( 0 ),
                                  AL10.AL_PITCH, pitch );
                    checkALError();
                }
                AL10.alSource( channelOpenAL.ALSource.get( 0 ),
                               AL10.AL_POSITION, sourcePosition );
                checkALError();

                AL10.alSource( channelOpenAL.ALSource.get( 0 ),
                               AL10.AL_VELOCITY, sourceVelocity );
               
                checkALError();

                if( attModel == SoundSystemConfig.ATTENUATION_ROLLOFF )
                    AL10.alSourcef( channelOpenAL.ALSource.get( 0 ),
                                    AL10.AL_ROLLOFF_FACTOR, distOrRoll );
                else
                    AL10.alSourcef( channelOpenAL.ALSource.get( 0 ),
                                    AL10.AL_ROLLOFF_FACTOR, 0.0f );
                checkALError();

                if( toLoop && (!toStream) )
                    AL10.alSourcei( channelOpenAL.ALSource.get( 0 ),
                                    AL10.AL_LOOPING, AL10.AL_TRUE );
                else
                    AL10.alSourcei( channelOpenAL.ALSource.get( 0 ),
                                    AL10.AL_LOOPING, AL10.AL_FALSE );
                checkALError();
            }
            if( !toStream )
            {
                // This is not a streaming source, so make sure there is
                // a sound buffer loaded to play:
                if( myBuffer == null )
                {
                    errorMessage( "No sound buffer to play" );
                    return;
                }
               
                channelOpenAL.attachBuffer( myBuffer );
            }
        }

In other words, raw data streams are simply ignoring whatever you have set for attenuation.  As a workaround, you should be able to call setAttenuation on the source after you create it.  This propagates down to setAttenuation on line 438 of SourceLWJGLOpenAL.java, which will do the necessary calls to alSourcef for rolloff factor.  If you are utilizing pitch or velocity, same thing.

--EDIT-- call to setAttenuation will probably need to be after feeding your first block of data, since it won't be attached to a channel before then.  May not even work then, since there is a race condition here between the command thread and the stream thread.  This is definitely a bug I will need to fix.
Title: Re: 3D Sound System
Post by: Smith61 on July 17, 2013, 10:20:16 PM
Okay so I tried placing the setAttenuation after creating, after the first block is passed in, after waiting to verify that the source is playing, and after moving the listener to the new position and neither worked. It played exactly like it had before. There is still also the problem with not being able to move raw stream sources from the origin.
Title: Re: 3D Sound System
Post by: Paul on July 17, 2013, 10:31:14 PM
That is not a separate problem -- exactly the same cause (feeding the data merely plays the source, it doesn't update the AL information on the channel to reflect the values for the source).  Like I said, there is a race condition here, so I'll have to come up with a permanent fix rather than the workaround.
Title: Re: 3D Sound System
Post by: ashrzr on January 02, 2014, 02:26:12 PM
Hey Paul. I use the SoundSystem to load all sounds for my game ahead of time with the player. Then, when I want to play a sound, I call quick play on the string that the player identifies. The sound plays no problem, but when I profile the game I notice that the SoundSystem creates almost 50 live threads (I have isolated it as the problem) when I play a sound. Why on earth is that?
Title: Re: 3D Sound System
Post by: Paul on January 02, 2014, 02:51:17 PM
SoundSystem should have only two threads at most (one if you don't do streaming), in addition to the threads you are calling functions from (outside of the SoundSystem).  Could you post a simple test-case that demonstrates this problem?
Title: Re: 3D Sound System
Post by: ashrzr on January 03, 2014, 08:08:14 PM
This test creates a new thread for every sound (and doesn't ever dispose each thread):

Code: [Select]
class GameSound
{

  static SoundSystem PLAYER;
 
  static void setup()
  {
    try {
      SoundSystemConfig.addLibrary(LibraryJavaSound.class);
      SoundSystemConfig.setCodec("wav", CodecWav.class);
    } catch (SoundSystemException E) {
      E.printStackTrace();
    }
   
    PLAYER = new SoundSystem();
    PLAYER.loadSound(GameSound.class.getResource("select_mechwhat1.wav"), "select_mechwhat1.wav");
  }


  public static void main(String[] args)
  {
    setup();

    for (int i = 1; i <= 20; i++) {
      PLAYER.quickPlay(false, "select_mechwhat1.wav", false, 0, 0, 0, SoundSystemConfig.ATTENUATION_NONE, SoundSystemConfig.getDefaultRolloff());
      try {
        Thread.sleep(1000);
      } catch (Exception E) {}
    }
  }
 
}

(http://i249.photobucket.com/albums/gg207/askher2/ScreenShot2014-01-03at90002PM_zps81c3ef7f.png)

I'm must be doing it wrong. Thanks.
Title: Re: 3D Sound System
Post by: Paul on January 03, 2014, 10:13:39 PM
You can look at the source code to confirm this, but if more than two threads are created, they are not being created from within the SoundSystem library itself.  Perhaps this is another issue with JavaSound.. have you compared to what you get if you use one of the OpenAL library plugins?

EDIT: After a little Googling, it looks like in fact this is a behaviour of JavaSound (each clip is given its own thread).  See here (http://stackoverflow.com/questions/11456622/java-javasound-is-clip-play-an-expensive-call) and here (http://stackoverflow.com/a/6871770/1002212) for example.  SoundSystem allows at most 32 simultaneous clips (which are the backend of each "normal channel" in the JavaSound library plugin), so you should not see more than that unless there is a bug.  Probably not much I can do to reduce this thread creation from the library, since this is how JavaSound is written to behave.  You could reduce the number of channels using SoundSystemConfig.setNumberNormalChannels() if 32 is too many for whatever reason.
Title: Re: 3D Sound System
Post by: ashrzr on January 04, 2014, 12:14:35 PM
That's it! Thanks!
Title: Re: 3D Sound System
Post by: wessles on January 25, 2014, 08:46:16 PM
Great engine paul!

One issue I have, however, is how to load sounds via InputStreams. I am trying to load a sound from within the jar using Class.getClassLoader().getResourceAsStream(). I can only find a URL to feed into newSource(). Is there another way to create sounds than newSource() that accepts InputStreams?
Title: Re: 3D Sound System
Post by: Paul on January 26, 2014, 09:13:44 AM
Why not use getResource() instead of getResourceAsStream()?  The former should return a URL instance.

Note that SoundSytem was original designed to load files from inside the JAR (the URL thing was added as a feature request later on).  Every command that takes identifier + URL parameters has a version which simply takes a filename.  By default, SoundSystem looks for the file in a package named "Sounds", but you can change it via SoundSystemConfig.setSoundFilesPackage().  If the files are under subfolders under a common root folder, call setSoundFilesPackage for the root folder, and then append the subfolder to the front of the filename when calling a method like loadSound.  If there is no common root folder for the sounds, you should be able to pass an empty string to setSoundFilesPackage (haven't actually tried this latter option, but it should work)
Title: Re: 3D Sound System
Post by: jpvguerreiro on January 31, 2014, 08:24:44 AM
Hi Paul. I have been trying the 3D Sound System and it's really great. I have a question regarding the libraries used. The sound quality difference between Javasound and ljwgl is evident, however does ljwgl use HRTF to enhance the 3D audio?
I have read that LJWGL uses OpenAL soft, which has some HTRF support, but I'm not sure that it is using it and if I can do something to enable it. Do you have some information about that?

Thanks in advance!
Title: Re: 3D Sound System
Post by: Paul on January 31, 2014, 09:45:09 AM
I've never tried modifying LWJGL myself, but a quick google search brought up a lot of information that should be helpful.  For example, I saw this (http://www.minecraftforum.net/topic/1513100-openal-update/#entry18455709) on the Mincraft forums (Minecraft uses the SoundSystem library, so the info should be relevant).
Title: Re: 3D Sound System
Post by: Steveice10 on May 01, 2014, 08:46:32 PM
If I may ask, what ever happened to the planned Android support for this? (http://www.jpct.net/forum2/index.php/topic,1057.msg16288.html?PHPSESSID=25bd63095174df2a15ae8956db80fecf#msg16288)

It would be a useful thing to have for cross-platform mobile/PC games.
Title: Re: 3D Sound System
Post by: Paul on September 04, 2014, 03:15:13 PM
Change in priorities.. SoundSystem took a back burner when things started taking off with Mupen64Plus AE.  I may eventually get back around to this one.
Title: Re: 3D Sound System
Post by: Brian_Entei on October 20, 2014, 01:32:55 PM
Hey Paul, love the sound system! I have been developing a game and I am using your sound system. It has been working great so far, but I can't seem to find a library for *.m4a files. So far I have *.mp3 *.ogg and *.wav files working. Is there a library out there that I can use to play the *.m4a files? And if not, how might I make a library for a specific file type? Thanks for the awesome sound system, keep it up! :)
Title: Re: 3D Sound System
Post by: Javis on January 04, 2015, 06:26:36 AM
HI
Iv got a problem with the queuesound function.
I simply dont know how to use it  ;D
Can anybody help me ?
Title: Re: 3D Sound System
Post by: Paul on January 04, 2015, 10:08:57 AM
HI
Iv got a problem with the queuesound function.
I simply dont know how to use it  ;D
Can anybody help me ?

queueSound is called on a streaming source or the MIDI source.  It queues up the next sound to play when the previous playback ends.  There are two versions of the method, with parameters that are similar to the first couple parameters of newStreamingSource (so if you know how to create a streaming source, you should have no problem using queueSound). As stated in the JavaDoc, this method has no effect on non-streaming sources.
Title: Re: 3D Sound System
Post by: SOGKiller10 on January 04, 2015, 07:48:13 PM
Hi,
I've got a problem on how to add the 3D Sound System into my project. The problem is that I don't know where to put it so it is going to work. I am using Eclipse Luna. I already tried to put it into my project and then import it with the following:
Code: [Select]
import paulscode.sound.SoundSystem;
import paulscode.sound.SoundSystemConfig;
import paulscode.sound.SoundSystemException;
import paulscode.sound.libraries.LibraryJavaSound;
import paulscode.sound.codecs.CodecJOrbis;
Can you help me with this?
Thanks,

SOGKiller10
Title: Re: 3D Sound System
Post by: Paul on January 05, 2015, 01:21:01 AM
Put the source files into a package with the specified name/path as in the import statements.  paulscode/sound, paulscode/sound/libraries, and paulscode/sound/codecs are the three you have listed below.  Or if you are using the compiled JARs, include them like any other JAR you would add to a Java project.
Title: Re: 3D Sound System
Post by: SOGKiller10 on January 05, 2015, 09:54:40 AM
Ok, thanks, but I have still got one problem. The last import doesn't work. (import paulscode.sound.codecs.CodecJOrbis;) What is wrong with that? (And yes, I have that codec JAR)

Thanks,

SOGKiller10
Title: Re: 3D Sound System
Post by: Paul on January 05, 2015, 11:02:44 AM
Not sure.  That is the correct path.  The other four imports work?
Title: Re: 3D Sound System
Post by: jakethesnake on April 25, 2015, 07:52:12 AM
Hello! nice library you've got going here!

I was wondering if you're planning on making the OpenAL plugin compatable with lwjgl 3.0?

As far as I know, the lwjgl-team hasn't changed the openAl interface very much, and I think there's only a few lines of code that needs changing. It would be great if you did!
Title: Re: 3D Sound System
Post by: gouessej on September 08, 2015, 03:37:09 PM
Hi

Maybe you should update the few lines about the JOAL plugin because it uses both OpenAL and OpenAL-Soft under the hood which drives it more compatible.

I'd like to build your library with the profile "compact1" but there is only one class preventing me from doing it: javax.sound.sampled.AudioFormat. As this class is just a bean (there is no intelligence in it, it contains only some fields and some accessors), maybe it would be acceptable to replace it by a more simple class or by the implementation of this class in Apache Harmony so that I can use your library even under Android.

Finally, I see that you're on Github. Why not putting the source code of your sound system into it? It would help me to contribute.

Keep up the good work as usual :)
Title: Re: 3D Sound System
Post by: r2range on January 25, 2016, 03:56:01 PM
Ey Paul,

Nice Sound system a friend of mine implemented it into a game and it worked prefect until i upgraded to windows 10

it seems that  windows 10 doesnt have the "Microsoft GS Wavetable synth"

Code: [Select]
javax.sound.midi.MidiUnavailableException: Undefined external error.
at com.sun.media.sound.MidiOutDevice.nOpen(Native Method)
at com.sun.media.sound.MidiOutDevice.implOpen(MidiOutDevice.java:54)
at com.sun.media.sound.AbstractMidiDevice.doOpen(AbstractMidiDevice.java:154)
at com.sun.media.sound.AbstractMidiDevice.openInternal(AbstractMidiDevice.java:144)
at com.sun.media.sound.AbstractMidiDevice.getReceiverReferenceCounting(AbstractMidiDevice.java:350)
at javax.sound.midi.MidiSystem.getReceiver(MidiSystem.java:273)
at MidiPlayer.<init>(MidiPlayer.java:9)
at Client.<init>(Client.java:16382)
at Client.main(Client.java:5499)

Code: [Select]
Starting up SoundSystem...
Exception in thread "Thread-7" java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at paulscode.sound.SoundSystemConfig.runMethod(SoundSystemConfig.java:900)
at paulscode.sound.SoundSystemConfig.getLibraryTitle(SoundSystemConfig.java:321)
at paulscode.sound.SoundSystem.CommandNewLibrary(SoundSystem.java:1524)
at paulscode.sound.SoundSystem.CommandQueue(SoundSystem.java:2572)
at paulscode.sound.CommandThread.run(CommandThread.java:121)
Caused by: java.lang.ClassNotFoundException: org.lwjgl.LWJGLException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 10 more
Title: Re: 3D Sound System
Post by: Paul on February 01, 2016, 06:15:23 PM
The solution to this will likely be the same solution as the problem with only having one line on Linux, which is to write my own software mixer.  Been meaning to do that, but haven't had much time for programming in a while.
Title: Re: 3D Sound System
Post by: r2range on February 02, 2016, 02:51:21 PM
well if you could find the time to update the libs it would be awesome other wise i need to ask my friend to redo the entire sound system  :-\
Title: Re: 3D Sound System
Post by: nicymike (Michael) on June 01, 2016, 05:22:56 AM
Hi Paul,

First, thank you for your work on the 3D Sound System. It must be quite popular since Minecraft is using it.

I started a remake of Settlers 1 and I am using your library. Because the music is in MIDI format I am using the MIDI system and found a bug:

In class MidiChannel in method meta(MetaMessage message) line 1030:
sequenceQueue is null if you are not using it before and that means a NullPointerException is stopping the loop from working.

If you are interested in the game check out:
https://www.simpleguide.net/sg/serflings.jsf

EDIT:
Two more things to optimize MIDI playback:

1. In MidiChannel always add parameter false when fetching the Sequencer (MidiSystem.getSequencer(false)). False means to not connect to a Synthesizer, which is done later anyway. If not given this parameter the output is terrible, at least in java 8. I guess this is because there is more than one Synthesizer connected.

2. I found out that on my system the volume control is not on controller 7 but on controller 11. I don't know if this is always the case but it worked for me. Now I set the volume on both controllers (method resetGain).

Best regards,
Michael
Title: Re: 3D Sound System
Post by: NullNoname on September 03, 2016, 10:38:27 AM
Hello. Thanks for your great library. I've created a preliminary Android port using Android's AudioTrack class. This is still very early state but it can play some music.
The main library has some API changes required for Android, like adding the clone of JavaSound's AudioFormat class and adding the ability to override how InputStreams are obtained from URLs (useful for Android asset).

Main Library: https://github.com/NullNoname/Paulscode-SoundSystem/tree/droid (https://github.com/NullNoname/Paulscode-SoundSystem/tree/droid)
LibraryAudioTrack: https://github.com/NullNoname/paudiotrack (https://github.com/NullNoname/paudiotrack)
Example App: https://github.com/NullNoname/pc3dssdemo (https://github.com/NullNoname/pc3dssdemo)

Any suggestions, forks, bug reports and fixes are welcome.