3D Sound System

Your system looks and sounds really cool PaulLamb and I do wish to try it out.



But when I tried running your examples, I ran into the following problems:



Example 1:

Error in class 'MidiChannel'
    MIDI unavailable, or MIDI device is already in use.
    ERROR MESSAGE:
        MIDI OUT transmitter not available
    STACK TRACE:
        com.sun.media.sound.AbstractMidiDevice.createTransmitter(Unknown Source)
        com.sun.media.sound.AbstractMidiDevice.getTransmitter(Unknown Source)
        javax.sound.midi.MidiSystem.getSequencer(Unknown Source)
        javax.sound.midi.MidiSystem.getSequencer(Unknown Source)
        paulscode.sound.MidiChannel.<init>(MidiChannel.java:225)
        paulscode.sound.Library.loadMidi(Library.java:1164)
        paulscode.sound.SoundSystem.CommandQuickPlay(SoundSystem.java:1418)
        paulscode.sound.SoundSystem.ManageSources(SoundSystem.java:1811)
        paulscode.sound.CommandThread.run(CommandThread.java:118)


This actually appears twice in the console.

Example2 and Example3

Exception in thread "Thread-0" java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException
at java.lang.Class.getDeclaredMethods0(Native Method)
   at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
   at java.lang.Class.getMethod0(Unknown Source)
   at java.lang.Class.getMethod(Unknown Source)
   at paulscode.sound.SoundSystemConfig.runMethod(SoundSystemConfig.java:673)
   at paulscode.sound.SoundSystemConfig.getLibraryTitle(SoundSystemConfig.java:281)
   at paulscode.sound.SoundSystem.CommandNewLibrary(SoundSystem.java:1100)
   at paulscode.sound.SoundSystem.CommandQueue(SoundSystem.java:1997)
   at paulscode.sound.CommandThread.run(CommandThread.java:121)
Caused by: java.lang.ClassNotFoundException: org.lwjgl.LWJGLException
   at java.net.URLClassLoader$1.run(Unknown Source)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.net.URLClassLoader.findClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClassInternal(Unknown Source)
   ... 9 more



I have imported all the jar files and attached them into the build path via a User Library named SoundSystem. I am not particularly good with programming so I am not quite sure as to what is happening. I suppose it could be some really stupid things which I haven't done currently.

Please advice and thanks!

The first error is puzzling to me.  It says there is no MIDI transmitter, but this is the first time I have ever encountered that message before.  Could you please run the following applet and let me know if it works, and what output you get from the “Output Window”:

MIDI Check Applet



The second error appears to indicate that LWJGL was not found.  This usually means you are either not linking with LWJGL, not linking with the correct JARs, or don’t have the natives visible to your program.  Ensure that you have downloaded LWJGL from http://www.lwjgl.org, make sure that you are linking with the correct JARs at runtime, and check that the natives (DLLs if you are running Microsoft Windows) are in whatever directory you are running the applications from.

PaulLamb said:

The first error is puzzling to me.  It says there is no MIDI transmitter, but this is the first time I have ever encountered that message before.  Could you please run the following applet and let me know if it works, and what output you get from the "Output Window":
MIDI Check Applet


I ran it and while I can toggle between Play and Stop MIDI Music, no sound was made and when I push SpaceBar, " MIDI unavailable, or MIDI device is already in use." is displayed.

I am running Vista, could that be breaking anything?

The second error appears to indicate that LWJGL was not found.  This usually means you are either not linking with LWJGL, not linking with the correct JARs, or don't have the natives visible to your program.  Ensure that you have downloaded LWJGL from http://www.lwjgl.org, make sure that you are linking with the correct JARs at runtime, and check that the natives (DLLs if you are running Microsoft Windows) are in whatever directory you are running the applications from.


I have done this and it works now! Thank you for that.
zerohikaru said:

when I push SpaceBar, " MIDI unavailable, or MIDI device is already in use." is displayed.

That is really strange.  Let me play around with the code a little to see if I can come up with a test program that is smart enough to figure out something more specific.

zerohikaru said:

I am running Vista, could that be breaking anything?

I don't think so.  I conducted public MIDI beta-tests when I developed that part of SoundSystem, and a large number of users with a variety of systems were involved.  The only problem I really encountered (not specific to Vista) was imprecise volume changes (i.e. volume=0 was not always completely silent).  Your problem is unique, so I am definitely interested in figuring out what might be the cause.

Ok, can I get you to run the following applet, and copy any output from the Java Console:

MIDI Device Discovery Applet



This is the bare minimum required to check what MIDI devices are present on your system (it doesn’t try to connect, just get the device names).  I want to see if your system can at least make it this far, and if so what devices Java can see.

PaulLamb said:

Ok, can I get you to run the following applet, and copy any output from the Java Console:
MIDI Device Discovery Applet

