mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 04:57:58 +02:00
Merge pull request #8259 from kencooke/improved-hrtf
Fix the AudioMixer distance attenuation.
This commit is contained in:
commit
dc2741950a
3 changed files with 12 additions and 11 deletions
|
@ -62,7 +62,7 @@
|
||||||
#include "AudioMixer.h"
|
#include "AudioMixer.h"
|
||||||
|
|
||||||
const float LOUDNESS_TO_DISTANCE_RATIO = 0.00001f;
|
const float LOUDNESS_TO_DISTANCE_RATIO = 0.00001f;
|
||||||
const float DEFAULT_ATTENUATION_PER_DOUBLING_IN_DISTANCE = 0.18f;
|
const float DEFAULT_ATTENUATION_PER_DOUBLING_IN_DISTANCE = 0.5f; // attenuation = -6dB * log2(distance)
|
||||||
const float DEFAULT_NOISE_MUTING_THRESHOLD = 0.003f;
|
const float DEFAULT_NOISE_MUTING_THRESHOLD = 0.003f;
|
||||||
const QString AUDIO_MIXER_LOGGING_TARGET_NAME = "audio-mixer";
|
const QString AUDIO_MIXER_LOGGING_TARGET_NAME = "audio-mixer";
|
||||||
const QString AUDIO_ENV_GROUP_KEY = "audio_env";
|
const QString AUDIO_ENV_GROUP_KEY = "audio_env";
|
||||||
|
@ -141,13 +141,14 @@ float AudioMixer::gainForSource(const PositionalAudioStream& streamToAdd,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (distanceBetween >= ATTENUATION_BEGINS_AT_DISTANCE) {
|
if (distanceBetween >= ATTENUATION_BEGINS_AT_DISTANCE) {
|
||||||
// calculate the distance coefficient using the distance to this node
|
|
||||||
float distanceCoefficient = 1.0f - (logf(distanceBetween / ATTENUATION_BEGINS_AT_DISTANCE) / logf(2.0f)
|
|
||||||
* attenuationPerDoublingInDistance);
|
|
||||||
|
|
||||||
if (distanceCoefficient < 0) {
|
// translate the zone setting to gain per log2(distance)
|
||||||
distanceCoefficient = 0;
|
float g = 1.0f - attenuationPerDoublingInDistance;
|
||||||
}
|
g = (g < EPSILON) ? EPSILON : g;
|
||||||
|
g = (g > 1.0f) ? 1.0f : g;
|
||||||
|
|
||||||
|
// calculate the distance coefficient using the distance to this node
|
||||||
|
float distanceCoefficient = exp2f(log2f(g) * log2f(distanceBetween/ATTENUATION_BEGINS_AT_DISTANCE));
|
||||||
|
|
||||||
// multiply the current attenuation coefficient by the distance coefficient
|
// multiply the current attenuation coefficient by the distance coefficient
|
||||||
gain *= distanceCoefficient;
|
gain *= distanceCoefficient;
|
||||||
|
|
|
@ -589,8 +589,8 @@
|
||||||
"name": "attenuation_per_doubling_in_distance",
|
"name": "attenuation_per_doubling_in_distance",
|
||||||
"label": "Default Domain Attenuation",
|
"label": "Default Domain Attenuation",
|
||||||
"help": "Factor between 0 and 1.0 (0: No attenuation, 1.0: extreme attenuation)",
|
"help": "Factor between 0 and 1.0 (0: No attenuation, 1.0: extreme attenuation)",
|
||||||
"placeholder": "0.18",
|
"placeholder": "0.5",
|
||||||
"default": "0.18",
|
"default": "0.5",
|
||||||
"advanced": false
|
"advanced": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -686,7 +686,7 @@
|
||||||
"name": "coefficient",
|
"name": "coefficient",
|
||||||
"label": "Attenuation coefficient",
|
"label": "Attenuation coefficient",
|
||||||
"can_set": true,
|
"can_set": true,
|
||||||
"placeholder": "0.18"
|
"placeholder": "0.5"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
|
@ -1308,7 +1308,7 @@ float AudioClient::gainForSource(float distance, float volume) {
|
||||||
|
|
||||||
// attenuate based on distance
|
// attenuate based on distance
|
||||||
if (distance >= ATTENUATION_BEGINS_AT_DISTANCE) {
|
if (distance >= ATTENUATION_BEGINS_AT_DISTANCE) {
|
||||||
gain /= distance; // attenuation = -6dB * log2(distance)
|
gain /= (distance/ATTENUATION_BEGINS_AT_DISTANCE); // attenuation = -6dB * log2(distance)
|
||||||
}
|
}
|
||||||
|
|
||||||
return gain;
|
return gain;
|
||||||
|
|
Loading…
Reference in a new issue