diff --git a/assignment-client/src/audio/AudioMixerSlave.cpp b/assignment-client/src/audio/AudioMixerSlave.cpp index e5ad9a681a..04b818adee 100644 --- a/assignment-client/src/audio/AudioMixerSlave.cpp +++ b/assignment-client/src/audio/AudioMixerSlave.cpp @@ -540,8 +540,8 @@ float computeGain(const AudioMixerClientData& listenerNodeData, const AvatarAudi // calculate the attenuation using the distance to this node // reference attenuation of 0dB at distance = 1.0m - gain *= exp2f(log2f(g) * log2f(std::max(distance, HRTF_DISTANCE_MIN))); - gain = std::min(gain, 1.0f / HRTF_DISTANCE_MIN); + gain *= exp2f(log2f(g) * log2f(std::max(distance, HRTF_NEARFIELD_MIN))); + gain = std::min(gain, 1.0f / HRTF_NEARFIELD_MIN); return gain; } diff --git a/libraries/audio-client/src/AudioClient.cpp b/libraries/audio-client/src/AudioClient.cpp index 40a55c272c..8379151d1c 100644 --- a/libraries/audio-client/src/AudioClient.cpp +++ b/libraries/audio-client/src/AudioClient.cpp @@ -1826,7 +1826,7 @@ float AudioClient::gainForSource(float distance, float volume) { // attenuation = -6dB * log2(distance) // reference attenuation of 0dB at distance = 1.0m - float gain = volume / std::max(distance, HRTF_DISTANCE_MIN); + float gain = volume / std::max(distance, HRTF_NEARFIELD_MIN); return gain; } diff --git a/libraries/audio/src/AudioHRTF.cpp b/libraries/audio/src/AudioHRTF.cpp index 8ccb79b2a5..a6451b1771 100644 --- a/libraries/audio/src/AudioHRTF.cpp +++ b/libraries/audio/src/AudioHRTF.cpp @@ -790,10 +790,10 @@ static void nearFieldAzimuth(float azimuth, float distance, float& azimuthL, flo // static void nearFieldGain(float azimuth, float distance, float& gainL, float& gainR) { - // normalized distance factor = [0,1] as distance = [1,HRTF_HEAD_RADIUS] - assert(distance < 1.0f); + // normalized distance factor = [0,1] as distance = [HRTF_NEARFIELD_MAX,HRTF_HEAD_RADIUS] + assert(distance < HRTF_NEARFIELD_MAX); assert(distance > HRTF_HEAD_RADIUS); - float d = (1.0f - distance) * ( 1.0f / (1.0f - HRTF_HEAD_RADIUS)); + float d = (HRTF_NEARFIELD_MAX - distance) * ( 1.0f / (HRTF_NEARFIELD_MAX - HRTF_HEAD_RADIUS)); // angle of incidence at each ear float angleL = azimuth + HALFPI; @@ -816,7 +816,7 @@ static void nearFieldGain(float azimuth, float distance, float& gainL, float& ga float cR = ((-0.000452339132f * angleR - 0.00173192444f) * angleR + 0.162476536f) * angleR; // approximate the gain correction - // NOTE: this must converge to 1.0 when distance = 1.0m at all azimuth + // NOTE: this must converge to 1.0 when distance = HRTF_NEARFIELD_MAX at all azimuth gainL = 1.0f - d * cL; gainR = 1.0f - d * cR; } @@ -891,7 +891,7 @@ static void setFilters(float firCoef[4][HRTF_TAPS], float bqCoef[5][8], int dela assert(azimuth >= -PI); assert(azimuth <= +PI); - distance = MAX(distance, HRTF_DISTANCE_MIN); + distance = MAX(distance, HRTF_NEARFIELD_MIN); // compute the azimuth correction at each ear float azimuthL, azimuthR; @@ -900,7 +900,7 @@ static void setFilters(float firCoef[4][HRTF_TAPS], float bqCoef[5][8], int dela // compute the DC gain correction at each ear float gainL = 1.0f; float gainR = 1.0f; - if (distance < 1.0f) { + if (distance < HRTF_NEARFIELD_MAX) { nearFieldGain(azimuth, distance, gainL, gainR); } diff --git a/libraries/audio/src/AudioHRTF.h b/libraries/audio/src/AudioHRTF.h index b8422b7c73..f0f4dd849b 100644 --- a/libraries/audio/src/AudioHRTF.h +++ b/libraries/audio/src/AudioHRTF.h @@ -24,8 +24,9 @@ static const int HRTF_BLOCK = 240; // block processing size static const float HRTF_GAIN = 1.0f; // HRTF global gain adjustment // Near-field HRTF -static const float HRTF_DISTANCE_MIN = 0.125f; -static const float HRTF_HEAD_RADIUS = 0.0875f; // average human head +static const float HRTF_NEARFIELD_MAX = 1.0f; // distance in meters +static const float HRTF_NEARFIELD_MIN = 0.125f; // distance in meters +static const float HRTF_HEAD_RADIUS = 0.0875f; // average human head in meters class AudioHRTF {