Game Development Community

Audio position interpolation fix

by Henry Todd · in Torque Game Engine · 11/28/2007 (7:38 pm) · 6 replies

I had a hard time finding this on the forums, but I did eventually pull up a 2002 reference. Basically, all of the audio calls for players, vehicles, weapon images and anything else that makes sounds are incorrectly using getTransform(), which is the latest non-interpolated position. Since sounds only get played on the client, you'll want to use getRenderTransform().

Making this change in, for example, flyingVehicle.cc will fix the engine audio stuttering you experience at speeds high enough to result in lag between actual positions and interpolated client positions.

In flyingVehicle.cc, find this function:

void FlyingVehicle::updateEngineSound(F32 level)
{
   if (mEngineSound) {
      alxSourceMatrixF(mEngineSound, &getTransform());
      alxSourcef(mEngineSound, AL_GAIN_LINEAR, level);
   }
}

and make the change in bold:

void FlyingVehicle::updateEngineSound(F32 level)
{
   if (mEngineSound) {
      alxSourceMatrixF(mEngineSound, [b]&getRenderTransform()[/b]);
      alxSourcef(mEngineSound, AL_GAIN_LINEAR, level);
   }
}
Repeat as needed for basically every sound effect in the engine. You can basically just search for "&getTransform()", as this use of getTransform is basically used only in the audio code. Don't just use replace all though; make sure it's actually audio code before making the change.

This seems like a pretty old bug that should probably make it into the next version.

#1
11/28/2007 (8:20 pm)
I wonder what the difference is, and why it hasn't been caught before.
#2
11/29/2007 (8:50 pm)
Basically, getTransform only gives you the server position, which is rarely in sync with the interpolated client position (getRenderTransform). If you select a vehicle in the editor and then drive it, you'll see the server position is generally slightly lagged compared to the client position (bounding box represents the server position). The result is sounds which seem to be coming from slightly the wrong place, like gunshots sounding like they were fired from where you were a second ago instead of your current position (this effect is very obvious when shooting while strafing left/right at a decent speed).

www.garagegames.com/mg/forums/result.thread.php?qt=3146

This post from 2002 explains the issue. I assume this fix never made it into an official release because of the sheer quantity of lines which need the fix and its relatively non-critical nature (the sound lag is only especially problematic at high speeds; at normal Player speeds, it's just slightly annoying). There shouldn't be any situation where a sound needs to play at the server position, excepting types of objects which don't implement any interpolation (and even for these objects it's still safe to call getRenderTransform(), as every rendered object has a render trans.)
#3
11/30/2007 (5:05 pm)
Wow. big glitch for real time games.. Thanks Henry. Tag for later.
#4
12/01/2007 (2:37 pm)
Thankyou for the explination. :-)

Quote:
I assume this fix never made it into an official release because of the sheer quantity of lines which need the fix and its relatively non-critical nature

It took me 10 minutes start to finish including cleaning the build and rebuilding the demo. Not a big thing to fix.
Thanks for posting this. (now have to test)
#5
12/01/2007 (7:43 pm)
Yes thank you it seems to have helped me on some of my vehicles.
#6
12/02/2007 (6:27 am)
Good catch!