Moving sound problems

Dear All,

I’ve been unable to get a sound to fade by moving its position.
I’m using JOAL release build 1.1 b01 for Windows.
Here’s a snippet of code that doesn’t work:


    if (e.getSource() == playButton) {
      al.alSourcePlay(source[0]);

      float step = 20.0f;
      float zPos = 0.0f;
      for(int i=0; i < 50; i++) {
        zPos += step;

        float[] pos = new float[]{0, 0, zPos};
        al.alSourcefv(source[0], AL.AL_POSITION, pos, 0);

        try {
          Thread.sleep(250);   // sleep for 0.25 secs
        }
        catch(InterruptedException ex) {}
      }
    }

Any suggestions about how to get it to work?

  • Andrew

Hi!

please check if the listener is setup correctly:

		
al.alListenerfv(AL.AL_POSITION, listenerPos, 0);
al.alListenerfv(AL.AL_VELOCITY, listenerVel, 0);		
al.alListenerfv(AL.AL_ORIENTATION, listenerOri, 0);

try setting up the source with a distance model of you choice and make sure that all variables used by the distance formula are set correctly
look here for more information about that: http://www.openal.org/oalspecs-specs/attenuation-by-distance.html

last but not least also make sure that you are playing a MONO wav file, openal can’t fade a source with Stereo data

i hope this will help you! if not please post more of the source code!
have a nice day!

greetings from austria

The problem was that the sound was stereo. The code works when the file was saved in mono.

A quick way of finding out on Win XP is to right click on the properties menu for the audio file, and then look at the “Summary” tab.

Thanks,
Andrew