mirror of
https://github.com/lubosz/overte.git
synced 2025-04-08 15:43:24 +02:00
Parameterize distance attenuation by reference distance (where gain = unity)
This commit is contained in:
parent
833ad936c0
commit
5148b60c73
3 changed files with 13 additions and 6 deletions
|
@ -727,9 +727,12 @@ float approximateGain(const AvatarAudioStream& listeningNodeStream, const Positi
|
|||
// distance attenuation: approximate, ignore zone-specific attenuations
|
||||
glm::vec3 relativePosition = streamToAdd.getPosition() - listeningNodeStream.getPosition();
|
||||
float distance = glm::length(relativePosition);
|
||||
return gain / distance;
|
||||
|
||||
float d = (1.0f / ATTN_DISTANCE_REF) * std::max(distance, HRTF_NEARFIELD_MIN);
|
||||
gain = gain / d;
|
||||
|
||||
// avatar: skip master gain - it is constant for all streams
|
||||
return gain;
|
||||
}
|
||||
|
||||
float computeGain(float masterListenerGain, const AvatarAudioStream& listeningNodeStream,
|
||||
|
@ -774,9 +777,9 @@ float computeGain(float masterListenerGain, const AvatarAudioStream& listeningNo
|
|||
float g = glm::clamp(1.0f - attenuationPerDoublingInDistance, EPSILON, 1.0f);
|
||||
|
||||
// calculate the attenuation using the distance to this node
|
||||
// reference attenuation of 0dB at distance = 1.0m
|
||||
gain *= fastExp2f(fastLog2f(g) * fastLog2f(std::max(distance, HRTF_NEARFIELD_MIN)));
|
||||
gain = std::min(gain, 1.0f / HRTF_NEARFIELD_MIN);
|
||||
// reference attenuation of 0dB at distance = ATTN_DISTANCE_REF
|
||||
float d = (1.0f / ATTN_DISTANCE_REF) * std::max(distance, HRTF_NEARFIELD_MIN);
|
||||
gain *= fastExp2f(fastLog2f(g) * fastLog2f(d));
|
||||
|
||||
return gain;
|
||||
}
|
||||
|
|
|
@ -1952,8 +1952,9 @@ float AudioClient::azimuthForSource(const glm::vec3& relativePosition) {
|
|||
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_NEARFIELD_MIN);
|
||||
// reference attenuation of 0dB at distance = ATTN_DISTANCE_REF
|
||||
float d = (1.0f / ATTN_DISTANCE_REF) * std::max(distance, HRTF_NEARFIELD_MIN);
|
||||
float gain = volume / d;
|
||||
|
||||
return gain;
|
||||
}
|
||||
|
|
|
@ -30,6 +30,9 @@ 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
|
||||
|
||||
// Distance attenuation
|
||||
static const float ATTN_DISTANCE_REF = 1.0f; // distance where attn is 0dB
|
||||
|
||||
class AudioHRTF {
|
||||
|
||||
public:
|
||||
|
|
Loading…
Reference in a new issue