Author Topic: 3D Sound System  (Read 184371 times)

Offline Marlon

  • int
  • **
  • Posts: 74
    • View Profile
    • Forgotten Elements Action MMORPG
Re: 3D Sound System
« Reply #420 on: February 01, 2012, 11:23:11 pm »
Hello!
I want to use SoundSystemJPCT for my game and I wonder if I can play a wav file, which is stored at a fix position on my hard drive.
I do not want to compile a sound file into a jar, I want to play it while using an absolute path to this file.

For example: If I use this code:
Code: [Select]
String path=System.getProperty("user.home")+"\\forgottenelements\\appletcontent\\sound\\"+type+"\\"+name+".wav";
soundSystem.quickPlay(path, false, vec);

I get the following error:
Code: [Select]
Error in class 'LibraryJavaSound'
    Unable to open file 'C:\Users\Marlon\forgottenelements\appletcontent\sound\misc\queststart.wav' in method 'loadSound'

I searched with the help of google, I searched in this forum, but I couldn't find anything useful.

Thanks in advance!
Marlon
www.forgottenelements.com
Free Action JAVA MMORPG

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11769
    • View Profile
    • http://www.jpct.net
Re: 3D Sound System
« Reply #421 on: February 01, 2012, 11:55:50 pm »
Have you set

Code: [Select]
SoundSystemConfig.setSoundFilesPackage("");

? I don't know if one has to, but i did in Robombs and i had no problem loading files from disk.

Offline Marlon

  • int
  • **
  • Posts: 74
    • View Profile
    • Forgotten Elements Action MMORPG
Re: 3D Sound System
« Reply #422 on: February 02, 2012, 12:25:07 am »
Have you set

Code: [Select]
SoundSystemConfig.setSoundFilesPackage("");

? I don't know if one has to, but i did in Robombs and i had no problem loading files from disk.