This is the bare minimum required to check what MIDI devices are present on your system (it doesn't try to connect, just get the device names).  I want to see if your system can at least make it this far, and if so what devices Java can see.


This is what I got:

5 MIDI Devices:
    Java Sound Sequencer
        *this is a Sequencer instance
    Microsoft MIDI Mapper
    Microsoft GS Wavetable Synth
    Real Time Sequencer
        *this is a Sequencer instance
    Java Sound Synthesizer
        *this is a Synthesizer instance



Hope this helps and sorry for not being able to extend much technical help.


Just a side note in linking SoundSystem with jME. I am currently writing a StandardGame and I tried to build SoundSystem into it.

At the moment, I have created a GameState which builds and activates SoundSystem. When I run the whole game however (and I tried creating single instance SoundSystem in a few different locations), I get the following:

Exception in thread "Thread-5" java.lang.IllegalStateException: Only one OpenAL context may be instantiated at any one time.
   at org.lwjgl.openal.AL.create(AL.java:115)
   at org.lwjgl.openal.AL.create(AL.java:104)
   at org.lwjgl.openal.AL.create(AL.java:191)
   at paulscode.sound.libraries.LibraryLWJGLOpenAL.init(LibraryLWJGLOpenAL.java:142)
   at paulscode.sound.SoundSystem.CommandNewLibrary(SoundSystem.java:1152)
   at paulscode.sound.SoundSystem.CommandQueue(SoundSystem.java:1997)
   at paulscode.sound.CommandThread.run(CommandThread.java:121)



I must say I am not familiar with how the threads are running with jME and don't really understand what is going on. Could you point me to a right direction please?

Thanks
zerohikaru said:

This is what I got:

5 MIDI Devices:
    Java Sound Sequencer
        *this is a Sequencer instance
    Microsoft MIDI Mapper
    Microsoft GS Wavetable Synth
    Real Time Sequencer
        *this is a Sequencer instance
    Java Sound Synthesizer
        *this is a Synthesizer instance



It seems that you have the devices needed for MIDI (The Java Sound Sequencer and Synthesizer).  Let me do a little research into what might be causing them to report that they are "in use or unavailable".

zerohikaru said:

(and I tried creating single instance SoundSystem in a few different locations)

It shouldn't matter where you instantiate the SoundSystem (I've spent a great deal of time making sure it is thread safe).

zerohikaru said:

I get the following:

Exception in thread "Thread-5" java.lang.IllegalStateException: Only one OpenAL context may be instantiated at any one time.
   at org.lwjgl.openal.AL.create(AL.java:115)
   at org.lwjgl.openal.AL.create(AL.java:104)
   at org.lwjgl.openal.AL.create(AL.java:191)
   at paulscode.sound.libraries.LibraryLWJGLOpenAL.init(LibraryLWJGLOpenAL.java:142)
   at paulscode.sound.SoundSystem.CommandNewLibrary(SoundSystem.java:1152)
   at paulscode.sound.SoundSystem.CommandQueue(SoundSystem.java:1997)
   at paulscode.sound.CommandThread.run(CommandThread.java:121)



This message means there are two instances of OpenAL, not necessarily that there are two instances of SoundSystem.  If you only instantiated SoundSystem in one single location in your code, then the problem must be a conflict with JME's sound stuff.  I am currently not very familiar with JME (haven't had a lot of time to play around with it yet).  Perhaps someone more experienced with JME can direct you how to make sure it is not connecting to OpenAL before you try to connect to OpenAL via SoundSystem.
PaulLamb said:

It seems that you have the devices needed for MIDI (The Java Sound Sequencer and Synthesizer).  Let me do a little research into what might be causing them to report that they are "in use or unavailable".


Thank you very much for this and good luck with that one.


It shouldn't matter where you instantiate the SoundSystem (I've spent a great deal of time making sure it is thread safe).
This message means there are two instances of OpenAL, not necessarily that there are two instances of SoundSystem.  If you only instantiated SoundSystem in one single location in your code, then the problem must be a conflict with JME's sound stuff.  I am currently not very familiar with JME (haven't had a lot of time to play around with it yet).  Perhaps someone more experienced with JME can direct you how to make sure it is not connecting to OpenAL before you try to connect to OpenAL via SoundSystem.


Your explainations ring some bells. I tried not adding the OpenAL library during the set up and with the SoundSystem taking up JavaSound, the problem is solved (which for me is quite enough at this stage). However, I suspect that it is jME's OpenAL thread blocking the OpenAL library in SoundSystem. I will try seeing into this one and see whether I can get round it.

Thank you very much!

Hi!



What is your state of progress in the integration of your sound system in JME 2?

I haven't had a lot of time to work on this lately (hopefully I will have some this weekend).  One thing I want to do is look at JME's sound stuff to make sure it doesn't conflict with SoundSystem (although looking back at zerohikaru's post I think his problem was likely due to him attempting to use the LibraryLWJGLOpenAL plug-in instead of the LibraryJOAL plug-in).



