From 328809f008a14c410f382e130f413b83ab7843b3 Mon Sep 17 00:00:00 2001 From: Ken Cooke Date: Wed, 16 Jan 2019 11:10:38 -0800 Subject: [PATCH] More robust approximation of distance attenuation at extreme settings. Fixes artifacts that occur when attenuation zone coef = 1.0 and distance > 32m. --- libraries/shared/src/AudioHelpers.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/shared/src/AudioHelpers.h b/libraries/shared/src/AudioHelpers.h index 1dcc11af0c..8f7f5f7f33 100644 --- a/libraries/shared/src/AudioHelpers.h +++ b/libraries/shared/src/AudioHelpers.h @@ -43,8 +43,9 @@ static inline float fastLog2f(float x) { } // -// for -127 <= x < 128, returns exp2(x) -// otherwise, returns undefined +// for -126 <= x < 128, returns exp2(x) +// for x < -126, returns 0 +// for x >= 128, returns undefined // // rel |error| < 9e-6, smooth (exact for x=N) // @@ -60,6 +61,7 @@ static inline float fastExp2f(float x) { x -= xi.i; // construct exp2(xi) as a float + xi.i &= ~(xi.i >> 31); // MAX(xi.i, 0) xi.i <<= IEEE754_MANT_BITS; // polynomial for exp2(x) over x=[0,1]