I already set this, but without success. :(
I checked the Robombs source code, but it seems that there sound files are loaded with relative paths?

Any other tipps?
www.forgottenelements.com
Free Action JAVA MMORPG

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: 3D Sound System
« Reply #423 on: February 03, 2012, 09:01:42 pm »
When the file is not compiled into the JAR, you must use the loadSound method (the version that takes a URL instance & a String identifier).  This is usually called when initializing the application, or loading a scene or game level.  The identifier should look like a filename (ending in .wav for example) because that is how the library knows which codec to use.  Then calls to quickPlay will use that identifier in place of the filename parameter.  When you are done with the sample, you can call unloadSound if you want to free the memory it is using (such as when transitioning between game levels that have a different set of sound effects)

Offline Marlon

  • int
  • **
  • Posts: 74
    • View Profile
    • Forgotten Elements Action MMORPG
Re: 3D Sound System
« Reply #424 on: February 06, 2012, 06:22:02 pm »
Thanks for your answer.
Actually... I got it running.

If I use
Code: [Select]
String path=System.getProperty("user.home")+"\\forgottenelements\\appletcontent\\sound\\"+type+"\\"+name+".wav";
if(soundNotLoaded(path)) {
try {
soundSystem.loadSound(new File(path).toURL(), path);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
soundSystem.quickPlay(path, false, vec);

... the sound gets loaded correctly and it is played.
But... the problem is that the sound always is panned the same (I can hear the same sound with the same volume on each speaker).
For the position of the sound I use a 3D object.
It seems that there is no 3D effect. Mhhh... did I do something wrong?
www.forgottenelements.com
Free Action JAVA MMORPG

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: 3D Sound System
« Reply #425 on: February 06, 2012, 07:43:04 pm »
Make sure your file is mono, not stereo.  Stereo files should be used for ambient sources, like background music, crickets, etc, and mono files should be used for point sources.

Offline Marlon

  • int
  • **
  • Posts: 74
    • View Profile
    • Forgotten Elements Action MMORPG
Re: 3D Sound System
« Reply #426 on: February 06, 2012, 07:54:20 pm »
Of course my file is mono (I use it at Forgotten Elements 2D already). Only the background music is stereo.
www.forgottenelements.com
Free Action JAVA MMORPG

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: 3D Sound System
« Reply #427 on: February 06, 2012, 08:48:40 pm »
I didn't mean to insult your intelligence, but I can't even count how many times that question has been asked from folks using stereo files.  Is this problem happening with every file or just particular ones?  Could you post a link to one of the audio files that is having the problem?  If the sound is mono and the source position is not virtually the same as the listener position, and the attenuation model is not ATTENUATION_NONE, then there must be a bug in my code somewhere.  It will be easier to track down the cause with a file that experiences the problem (none of my files are doing this).

Offline Marlon

  • int
  • **
  • Posts: 74
    • View Profile
    • Forgotten Elements Action MMORPG
Re: 3D Sound System
« Reply #428 on: February 06, 2012, 10:45:31 pm »
I didn't mean to insult your intelligence, but I can't even count how many times that question has been asked from folks using stereo files.

No problem, I can understand that.
I wrote an own engine for my game (www.forgottenelements.com / still in 2D) and pan the sound depending on where the enemies are located. Because I am transforming my game to a 3D game and use JPCT I thought about using your Library also.

When I initialize the JPCT Camera I use the following code:
Code: [Select]
if(SoundController.getInstance().getSoundSystem()!=null) {
SoundController.getInstance().getSoundSystem().bindListener(cam);
}

Every Frametick I use this code:
Code: [Select]
if(SoundController.getInstance().getSoundSystem()!=null) {
SoundController.getInstance().getSoundSystem().tick();
}

I don't set any Attenuation, should I do this?
For example I use this file:
www.forgottenelements.com/appletcontent/sound/misc/questcomplete.wav

Thanks,
Marlon
www.forgottenelements.com
Free Action JAVA MMORPG

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: 3D Sound System
« Reply #429 on: February 07, 2012, 12:27:31 am »
By default, it should use ATTENUATION_ROLLOFF, so if you aren't changing it that shouldn't be the problem.  I downloaded your file and will do some tests.  I'll let you know what I find.

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: 3D Sound System
« Reply #430 on: February 07, 2012, 12:37:34 am »
Hmm.. it seems to pan ok on my computer.  Let me write a quick test applet for you to run, to rule out a hardware-related issue.

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: 3D Sound System
« Reply #431 on: February 07, 2012, 01:48:52 am »
Ok, I rigged up one of my old applets.  Let me know if you hear/ don't hear the panning between left/ right speakers as the camera rotates in place:

Panning Test Applet

Offline Marlon

  • int
  • **
  • Posts: 74
    • View Profile
    • Forgotten Elements Action MMORPG
Re: 3D Sound System
« Reply #432 on: February 07, 2012, 09:05:03 pm »
Wow! First I have to say thank you! And its great that you posted a demo applet!
The Applet is running and 3D Sound working.
Its like the wheels are rotating around my head. :)

But: It's still not running with my code. The sound always has the same volume and panning and then (20 Sounds later) there is an exception:
Code: [Select]
java.lang.NullPointerException
at paulscode.sound.SoundSystemJPCT.tick(SoundSystemJPCT.java:270)
at graphic.Graphic3DController.update(Graphic3DController.java:708)

And at the beginning there is this exception:
Code: [Select]
Initializing LWJGL OpenAL
    (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.org)
Error in class 'LibraryLWJGLOpenAL'
    Unable to initialize OpenAL.  Probable cause: OpenAL not supported.
    ERROR MESSAGE:
        Could not locate OpenAL library.
    STACK TRACE:
        org.lwjgl.openal.AL.create(AL.java:151)
        org.lwjgl.openal.AL.create(AL.java:102)
        org.lwjgl.openal.AL.create(AL.java:201)
        paulscode.sound.libraries.LibraryLWJGLOpenAL.init(LibraryLWJGLOpenAL.java:164)
        paulscode.sound.SoundSystem.CommandNewLibrary(SoundSystem.java:1576)
        paulscode.sound.SoundSystem.CommandQueue(SoundSystem.java:2572)
        paulscode.sound.CommandThread.run(CommandThread.java:121)
    ERROR MESSAGE:
        Could not locate OpenAL library.

Starting up SoundSystemJPCT...
Switching to Java Sound
    (The Java Sound API.  For more information, see http://java.sun.com/products/java-media/sound/)
JavaSound initialized.


I am initializing this way:
Code: [Select]
public void initSoundSystem() {
        try
        {
            // add some plug-ins:
            SoundSystemConfig.addLibrary( LibraryLWJGLOpenAL.class );
            SoundSystemConfig.addLibrary( LibraryJavaSound.class );
            SoundSystemConfig.setCodec( "wav", CodecWav.class );
        }
        catch( SoundSystemException e )
        {}
soundSystem=new SoundSystemJPCT();
SoundSystemConfig.setSoundFilesPackage("");
}

At the end I call cleanup(), to avoid dead instances.

Marlon

Edit: Wrong language ;D
« Last Edit: February 07, 2012, 09:51:16 pm by Marlon »
www.forgottenelements.com
Free Action JAVA MMORPG

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11769
    • View Profile
    • http://www.jpct.net
Re: 3D Sound System
« Reply #433 on: February 07, 2012, 09:24:32 pm »
...ein bisschen sehr in Deutsch, oder ???

Offline Marlon

  • int
  • **
  • Posts: 74
    • View Profile
    • Forgotten Elements Action MMORPG
Re: 3D Sound System
« Reply #434 on: February 07, 2012, 09:53:19 pm »
...ein bisschen sehr in Deutsch, oder ???

Bamm... OMG... fortunately I am only speaking 2 languages... Sorry for wrong language.  :-[
But its edited already... ;)
www.forgottenelements.com
Free Action JAVA MMORPG