aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2009-12-01 03:32:04 -0800
committerChris Robinson <[email protected]>2009-12-01 03:32:04 -0800
commitd5889a941f5ecfe0ba15e57666d2f0cc39052628 (patch)
treea1b5f94b2fe99d53a1eeab0c42ad68ff5097702a
parent6248e986e58ee91f3570d3f6fde96e6a558bedd7 (diff)
Clamp dry gain after cone attenuation is applied
-rw-r--r--Alc/ALu.c75
1 files changed, 39 insertions, 36 deletions
diff --git a/Alc/ALu.c b/Alc/ALu.c
index 54369c4b..ce0f841c 100644
--- a/Alc/ALu.c
+++ b/Alc/ALu.c
@@ -425,6 +425,9 @@ static ALvoid CalcSourceParams(const ALCcontext *ALContext, ALsource *ALSource,
ALint pos, s, i;
ALfloat cw, a, g;
+ for(i = 0;i < MAX_SENDS;i++)
+ WetGainHF[i] = 1.0f;
+
//Get context properties
DopplerFactor = ALContext->DopplerFactor * ALSource->DopplerFactor;
DopplerVelocity = ALContext->DopplerVelocity;
@@ -646,18 +649,10 @@ static ALvoid CalcSourceParams(const ALCcontext *ALContext, ALsource *ALSource,
break;
}
- // Source Gain + Attenuation and clamp to Min/Max Gain
+ // Source Gain + Attenuation
DryMix = SourceVolume * flAttenuation;
- DryMix = __min(DryMix,MaxVolume);
- DryMix = __max(DryMix,MinVolume);
-
for(i = 0;i < NumSends;i++)
- {
- ALfloat WetMix = SourceVolume * RoomAttenuation[i];
- WetMix = __min(WetMix,MaxVolume);
- WetGain[i] = __max(WetMix,MinVolume);
- WetGainHF[i] = 1.0f;
- }
+ WetGain[i] = SourceVolume * RoomAttenuation[i];
// Distance-based air absorption
if(ALSource->AirAbsorptionFactor > 0.0f && flAttenuation < 1.0f)
@@ -702,31 +697,9 @@ static ALvoid CalcSourceParams(const ALCcontext *ALContext, ALsource *ALSource,
ConeHF = 1.0f;
}
- //4. Calculate Velocity
- if(DopplerFactor != 0.0f)
- {
- ALfloat flVSS, flVLS;
- ALfloat flMaxVelocity = (DopplerVelocity * flSpeedOfSound) /
- DopplerFactor;
-
- flVSS = aluDotproduct(Velocity, SourceToListener);
- if(flVSS >= flMaxVelocity)
- flVSS = (flMaxVelocity - 1.0f);
- else if(flVSS <= -flMaxVelocity)
- flVSS = -flMaxVelocity + 1.0f;
-
- flVLS = aluDotproduct(ListenerVel, SourceToListener);
- if(flVLS >= flMaxVelocity)
- flVLS = (flMaxVelocity - 1.0f);
- else if(flVLS <= -flMaxVelocity)
- flVLS = -flMaxVelocity + 1.0f;
-
- ALSource->Params.Pitch = ALSource->flPitch *
- ((flSpeedOfSound * DopplerVelocity) - (DopplerFactor * flVLS)) /
- ((flSpeedOfSound * DopplerVelocity) - (DopplerFactor * flVSS));
- }
- else
- ALSource->Params.Pitch = ALSource->flPitch;
+ // Clamp to Min/Max Gain
+ DryMix = __min(DryMix,MaxVolume);
+ DryMix = __max(DryMix,MinVolume);
for(i = 0;i < NumSends;i++)
{
@@ -740,6 +713,10 @@ static ALvoid CalcSourceParams(const ALCcontext *ALContext, ALsource *ALSource,
if(ALSource->WetGainHFAuto)
WetGainHF[i] *= ConeHF;
+ // Clamp to Min/Max Gain
+ WetGain[i] = __min(WetGain[i],MaxVolume);
+ WetGain[i] = __max(WetGain[i],MinVolume);
+
if(ALSource->Send[i].Slot->effect.type == AL_EFFECT_REVERB ||
ALSource->Send[i].Slot->effect.type == AL_EFFECT_EAXREVERB)
{
@@ -789,7 +766,7 @@ static ALvoid CalcSourceParams(const ALCcontext *ALContext, ALsource *ALSource,
WetGainHF[i] = 1.0f;
}
- //5. Apply filter gains and filters
+ // Apply filter gains and filters
switch(ALSource->DirectFilter.type)
{
case AL_FILTER_LOWPASS:
@@ -799,6 +776,32 @@ static ALvoid CalcSourceParams(const ALCcontext *ALContext, ALsource *ALSource,
}
DryMix *= ListenerGain;
+ // Calculate Velocity
+ if(DopplerFactor != 0.0f)
+ {
+ ALfloat flVSS, flVLS;
+ ALfloat flMaxVelocity = (DopplerVelocity * flSpeedOfSound) /
+ DopplerFactor;
+
+ flVSS = aluDotproduct(Velocity, SourceToListener);
+ if(flVSS >= flMaxVelocity)
+ flVSS = (flMaxVelocity - 1.0f);
+ else if(flVSS <= -flMaxVelocity)
+ flVSS = -flMaxVelocity + 1.0f;
+
+ flVLS = aluDotproduct(ListenerVel, SourceToListener);
+ if(flVLS >= flMaxVelocity)
+ flVLS = (flMaxVelocity - 1.0f);
+ else if(flVLS <= -flMaxVelocity)
+ flVLS = -flMaxVelocity + 1.0f;
+
+ ALSource->Params.Pitch = ALSource->flPitch *
+ ((flSpeedOfSound * DopplerVelocity) - (DopplerFactor * flVLS)) /
+ ((flSpeedOfSound * DopplerVelocity) - (DopplerFactor * flVSS));
+ }
+ else
+ ALSource->Params.Pitch = ALSource->flPitch;
+
// Use energy-preserving panning algorithm for multi-speaker playback
length = aluSqrt(Position[0]*Position[0] + Position[1]*Position[1] +
Position[2]*Position[2]);