As far as the random delay problem I mentioned in an earlier post, I solved that.  It was a problem with how I was using the jPCT API, not with the SoundSystem library itself (so it shouldn't affect anyone here).

PaulLamb said:

I haven't had a lot of time to work on this lately (hopefully I will have some this weekend).  One thing I want to do is look at JME's sound stuff to make sure it doesn't conflict with SoundSystem (although looking back at zerohikaru's post I think his problem was likely due to him attempting to use the LibraryLWJGLOpenAL plug-in instead of the LibraryJOAL plug-in).

As far as the random delay problem I mentioned in an earlier post, I solved that.  It was a problem with how I was using the jPCT API, not with the SoundSystem library itself (so it shouldn't affect anyone here).

Ok it sounds good. Thank you very much for your efforts, it will be particularly useful for me and for lots of people. I wanted to know your state of progress because I wonderer if I should use your sound system directly or wait for a better integration in JME 2. Keep it up, we rely on you.

Just another query. Is there a way to figure out whether or not a source has finished playing? I have been looking at the classed and there seems to be a boolean playing but it doesn't seem to stop my guard at the update loop in one of the gamestates.



Thanks.

zerohikaru said:

Just another query. Is there a way to figure out whether or not a source has finished playing? I have been looking at the classed and there seems to be a boolean playing but it doesn't seem to stop my guard at the update loop in one of the gamestates.

The SoundSystem class has a method playing( String sourcename ) which should return true if the specified source is playing and false if not.  If that's the method you are using and it isn't working properly for you, let me know and I'll look into it.
PaulLamb said:

The SoundSystem class has a method playing( String sourcename ) which should return true if the specified source is playing and false if not.  If that's the method you are using and it isn't working properly for you, let me know and I'll look into it.


No problems - I managed to get it to work within the update loop of jME by reseting the timer everytime I play a new Background Music.

Thank you very much!

Just a heads up, it will probably be a month before I can get back to working on the jME integration of SoundSystem.  I started a six-week class a couple of weeks ago, and the homework has been very time consuming ( :x I hate homework, BTW! )

Hi!


PaulLamb said:

Just a heads up, it will probably be a month before I can get back to working on the jME integration of SoundSystem.  I started a six-week class a couple of weeks ago, and the homework has been very time consuming ( :x I hate homework, BTW! )

Good luck for your homework. We really need your sound system. Let us know when you're ready to go on its integration inside JME 2.  :D
PaulLamb said:

Just a heads up, it will probably be a month before I can get back to working on the jME integration of SoundSystem.  I started a six-week class a couple of weeks ago, and the homework has been very time consuming ( :x I hate homework, BTW! )


All the best wishes for the workload!

I hope this doesn't bother you too much, but would I be able to play a file that is located anywhere in my computer? I have tried using the .load on a URL, but it doen't seem to pick up the music file.

Thanks a lot!
zerohikaru said:

I hope this doesn't bother you too much, but would I be able to play a file that is located anywhere in my computer? I have tried using the .load on a URL, but it doen't seem to pick up the music file.

Any exceptions or error messages on the Java console?  Could you also post a little code snippit so I can do some error checking on my end?
zerohikaru said:

This is what I got:

5 MIDI Devices:
    Java Sound Sequencer
        *this is a Sequencer instance
    Microsoft MIDI Mapper
    Microsoft GS Wavetable Synth
    Real Time Sequencer
        *this is a Sequencer instance
    Java Sound Synthesizer
        *this is a Synthesizer instance



PaulLamb said:

It seems that you have the devices needed for MIDI (The Java Sound Sequencer and Synthesizer).  Let me do a little research into what might be causing them to report that they are "in use or unavailable".


Sorry to take so long to get back with you, zerohikaru.  I had a flood of feedback from developers using SoundSystem, so I've been tackling one thing at a time.

I've gotten back to working on your MIDI problem.  It seems that the most likely cause for a MIDI device to not be available is another program using the device (even if it isn't actively playing something. - could even be an "artifact" left behind by a program shut down improperly).  You previously had problems with OpenAL saying it couldn't be instantiated twice, so I wonder if the two issues are related somehow?  The only other cause I could find for this message is driver or hardware problems.

That being said, I believe I may have a way to make MIDI work whenever the default Synthesizer or Sequencer is busy - I can just look through the other MIDI devices for one that is not busy.  I put together a test applet that does this:
http://www.paulscode.com/source/MIDI/MIDIApplet/
Please run it and let me know if it works (I've got my fingers crossed...)  Either way, please copy the output from the Java Console or Output Window, and paste it here for me to look at.

Today I finished a major update to the SoundSystem.  I wrote a new class to make switching between String filename/identifier and URL on the fly very easy.  I worked it into all the streaming methods and the MIDI channel stuff (as well as reworking the loadSound method to use this new setup), so now either URLs or filenames can be used with all types of sources (MIDI, normal, and streaming).  Everything seems to be working after running several quick tests.  However, since the change was rather extensive (I ended up editing almost every class), I need to spend some time doing more extreme testing to make sure the library is still stable and all features work.  I also have a couple more small additions I want to add before the next release.