From 0ea6e47f2082f0130aef7a78f871e2215cf8fd13 Mon Sep 17 00:00:00 2001 From: Caleb Kemere <ckemere@gmail.com> Date: Sat, 30 Nov 2013 22:05:29 -0600 Subject: [PATCH] Noise gate implemented. Scaling is still suspect, but sounds reasonable with sample data. --- Source/Processors/AudioNode.cpp | 23 ++++++++++++++--------- Source/Processors/AudioNode.h | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Source/Processors/AudioNode.cpp b/Source/Processors/AudioNode.cpp index cf5b9ae43..df989f10e 100755 --- a/Source/Processors/AudioNode.cpp +++ b/Source/Processors/AudioNode.cpp @@ -140,8 +140,7 @@ void AudioNode::setParameter(int parameterIndex, float newValue) else if (parameterIndex == 2) { // noiseGateLevel level - noiseGateLevel = newValue*0.01f; // not sure about this scaling??? - std::cout << "Changed noiseGateLevel: " << noiseGateLevel << std::endl; + noiseGateLevel = newValue; // in microVolts } else if (parameterIndex == 100) @@ -294,6 +293,10 @@ void AudioNode::process(AudioSampleBuffer& buffer, } // copying buffer gain = volume/(float(0x7fff) * channelPointers[i-2]->bitVolts); + // - Maximum of "volume" is 10 (100 * 0.1) + // - float(0x7fff) is the maximum value that comes out of the preamp (15 bits of 1's) + // - bitVolts is the number of microvolts per bit - why are we dividing by this??? + // So, maximum gain applied to maximum data would be 10/bitVolts int remainingSamples = numSamplesExpected - samplesToCopy; @@ -353,15 +356,17 @@ void AudioNode::process(AudioSampleBuffer& buffer, } - // HERE IS WHERE WE NEED TO NOISE GATE + // Simple implementation of a "noise gate" on audio output float *leftChannelData = buffer.getSampleData(0); float *rightChannelData = buffer.getSampleData(1); - float gateLevel = noiseGateLevel/(float(0x7fff)); - for (int i=0; i < buffer.getNumSamples(); i++) { - if (abs(leftChannelData[i]) < gateLevel) - leftChannelData[i] = 0; - if (abs(rightChannelData[i]) < gateLevel) - rightChannelData[i] = 0; + // float gateLevel = (noiseGateLevel / channelPointers[i-2]->bitVolts) * gain; // uVolts scaled by gain + float gateLevel = noiseGateLevel * gain; // bits scaled by gain + + for (int m=0; m < buffer.getNumSamples(); m++) { + if (fabs(leftChannelData[m]) < gateLevel) + leftChannelData[m] = 0; + if (fabs(rightChannelData[m]) < gateLevel) + rightChannelData[m] = 0; } } } diff --git a/Source/Processors/AudioNode.h b/Source/Processors/AudioNode.h index 8a7d20b2c..8ebc5296d 100755 --- a/Source/Processors/AudioNode.h +++ b/Source/Processors/AudioNode.h @@ -103,7 +103,7 @@ private: Array<int> leftChan; Array<int> rightChan; float volume; - float noiseGateLevel; + float noiseGateLevel; // in microvolts /** An array of pointers to the channels that feed into the AudioNode. */ Array<Channel*> channelPointers; -- GitLab