aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/ALu.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2012-03-08 18:19:15 -0800
committerChris Robinson <[email protected]>2012-03-08 18:19:15 -0800
commite190fc9416a14bbe35abfde94f38ff8ca98dfa99 (patch)
treeb1ed089e83e2a7faa0746b4c25ec2b35884d7f8f /Alc/ALu.c
parent1a4a0abd1a1fd9a20345db54efef6587bec67197 (diff)
Refactor the doppler shift calculations
Diffstat (limited to 'Alc/ALu.c')
-rw-r--r--Alc/ALu.c35
1 files changed, 11 insertions, 24 deletions
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;