Sound System

Arman has contributed the initial Sound System. Check it out! Let him know what you think, if it works, etc.

I have tried to test the sound system but keep getting this error



org.lwjgl.openal.OpenALException: Unable to load function pointers to
openal.
        at org.lwjgl.openal.BaseAL.nCreate(Native Method)
        at org.lwjgl.openal.BaseAL.create(Unknown Source)
        at org.lwjgl.openal.AL.create(Unknown Source)
        at com.jme.sound.LWJGLSoundSystem.initOpenAL(Unknown Source)
        at com.jme.sound.LWJGLSoundSystem.createSoundSystem(Unknown Source)



Anybody knows what the error is? Do I need a specific jar or windows dll for this?

tomcat

I forgot to include the lwjglsound.dll in cvs. It’s in there now, so update the lib directory. Also, update the data directory to get the sound referenced, and get the new TestSound in the sound directory.



It should then work for you. :slight_smile:

Thanks, It seems that I was only missing the dll. I used my own wav file and it seems to work fine on my machine. The strange thing, once you load the sound the Thread.sleep(sometime) is used to cause delay once sound is being played back to the user.


        soundsystem.getRenderer().loadWaveAs("test1", "./sounds/Battle.wav", 0);
        soundsystem.getRenderer().play("test1");
        Thread.sleep(10000L);



I thought it creates a seperate thread within which the sound can be played (once started).

Another thing is that I dont seem to be able to load multiple sound files and play them one after the other or simply play them. I used this


       soundsystem.getRenderer().loadWaveAs("test3", "./sounds/ringout.wav", 0);
        soundsystem.getRenderer().play("test2");       
        Thread.sleep(1000L);

       soundsystem.getRenderer().loadWaveAs("test2", "./sounds/ringin.wav", 0);
        soundsystem.getRenderer().play("test3");
        Thread.sleep(1000L);



Apart from this it seems to work fine.

tomcat

I think you are overloading the previous sound by calling each 0.



Arman can answer this better than I can.



Try this:


soundsystem.getRenderer().loadWaveAs("test3", "./sounds/ringout.wav", 3);
       soundsystem.getRenderer().loadWaveAs("test2", "./sounds/ringin.wav", 2);

        soundsystem.getRenderer().play("test2");       
        Thread.sleep(1000L);
        soundsystem.getRenderer().play("test3");
        Thread.sleep(1000L);

tried that. Same problem



Exception in thread "main" java.lang.IndexOutOfBoundsException
        at java.nio.Buffer.checkIndex(Buffer.java:438)
        at java.nio.DirectIntBufferU.get(DirectIntBufferU.java:196)
        at com.jme.sound.LWJGLSoundRenderer.loadWaveAs(Unknown Source)

        at SndTst.main(SndTst.java:21)



line 21 in my code is


       soundsystem.getRenderer().loadWaveAs("test3", "./sounds/ringout.wav", 2);



where I try to load the second sound.

Arman is going to have to tackle this one then. I don’t know nearly enough about OpenAL.

Hello,

I am pleased you started to test the sound part.



I did not see the createSoundSystem method in your post but let me explain a few things about it:

For the moment the number of buffers and sources are limited by the values you enter there.



The maxBuffer value is the maximum number of wav files you can upload to memory.

The same for the sources.



Knowing that, one source can play several buffers actually, but not in the same time.

If you want to play one buffer after the other on the same source do as following.



SoundSystem system=SoundSystem.getSoundSystem("LWJGL");
      system.createSoundSystem(1, 2);
      system.getRenderer().loadWaveAs("test", "Battle.wav", 0);
      system.getRenderer().loadWaveAs("test2", "ding.wav", 0);
      system.getRenderer().play("test");
      Thread.sleep(5000);
      system.getRenderer().play("test2");
      Thread.sleep(5000);


The third parameter of loadWaveAs is "from where" you want to hear the sound. For instance it's the only source we have created -> 0 (first in the array of sources).

Now if you want to play two different buffers (sounds) in the same time you have to declare 2 sources and 2 buffers as following


SoundSystem system=SoundSystem.getSoundSystem("LWJGL");
      system.createSoundSystem(2, 2);
      system.getRenderer().loadWaveAs("test", "Battle.wav", 0);
      system.getRenderer().loadWaveAs("test2", "ding.wav", 1);
      system.getRenderer().play("test");
      system.getRenderer().play("test2");
      Thread.sleep(5000);



I hope I helped you.
Arman.

8-O Oups I 've just realized that I put the createSoundSystem args in the reverse order.

I’ll correct it now! Thats why you have an array problem.

://

Thanks I have tried the following which works



        SoundSystem soundsystem = SoundSystem.getSoundSystem("LWJGL");
        soundsystem.createSoundSystem(3, 3);

        soundsystem.getRenderer().loadWaveAs("test1", "./sounds/Battle.wav", 0);
       soundsystem.getRenderer().loadWaveAs("test2", "./sounds/ringin.wav", 1);
       soundsystem.getRenderer().loadWaveAs("test3", "./sounds/ringout.wav", 2);

        soundsystem.getRenderer().play("test1");
        Thread.sleep(3000L);

        soundsystem.getRenderer().play("test2");       
        Thread.sleep(3000L);

        soundsystem.getRenderer().play("test3");
        Thread.sleep(2000L);



This plays the three files together. But when I tried this, its keep playing the first file three times:


        SoundSystem soundsystem = SoundSystem.getSoundSystem("LWJGL");
        soundsystem.createSoundSystem(3, 1);

        soundsystem.getRenderer().loadWaveAs("test1", "./sounds/Battle.wav", 0);
       soundsystem.getRenderer().loadWaveAs("test2", "./sounds/ringin.wav", 0);
       soundsystem.getRenderer().loadWaveAs("test3", "./sounds/ringout.wav", 0);

        soundsystem.getRenderer().play("test1");
        Thread.sleep(3000L);

        soundsystem.getRenderer().play("test2");       
        Thread.sleep(3000L);

        soundsystem.getRenderer().play("test3");
        Thread.sleep(2000L);



Doing


soundsystem.createSoundSystem(3, 1);



cause the array error. Dont know 8-O what is going on.

My understanding is that you can load a file into the memory and play it whenever you like. You can also play multiple sounds together (at the same time) if you want. What I dont understand is why do we need the thread and how do I decide how many miliseconds do I need for the thread. :?

thanks
tomcat

Hi,

if you were in the game loop you wouldn’t need this

Thread.sleep(time);


the clip would play entirely

Because we are in the main method (for testing), we let the background thread, launched by lwjgl, continue by making the "currentThread" sleep.

Does this answer your question?

So, Arman, the sleep was there for testing purposes only? No need for it in a real game?

Thanks Arman. This is a relief. :wink: