From 04e7df1a3fa6c5705c9f2afae1b9dd58b111b1cf Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 3 Jul 2014 13:46:38 -0700 Subject: [PATCH] change the audio rolloff function --- assignment-client/src/audio/AudioMixer.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/assignment-client/src/audio/AudioMixer.cpp b/assignment-client/src/audio/AudioMixer.cpp index 64cba7dd21..cb790ca7ac 100644 --- a/assignment-client/src/audio/AudioMixer.cpp +++ b/assignment-client/src/audio/AudioMixer.cpp @@ -166,12 +166,18 @@ void AudioMixer::addBufferToMixForListeningNodeWithBuffer(PositionalAudioRingBuf glm::vec3 rotatedSourcePosition = inverseOrientation * relativePosition; - // calculate the distance coefficient using the distance to this node - 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; + if (distanceBetween >= ATTENUATION_BEGINS_AT_DISTANCE) { + // calculate the distance coefficient using the distance to this node + float distanceCoefficient = 1 - (logf(distanceBetween / ATTENUATION_BEGINS_AT_DISTANCE) / logf(2.0f) + * ATTENUATION_AMOUNT_PER_DOUBLING_IN_DISTANCE); + + if (distanceCoefficient < 0) { + distanceCoefficient = 0; + } + + // multiply the current attenuation coefficient by the distance coefficient + attenuationCoefficient *= distanceCoefficient; + } // project the rotated source position vector onto the XZ plane rotatedSourcePosition.y = 0.0f;