Doppler Effect Example?

Started by paulscode, August 15, 2010, 22:54:36

Previous topic - Next topic

paulscode

I'm having trouble getting Doppler effect to function, and I'm not sure if I am using stupid values or if I need to set something different.  The tutorial explains how it works, but doesn't include an example.  Does anyone have some example source-code demonstrating working Doppler effect?

For reference, the values I am setting are:

alDopplerFactor is 1.0
alDopplerVelocity is 1.0
alListener, AL_POSITION is 0,0,0
alListener, AL_ORIENTATION is 0,0,-1 0,1,0
alListener, AL_VELOCITY is 0,0,0
alSourcef, AL_PITCH is 1.0
alSource, AL_POSITION is 0,0,0
alSource, AL_VELOCITY is initially 0,0,0, and a couple seconds after playing the source, I change it to 0.2,0.2,0.2

This should result in the pitch becoming higher, correct? I've played around with various different values, but can't seem to produce an audible difference in pitch of the playing source.  If needed, I can write a small program and post the source, however I can probably figure out the problem myself if I can look at an example.  My guess is I'm leaving out some important step to enable Doppler effect.

Momoko_Fan

I think your velocity value is too small, you should also use a sound that you can easily notice change in frequency, like a beep.

Here's some test code that works:
private float location = 0;
    private float rate = 1;

//...

if (location > 10){
            location = 10;
            rate = -rate;
            SetSourceVelocity(rate*10, 0, 0);
        }else if (location < -10){
            location = -10;
            rate = -rate;
            SetSourceVelocity(rate*10, 0, 0);
        }else{
            location += rate * tpf * 10;
        }
        SetSourcePosition(location, 0, 2);


paulscode

Thanks, I used the values you gave and it works.  I think it was just counter-intuitive - I thought the DopplerVelocity represented the speed of sound, so I wasn't using any source velocities above that.  Thanks for the help.