From 4a8c3b50b649815af123a08689efd7d16f9a571b Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 29 Mar 2018 15:41:51 -0700 Subject: [PATCH] Apply the initial decay and air absorption after gain clamping --- Alc/ALu.c | 84 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/Alc/ALu.c b/Alc/ALu.c index bbac0d2f..51150cd7 100644 --- a/Alc/ALu.c +++ b/Alc/ALu.c @@ -1317,48 +1317,6 @@ static void CalcAttnSourceParams(ALvoice *voice, const struct ALvoiceProps *prop break; } - /* Distance-based air absorption */ - if(ClampedDist > props->RefDistance && props->RolloffFactor > 0.0f) - { - ALfloat meters_base = (ClampedDist-props->RefDistance) * props->RolloffFactor * - Listener->Params.MetersPerUnit; - if(props->AirAbsorptionFactor > 0.0f) - { - ALfloat hfattn = powf(AIRABSORBGAINHF, meters_base * props->AirAbsorptionFactor); - DryGainHF *= hfattn; - for(i = 0;i < NumSends;i++) - WetGainHF[i] *= hfattn; - } - - if(props->WetGainAuto) - { - /* Apply a decay-time transformation to the wet path, based on the - * source distance in meters. The initial decay of the reverb - * effect is calculated and applied to the wet path. - */ - for(i = 0;i < NumSends;i++) - { - ALfloat gain, gainhf, gainlf; - - if(!(DecayDistance[i] > 0.0f)) - continue; - - gain = powf(REVERB_DECAY_GAIN, meters_base/DecayDistance[i]); - WetGain[i] *= gain; - /* Yes, the wet path's air absorption is applied with - * WetGainAuto on, rather than WetGainHFAuto. - */ - if(gain > 0.0f) - { - gainhf = powf(REVERB_DECAY_GAIN, meters_base/DecayHFDistance[i]); - WetGainHF[i] *= minf(gainhf / gain, 1.0f); - gainlf = powf(REVERB_DECAY_GAIN, meters_base/DecayLFDistance[i]); - WetGainLF[i] *= minf(gainlf / gain, 1.0f); - } - } - } - } - /* Calculate directional soundcones */ if(directional && props->InnerAngle < 360.0f) { @@ -1414,6 +1372,48 @@ static void CalcAttnSourceParams(ALvoice *voice, const struct ALvoiceProps *prop WetGainLF[i] *= props->Send[i].GainLF; } + /* Distance-based air absorption and initial send decay. */ + if(ClampedDist > props->RefDistance && props->RolloffFactor > 0.0f) + { + ALfloat meters_base = (ClampedDist-props->RefDistance) * props->RolloffFactor * + Listener->Params.MetersPerUnit; + if(props->AirAbsorptionFactor > 0.0f) + { + ALfloat hfattn = powf(AIRABSORBGAINHF, meters_base * props->AirAbsorptionFactor); + DryGainHF *= hfattn; + for(i = 0;i < NumSends;i++) + WetGainHF[i] *= hfattn; + } + + if(props->WetGainAuto) + { + /* Apply a decay-time transformation to the wet path, based on the + * source distance in meters. The initial decay of the reverb + * effect is calculated and applied to the wet path. + */ + for(i = 0;i < NumSends;i++) + { + ALfloat gain, gainhf, gainlf; + + if(!(DecayDistance[i] > 0.0f)) + continue; + + gain = powf(REVERB_DECAY_GAIN, meters_base/DecayDistance[i]); + WetGain[i] *= gain; + /* Yes, the wet path's air absorption is applied with + * WetGainAuto on, rather than WetGainHFAuto. + */ + if(gain > 0.0f) + { + gainhf = powf(REVERB_DECAY_GAIN, meters_base/DecayHFDistance[i]); + WetGainHF[i] *= minf(gainhf / gain, 1.0f); + gainlf = powf(REVERB_DECAY_GAIN, meters_base/DecayLFDistance[i]); + WetGainLF[i] *= minf(gainlf / gain, 1.0f); + } + } + } + } + /* Initial source pitch */ Pitch = props->Pitch; -- 2.11.4.GIT