Doppler Effect

syedhs

11-04-2007 20:56:51

Hi,

I am trying to create a doppler effect: a camera will just wait at the roadside for vehicle.. and the vehicle pass.. and well you know it :wink: The problem is there is no doppler effect - the sound stays the same. Just to make sure I am not missing anything, here is the code flow:-
Setup
1. Create sound
2. setRelativeDistance(true); // may not be applicable here..
3. setRenderingDistance; // may not applicable too
4. and attach it to SceneNode of the vehicle.

5. Create camera SceneNode
6. attach camera to it
7. attach the SoundManager::getSingleton().getListener() to this node too.

In loop
1. setVelocity to the sound.

I think the setup is quite straight forward; I may miss some step but I doubt it. The culprit could be the setVelocity. I may not provide the correct value. Currently I am using Ageia PhysX and I use the linear velocity of the actor (rigid body of the car) as the velocity. Linear velocity has x,y,z and I think should be okay.

Okay what else did I miss?

Edit: Okay I do vary the sound pitch in every frame. Should be okay isn't it?

CaseyB

11-04-2007 21:54:49

That should do it. What does the linear velocity look like? By default the velocity that gets passed in should be in meters per second, if the linear velocity is in some other measure then you need to call SoundManager::setSpeedOfSound() with the speed of sound in the units that it uses. You can also play with SoundManager::setDopplerFactor(), by default it is 1.0 and should correspond to the true Doppler effect at the given velocity and speed of sound values, but you can crank it up and see what happens.

syedhs

12-04-2007 05:20:18

I have a feeling that a stereo wav file may not achieve the doppler/relative listener effect. Okay, that is just my thought - I will try it in a couple of hours :)

Edit: Okay I decide to try it now, and it seems to work. Maybe the requirement is to have a mono audio? Btw, it is not conclusive yet but definitely there is a difference.

CaseyB

12-04-2007 05:28:26

Maybe the requirement is to have a mono audio?Yup, that's it! OpenAL can't render a stereo sound in 3D becuase all of the channels are full. You can use stereo (or even multi-channel, i.e. 5.1, 6.1, 7.1) Sound for background music, but for 3D sounds they must be mono.

syedhs

12-04-2007 07:35:24

Right now it works like charm. Thanks for the library :)

I am looking forward to next version which I understand include audio culling eg audio from a source blocked from our eyes should be somehow blocked from our hears. But that's is not ultra important in my TODO list :)

CaseyB

12-04-2007 07:45:33

Glad you got it working! Yeah, there is a pretty hefty feature list for the next release, so it make take a while to "make it official" but all of the latest stuff will be available in SVN and I'll announce those updates here, so stay tuned!