Skip to content
Snippets Groups Projects
Commit c2ebe39f authored by jsiegle's avatar jsiegle
Browse files

Finally! The noise gate does what it's supposed to

parent 971ca63c
No related branches found
No related tags found
No related merge requests found
...@@ -142,7 +142,7 @@ void AudioNode::setParameter(int parameterIndex, float newValue) ...@@ -142,7 +142,7 @@ void AudioNode::setParameter(int parameterIndex, float newValue)
{ {
// noiseGateLevel level // noiseGateLevel level
Expander.setThreshold(newValue); // in microVolts expander.setThreshold(newValue); // in microVolts
} }
else if (parameterIndex == 100) else if (parameterIndex == 100)
...@@ -359,9 +359,7 @@ void AudioNode::process(AudioSampleBuffer& buffer, ...@@ -359,9 +359,7 @@ void AudioNode::process(AudioSampleBuffer& buffer,
} }
// Simple implementation of a "noise gate" on audio output // Simple implementation of a "noise gate" on audio output
// Modified from http://musicdsp.org/archive.php?classid=1#272: expander.process(buffer.getWritePointer(0), // left channel
Expander.process(buffer.getWritePointer(0), // left channel
buffer.getWritePointer(1), // right channel buffer.getWritePointer(1), // right channel
buffer.getNumSamples()); buffer.getNumSamples());
...@@ -381,14 +379,14 @@ void AudioNode::process(AudioSampleBuffer& buffer, ...@@ -381,14 +379,14 @@ void AudioNode::process(AudioSampleBuffer& buffer,
Expander::Expander() Expander::Expander()
{ {
threshold = 1.f; threshold = 1.f;
attack = release = envelope_decay = 0.f;
output = 1.f; output = 1.f;
transfer_A = 0.f;
transfer_B = 1.f;
env = 0.f; env = 0.f;
gain = 1.f; gain = 1.f;
setAttack(1.0f);
setRelease(1.0f);
setRatio(1.2); // ratio > 1.0 will decrease gain below threshold
} }
void Expander::setThreshold(float value) void Expander::setThreshold(float value)
...@@ -432,13 +430,13 @@ void Expander::process(float* leftChan, float* rightChan, int numSamples) ...@@ -432,13 +430,13 @@ void Expander::process(float* leftChan, float* rightChan, int numSamples)
env = det >= env ? det : det + envelope_decay*(env-det); env = det >= env ? det : det + envelope_decay*(env-det);
transfer_gain = env > threshold ? pow(env, transfer_A) * transfer_B : output; transfer_gain = env < threshold ? pow(env, transfer_A) * transfer_B : output;
gain = transfer_gain < gain ? gain = transfer_gain < gain ?
transfer_gain + attack * (gain - transfer_gain) : transfer_gain + attack * (gain - transfer_gain) :
transfer_gain + release * (gain - transfer_gain); transfer_gain + release * (gain - transfer_gain);
leftChan[i] = leftChan[i] * gain; leftChan[i] = leftChan[i] * gain;
rightChan[i] = rightChan[i] * gain; rightChan[i] = rightChan[i] * gain;
} }
} }
\ No newline at end of file
...@@ -139,7 +139,7 @@ private: ...@@ -139,7 +139,7 @@ private:
bool bufferSwap; bool bufferSwap;
Compressor compressor; Expander expander;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(AudioNode); JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(AudioNode);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment