From 1c6fa5235745f699cb6469f7e67e62ec9c3f3787 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 1 Mar 2013 15:34:49 -0800 Subject: [PATCH] Revert "Revert "test of a low pass filter in non-FFT space"" This reverts commit 2bbeca1e01446253f91b707bc599c4d73b7638c7. --- mixer/src/main.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/mixer/src/main.cpp b/mixer/src/main.cpp index 2fb94ab71c..185eb0305b 100644 --- a/mixer/src/main.cpp +++ b/mixer/src/main.cpp @@ -37,12 +37,20 @@ const long MIN_SAMPLE_VALUE = std::numeric_limits::min(); const float DISTANCE_RATIO = 3.0/4.2; const int PHASE_DELAY_AT_90 = 20; +const float BEARING_LOW_PASS_FACTOR = 0.1; +const float ANGLE_TO_SOURCE_LOW_PASS_FACTOR = 0.4; + char DOMAIN_HOSTNAME[] = "highfidelity.below92.com"; char DOMAIN_IP[100] = ""; // IP Address will be re-set by lookup on startup const int DOMAINSERVER_PORT = 40102; AgentList agentList(MIXER_LISTEN_PORT); +int16_t lowPassSampleCenteredAtPointer(int16_t *samplePointer) { + return (0.0625 * *(samplePointer - 3)) + (0.125 * *(samplePointer - 2)) + (0.1875 * *(samplePointer - 1)) + (0.25 * *samplePointer) + + (0.1875 * *(samplePointer + 1)) + (0.125 * *(samplePointer + 2)) + (0.0625 * *(samplePointer + 3)); +} + void *sendBuffer(void *args) { int sentBytes; @@ -134,8 +142,13 @@ void *sendBuffer(void *args) ? otherAgentBuffer->getBuffer() + RING_BUFFER_SAMPLES - numSamplesDelay : otherAgentBuffer->getNextOutput() - numSamplesDelay; + int16_t *lowPassFrame = new int16_t[(BUFFER_LENGTH_SAMPLES_PER_CHANNEL * 2) / 4]; + // calculate the low-pass filter intensity + float lowPassIntensity = ((agentBearing - otherAgentBuffer->getBearing()) * BEARING_LOW_PASS_FACTOR) + + (fabsf(angleToSource) * ANGLE_TO_SOURCE_LOW_PASS_FACTOR); + for (int s = 0; s < BUFFER_LENGTH_SAMPLES_PER_CHANNEL; s++) { - + if (s < numSamplesDelay) { // pull the earlier sample for the delayed channel @@ -149,6 +162,15 @@ void *sendBuffer(void *args) if (s + numSamplesDelay < BUFFER_LENGTH_SAMPLES_PER_CHANNEL) { delayedChannel[s + numSamplesDelay] = currentSample; } + + if ((s + 1) % 4 == 0) { + int sampleIndex = ((s + 1) / 4) - 1; + // this will be a sample in the lowPassFrame + lowPassFrame[sampleIndex] = lowPassSampleCenteredAtPointer(clientMix + s); + lowPassFrame[sampleIndex + (BUFFER_LENGTH_SAMPLES_PER_CHANNEL / 4)] = lowPassSampleCenteredAtPointer(clientMix + s + BUFFER_LENGTH_SAMPLES_PER_CHANNEL); + } + + clientMix[s] = lowPassFrame[s / 4]; } } }