From e893211b659a5dbaf75aa437ab594aac87984b85 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 30 May 2017 05:13:54 -0700 Subject: Restrict ClampedDist to RefDistance for invalid distance attenuation --- Alc/ALu.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'Alc/ALu.c') diff --git a/Alc/ALu.c b/Alc/ALu.c index d7a8a89b..11b3fd26 100644 --- a/Alc/ALu.c +++ b/Alc/ALu.c @@ -1195,7 +1195,9 @@ static void CalcAttnSourceParams(ALvoice *voice, const struct ALvoiceProps *prop break; /*fall-through*/ case InverseDistance: - if(props->RefDistance > 0.0f) + if(!(props->RefDistance > 0.0f)) + ClampedDist = props->RefDistance; + else { ALfloat dist = lerp(props->RefDistance, ClampedDist, props->RolloffFactor); if(dist > 0.0f) DryGain *= props->RefDistance / dist; @@ -1213,10 +1215,12 @@ static void CalcAttnSourceParams(ALvoice *voice, const struct ALvoiceProps *prop break; /*fall-through*/ case LinearDistance: - if(props->MaxDistance != props->RefDistance) + if(!(props->MaxDistance != props->RefDistance)) + ClampedDist = props->RefDistance; + else { ALfloat attn = props->RolloffFactor * (ClampedDist-props->RefDistance) / - (props->MaxDistance-props->RefDistance); + (props->MaxDistance-props->RefDistance); DryGain *= maxf(1.0f - attn, 0.0f); for(i = 0;i < NumSends;i++) { @@ -1233,7 +1237,9 @@ static void CalcAttnSourceParams(ALvoice *voice, const struct ALvoiceProps *prop break; /*fall-through*/ case ExponentDistance: - if(ClampedDist > 0.0f && props->RefDistance > 0.0f) + if(!(ClampedDist > 0.0f && props->RefDistance > 0.0f)) + ClampedDist = props->RefDistance; + else { DryGain *= powf(ClampedDist/props->RefDistance, -props->RolloffFactor); for(i = 0;i < NumSends;i++) -- cgit v1.2.3