From 59ac2a789ff9bd406bc20c4605754f64f9effe3c Mon Sep 17 00:00:00 2001 From: Ken Cooke Date: Fri, 15 Jul 2016 18:07:19 -0700 Subject: [PATCH 1/3] Fix the AudioMixer distance attenuation. The zone settings are still used, and still match the documentation where 0 = no attenuation and 1 = max attenuation. The default is now 0.5 which corresponds to -6dB per doubling of distance. This is the attenuation for a spherical wave in the free field. --- assignment-client/src/audio/AudioMixer.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/assignment-client/src/audio/AudioMixer.cpp b/assignment-client/src/audio/AudioMixer.cpp index 08e6e029a0..40e22f855a 100644 --- a/assignment-client/src/audio/AudioMixer.cpp +++ b/assignment-client/src/audio/AudioMixer.cpp @@ -62,7 +62,7 @@ #include "AudioMixer.h" 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 QString AUDIO_MIXER_LOGGING_TARGET_NAME = "audio-mixer"; const QString AUDIO_ENV_GROUP_KEY = "audio_env"; @@ -141,13 +141,14 @@ float AudioMixer::gainForSource(const PositionalAudioStream& streamToAdd, } 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) { - distanceCoefficient = 0; - } + // translate the zone setting to gain per log2(distance) + 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 gain *= distanceCoefficient; From 1ee608ad2cb13ce7f23374ea93f7f040a717d16b Mon Sep 17 00:00:00 2001 From: Ken Cooke Date: Fri, 15 Jul 2016 18:23:12 -0700 Subject: [PATCH 2/3] Cleanup --- libraries/audio-client/src/AudioClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/audio-client/src/AudioClient.cpp b/libraries/audio-client/src/AudioClient.cpp index 84d0146f3b..1ec2f40928 100644 --- a/libraries/audio-client/src/AudioClient.cpp +++ b/libraries/audio-client/src/AudioClient.cpp @@ -1309,7 +1309,7 @@ float AudioClient::gainForSource(float distance, float volume) { // attenuate based on 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; From b03686c37f53c8362595cb9b65fe75bc2890d4b9 Mon Sep 17 00:00:00 2001 From: Ken Cooke Date: Fri, 15 Jul 2016 22:02:56 -0700 Subject: [PATCH 3/3] Change the default domain attenuation level to 0.5 --- domain-server/resources/describe-settings.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/domain-server/resources/describe-settings.json b/domain-server/resources/describe-settings.json index 948c6ddc18..e1334ee46f 100644 --- a/domain-server/resources/describe-settings.json +++ b/domain-server/resources/describe-settings.json @@ -589,8 +589,8 @@ "name": "attenuation_per_doubling_in_distance", "label": "Default Domain Attenuation", "help": "Factor between 0 and 1.0 (0: No attenuation, 1.0: extreme attenuation)", - "placeholder": "0.18", - "default": "0.18", + "placeholder": "0.5", + "default": "0.5", "advanced": false }, { @@ -686,7 +686,7 @@ "name": "coefficient", "label": "Attenuation coefficient", "can_set": true, - "placeholder": "0.18" + "placeholder": "0.5" } ] },