mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-13 22:27:13 +02:00
Use named constant for the onset of near-field corrections (1 meter)
This commit is contained in:
parent
f25b8e8df0
commit
bb2f3cac2c
4 changed files with 12 additions and 11 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
Loading…
Reference in a new issue