From e190fc9416a14bbe35abfde94f38ff8ca98dfa99 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 8 Mar 2012 18:19:15 -0800 Subject: Refactor the doppler shift calculations --- Alc/ALu.c | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) (limited to 'Alc/ALu.c') diff --git a/Alc/ALu.c b/Alc/ALu.c index be1f6103..32f14022 100644 --- a/Alc/ALu.c +++ b/Alc/ALu.c @@ -336,7 +336,7 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext) ALfloat Velocity[3],ListenerVel[3]; ALfloat MinVolume,MaxVolume,MinDist,MaxDist,Rolloff; ALfloat ConeVolume,ConeHF,SourceVolume,ListenerGain; - ALfloat DopplerFactor, DopplerVelocity, SpeedOfSound; + ALfloat DopplerFactor, SpeedOfSound; ALfloat AirAbsorptionFactor; ALfloat RoomAirAbsorption[MAX_SENDS]; ALbufferlistitem *BufferListItem; @@ -365,11 +365,10 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext) WetGainHF[i] = 1.0f; //Get context properties - DopplerFactor = ALContext->DopplerFactor * ALSource->DopplerFactor; - DopplerVelocity = ALContext->DopplerVelocity; - SpeedOfSound = ALContext->flSpeedOfSound; - NumSends = Device->NumAuxSends; - Frequency = Device->Frequency; + DopplerFactor = ALContext->DopplerFactor * ALSource->DopplerFactor; + SpeedOfSound = ALContext->flSpeedOfSound * ALContext->DopplerVelocity; + NumSends = Device->NumAuxSends; + Frequency = Device->Frequency; //Get listener properties ListenerGain = ALContext->Listener.Gain; @@ -624,26 +623,14 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext) } // Calculate Velocity - if(DopplerFactor != 0.0f) + if(DopplerFactor > 0.0f) { ALfloat VSS, VLS; - ALfloat MaxVelocity = (SpeedOfSound*DopplerVelocity) / - DopplerFactor; - - VSS = aluDotproduct(Velocity, SourceToListener); - if(VSS >= MaxVelocity) - VSS = (MaxVelocity - 1.0f); - else if(VSS <= -MaxVelocity) - VSS = -MaxVelocity + 1.0f; - - VLS = aluDotproduct(ListenerVel, SourceToListener); - if(VLS >= MaxVelocity) - VLS = (MaxVelocity - 1.0f); - else if(VLS <= -MaxVelocity) - VLS = -MaxVelocity + 1.0f; - - Pitch *= ((SpeedOfSound*DopplerVelocity) - (DopplerFactor*VLS)) / - ((SpeedOfSound*DopplerVelocity) - (DopplerFactor*VSS)); + + VSS = aluDotproduct(Velocity, SourceToListener) * DopplerFactor; + VLS = aluDotproduct(ListenerVel, SourceToListener) * DopplerFactor; + + Pitch *= maxf(SpeedOfSound-VLS, 1.0f) / maxf(SpeedOfSound-VSS, 1.0f); } BufferListItem = ALSource->queue; -- cgit v1.2.3