mirror of
https://github.com/overte-org/overte.git
synced 2025-04-15 06:08:22 +02:00
Clamp near-field distance attenuation to max gain
This commit is contained in:
parent
5148b60c73
commit
53dece5451
3 changed files with 4 additions and 0 deletions
|
@ -730,6 +730,7 @@ float approximateGain(const AvatarAudioStream& listeningNodeStream, const Positi
|
||||||
|
|
||||||
float d = (1.0f / ATTN_DISTANCE_REF) * std::max(distance, HRTF_NEARFIELD_MIN);
|
float d = (1.0f / ATTN_DISTANCE_REF) * std::max(distance, HRTF_NEARFIELD_MIN);
|
||||||
gain = gain / d;
|
gain = gain / d;
|
||||||
|
gain = std::min(gain, ATTN_GAIN_MAX);
|
||||||
|
|
||||||
// avatar: skip master gain - it is constant for all streams
|
// avatar: skip master gain - it is constant for all streams
|
||||||
return gain;
|
return gain;
|
||||||
|
@ -780,6 +781,7 @@ float computeGain(float masterListenerGain, const AvatarAudioStream& listeningNo
|
||||||
// reference attenuation of 0dB at distance = ATTN_DISTANCE_REF
|
// reference attenuation of 0dB at distance = ATTN_DISTANCE_REF
|
||||||
float d = (1.0f / ATTN_DISTANCE_REF) * std::max(distance, HRTF_NEARFIELD_MIN);
|
float d = (1.0f / ATTN_DISTANCE_REF) * std::max(distance, HRTF_NEARFIELD_MIN);
|
||||||
gain *= fastExp2f(fastLog2f(g) * fastLog2f(d));
|
gain *= fastExp2f(fastLog2f(g) * fastLog2f(d));
|
||||||
|
gain = std::min(gain, ATTN_GAIN_MAX);
|
||||||
|
|
||||||
return gain;
|
return gain;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1955,6 +1955,7 @@ float AudioClient::gainForSource(float distance, float volume) {
|
||||||
// reference attenuation of 0dB at distance = ATTN_DISTANCE_REF
|
// reference attenuation of 0dB at distance = ATTN_DISTANCE_REF
|
||||||
float d = (1.0f / ATTN_DISTANCE_REF) * std::max(distance, HRTF_NEARFIELD_MIN);
|
float d = (1.0f / ATTN_DISTANCE_REF) * std::max(distance, HRTF_NEARFIELD_MIN);
|
||||||
float gain = volume / d;
|
float gain = volume / d;
|
||||||
|
gain = std::min(gain, ATTN_GAIN_MAX);
|
||||||
|
|
||||||
return gain;
|
return gain;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ static const float HRTF_HEAD_RADIUS = 0.0875f; // average human head in meters
|
||||||
|
|
||||||
// Distance attenuation
|
// Distance attenuation
|
||||||
static const float ATTN_DISTANCE_REF = 1.0f; // distance where attn is 0dB
|
static const float ATTN_DISTANCE_REF = 1.0f; // distance where attn is 0dB
|
||||||
|
static const float ATTN_GAIN_MAX = 8.0f; // max gain allowed by distance attn (+18dB)
|
||||||
|
|
||||||
class AudioHRTF {
|
class AudioHRTF {
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue