3D Sound System

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

Previous topic - Next topic

Marlon

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:
String path=System.getProperty("user.home")+"\\forgottenelements\\appletcontent\\sound\\"+type+"\\"+name+".wav";
soundSystem.quickPlay(path, false, vec);


I get the following error:
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

EgonOlsen

Have you set


SoundSystemConfig.setSoundFilesPackage("");


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

Marlon

Quote from: EgonOlsen on February 01, 2012, 11:55:50 PM
Have you set


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

paulscode

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)

Marlon

Thanks for your answer.
Actually... I got it running.

If I use

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

paulscode

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.

Marlon

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

paulscode

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).

Marlon

Quote from: paulscode 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.

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:

if(SoundController.getInstance().getSoundSystem()!=null) {
SoundController.getInstance().getSoundSystem().bindListener(cam);
}


Every Frametick I use this code:

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

paulscode

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.

paulscode

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.

paulscode

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

Marlon

#432
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:

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:

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:

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
www.forgottenelements.com
Free Action JAVA MMORPG

EgonOlsen

...ein bisschen sehr in Deutsch, oder ???

Marlon

Quote from: EgonOlsen on February 07, 2012, 09:24:32 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