From 04b223a02095c58a014f548da227308f266223b0 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 6 May 2013 17:14:33 -0700 Subject: [PATCH] add off axis attenuation to audio-mixer --- audio-mixer/src/main.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index 362934568c..9e54b68c5a 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -60,6 +60,9 @@ const float DISTANCE_RATIO = 3.0f / 0.3f; const float PHASE_AMPLITUDE_RATIO_AT_90 = 0.5; const int PHASE_DELAY_AT_90 = 20; +const float MAX_OFF_AXIS_ATTENUATION = 0.5f; +const float OFF_AXIS_ATTENUATION_FORMULA_STEP = (1 - MAX_OFF_AXIS_ATTENUATION) / 2.0f; + void plateauAdditionOfSamples(int16_t &mixSample, int16_t sampleToAdd) { long sumSample = sampleToAdd + mixSample; @@ -168,8 +171,13 @@ void *sendBuffer(void *args) { bearingRelativeAngleToSource = absoluteAngleToSource - agentBearing; bearingRelativeAngleToSource *= (M_PI / 180); - float attenuationCoefficient = distanceCoefficients[lowAgentIndex][highAgentIndex] * - otherAgentBuffer->getAttenuationRatio(); + float angleOfDelivery = absoluteAngleToSource - otherAgentBuffer->getBearing(); + float offAxisCoefficient = MAX_OFF_AXIS_ATTENUATION + + (OFF_AXIS_ATTENUATION_FORMULA_STEP * (fabsf(angleOfDelivery) / 90.0f)); + + float attenuationCoefficient = distanceCoefficients[lowAgentIndex][highAgentIndex] + * otherAgentBuffer->getAttenuationRatio() + * offAxisCoefficient; float sinRatio = fabsf(sinf(bearingRelativeAngleToSource)); int numSamplesDelay = PHASE_DELAY_AT_90 * sinRatio;