How to add Doppler shift to your sounds using OpenAL
by David Wyand · in Torque Game Engine · 04/04/2003 (1:28 pm) · 3 replies
Greetings!
I've been playing around with sound in the TGE with the recent update to the OpenAL driver. This time around, I've actually downloaded the OpenAL docs to see what it can do. I've read that it can automatically apply a Doppler shift to your sounds, and I'm here to show you all how I've done it.
1. Open up engine/game/game.cc
2. Go to the clientProcess() function.
3. Find the line that reads:
4. Uncomment it and change it to read:
5. Recompile and enjoy!
Easy, eh? Two other functions are optional if you want to play with how the Doppler shift is applied:
alDopplerFactor(float) - This function allows you to exaggerate or tone-down the Doppler shift effect. The default is 1.0.
alDopplerVelocity(float) - This function allows you to the change the default velocity that the Doppler shift calculation is based on. The default is 343.0. If you have players moving really fast, then you may want to adjust this to stop the Doppler shift from distorting the sound too much.
I'd recommend that you place these two functions somewhere within OpenALInit() in audio.cc.
Please let me know if these work for you, and if so, then I'll turn this into a resource. Thanks!
- LightWave Dave
I've been playing around with sound in the TGE with the recent update to the OpenAL driver. This time around, I've actually downloaded the OpenAL docs to see what it can do. I've read that it can automatically apply a Doppler shift to your sounds, and I'm here to show you all how I've done it.
1. Open up engine/game/game.cc
2. Go to the clientProcess() function.
3. Find the line that reads:
// alxListener3f(AL_VELOCITY, velocity.x, velocity.y, velocity.z);within the if (GameGetCameraTransform(&mat, &velocity)) block.
4. Uncomment it and change it to read:
alxListenerPoint3F(AL_VELOCITY, &velocity);
5. Recompile and enjoy!
Easy, eh? Two other functions are optional if you want to play with how the Doppler shift is applied:
alDopplerFactor(float) - This function allows you to exaggerate or tone-down the Doppler shift effect. The default is 1.0.
alDopplerVelocity(float) - This function allows you to the change the default velocity that the Doppler shift calculation is based on. The default is 343.0. If you have players moving really fast, then you may want to adjust this to stop the Doppler shift from distorting the sound too much.
I'd recommend that you place these two functions somewhere within OpenALInit() in audio.cc.
Please let me know if these work for you, and if so, then I'll turn this into a resource. Thanks!
- LightWave Dave
About the author
A long time Associate of the GarageGames' community and author of the Torque 3D Game Development Cookbook. Buy it today from Packt Publishing!
#2
04/04/2003 (6:01 pm)
Thanks!! Now, can you get the positional audio working? :D
#3
I'm glad you guys like the changes.
Chris, what specifically were you having a problem with? I've been able to create a looping 3D audio source in the mission editor, and when I run past it, the audio pans correctly in my two speakers.
- LightWave Dave
04/07/2003 (11:16 am)
Greetings!I'm glad you guys like the changes.
Chris, what specifically were you having a problem with? I've been able to create a looping 3D audio source in the mission editor, and when I run past it, the audio pans correctly in my two speakers.
- LightWave Dave
Torque 3D Owner Jackie Hayes
MJ....