From fe52787572002ba9e4e178da994f36bcf695486c Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 3 Jul 2014 11:05:12 -0700 Subject: [PATCH] implement a new rolloff function --- assignment-client/src/audio/AudioMixer.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/assignment-client/src/audio/AudioMixer.cpp b/assignment-client/src/audio/AudioMixer.cpp index 1c3046b9b1..59c5d15582 100644 --- a/assignment-client/src/audio/AudioMixer.cpp +++ b/assignment-client/src/audio/AudioMixer.cpp @@ -89,6 +89,9 @@ AudioMixer::~AudioMixer() { delete _listenerUnattenuatedZone; } +const float ATTENUATION_BEGINS_AT_DISTANCE = 1.0f; +const float ATTENUATION_AMOUNT_PER_DOUBLING_IN_DISTANCE = 0.18f; + void AudioMixer::addBufferToMixForListeningNodeWithBuffer(PositionalAudioRingBuffer* bufferToAdd, AvatarAudioRingBuffer* listeningNodeBuffer) { float bearingRelativeAngleToSource = 0.0f; @@ -162,16 +165,9 @@ void AudioMixer::addBufferToMixForListeningNodeWithBuffer(PositionalAudioRingBuf glm::vec3 rotatedSourcePosition = inverseOrientation * relativePosition; - const float DISTANCE_SCALE = 2.5f; - const float GEOMETRIC_AMPLITUDE_SCALAR = 0.3f; - const float DISTANCE_LOG_BASE = 2.5f; - const float DISTANCE_SCALE_LOG = logf(DISTANCE_SCALE) / logf(DISTANCE_LOG_BASE); - // calculate the distance coefficient using the distance to this node - float distanceCoefficient = powf(GEOMETRIC_AMPLITUDE_SCALAR, - DISTANCE_SCALE_LOG + - (0.5f * logf(distanceSquareToSource) / logf(DISTANCE_LOG_BASE)) - 1); - distanceCoefficient = std::min(1.0f, distanceCoefficient); + float distanceCoefficient = 1 - (logf(distanceBetween / ATTENUATION_BEGINS_AT_DISTANCE) / logf(2.0f) + * ATTENUATION_AMOUNT_PER_DOUBLING_IN_DISTANCE); // multiply the current attenuation coefficient by the distance coefficient attenuationCoefficient *= distanceCoefficient;