diff --git a/Source/Processors/AudioNode.cpp b/Source/Processors/AudioNode.cpp index 988381f324acf9165f3ad3cd8f430337dbf07af3..26857855df4e1def03f4620e3c0dff7670e826dd 100755 --- a/Source/Processors/AudioNode.cpp +++ b/Source/Processors/AudioNode.cpp @@ -26,7 +26,7 @@ #include "Channel.h" AudioNode::AudioNode() - : GenericProcessor("Audio Node"), audioEditor(0), volume(0.00001f), + : GenericProcessor("Audio Node"), audioEditor(0), volume(0.00001f), noiseGateLevel(0.0f), bufferA(2,10000), bufferB(2,10000) { @@ -136,6 +136,12 @@ void AudioNode::setParameter(int parameterIndex, float newValue) // volume level volume = newValue*0.1f; + } + else if (parameterIndex == 2) + { + // noiseGateLevel level + noiseGateLevel = newValue; // in microVolts + } else if (parameterIndex == 100) { @@ -287,6 +293,8 @@ void AudioNode::process(AudioSampleBuffer& buffer, } // copying buffer gain = volume/(float(0x7fff) * channelPointers[i-2]->bitVolts); + // Data are floats in units of microvolts, so dividing by bitVolts and 0x7fff (max value for 16b signed) + // rescales to between -1 and +1. Audio output starts So, maximum gain applied to maximum data would be 10. int remainingSamples = numSamplesExpected - samplesToCopy; @@ -316,6 +324,7 @@ void AudioNode::process(AudioSampleBuffer& buffer, remainingSamples, // number of samples gain // gain to apply ); + } orphanedSamples = nSamples - samplesToCopy2; @@ -334,7 +343,7 @@ void AudioNode::process(AudioSampleBuffer& buffer, gain // gain to apply ); - backupBuffer->addFrom(0, // destination channel + backupBuffer->addFrom(0, // destination channel samplesInBackupBuffer, // destination start sample buffer, // source i, // source channel @@ -344,7 +353,18 @@ void AudioNode::process(AudioSampleBuffer& buffer, ); } - + + // Simple implementation of a "noise gate" on audio output + float *leftChannelData = buffer.getSampleData(0); + float *rightChannelData = buffer.getSampleData(1); + float gateLevel = noiseGateLevel * gain; // uVolts 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 e0f6a901aa57692583a8023ef7d5c4b9b05158f1..8ebc5296d02e893ff940706da009b745fb5ea4b3 100755 --- a/Source/Processors/AudioNode.h +++ b/Source/Processors/AudioNode.h @@ -103,6 +103,7 @@ private: Array<int> leftChan; Array<int> rightChan; float volume; + float noiseGateLevel; // in microvolts /** An array of pointers to the channels that feed into the AudioNode. */ Array<Channel*> channelPointers; diff --git a/Source/Processors/Editors/AudioEditor.cpp b/Source/Processors/Editors/AudioEditor.cpp index 054ddbcb530fae009c6bb6f2fd126385f13690ed..c66463b34626dfa325df1efeb166c53a96e065a0 100755 --- a/Source/Processors/Editors/AudioEditor.cpp +++ b/Source/Processors/Editors/AudioEditor.cpp @@ -98,13 +98,21 @@ AudioEditor::AudioEditor(AudioNode* owner) // addAndMakeVisible(audioWindowButton); - volumeSlider = new Slider("High-Cut Slider"); + volumeSlider = new Slider("Volume Slider"); volumeSlider->setRange(0,100,1); volumeSlider->addListener(this); volumeSlider->setTextBoxStyle(Slider::NoTextBox, false, 0, 0); addAndMakeVisible(volumeSlider); + noiseGateSlider = new Slider("Noise Gate Slider"); + noiseGateSlider->setRange(0,100,1); + noiseGateSlider->addListener(this); + noiseGateSlider->setTextBoxStyle(Slider::NoTextBox, + false, 0, 0); + addAndMakeVisible(noiseGateSlider); + + //acw = new AudioConfigurationWindow(getAudioComponent()->deviceManager, (Button*) audioWindowButton); } @@ -119,7 +127,8 @@ void AudioEditor::resized() { muteButton->setBounds(0,0,30,25); volumeSlider->setBounds(35,0,50,getHeight()); - audioWindowButton->setBounds(90,0,200,getHeight()); + noiseGateSlider->setBounds(85,0,50,getHeight()); + audioWindowButton->setBounds(140,0,200,getHeight()); } bool AudioEditor::keyPressed(const KeyPress& key) @@ -208,7 +217,10 @@ void AudioEditor::buttonClicked(Button* button) void AudioEditor::sliderValueChanged(Slider* slider) { - getAudioProcessor()->setParameter(1,slider->getValue()); + if (slider == volumeSlider) + getAudioProcessor()->setParameter(1,slider->getValue()); + else if (slider == noiseGateSlider) + getAudioProcessor()->setParameter(2,slider->getValue()); } void AudioEditor::paint(Graphics& g) diff --git a/Source/Processors/Editors/AudioEditor.h b/Source/Processors/Editors/AudioEditor.h index 7120d4b250201529b7fd2694a8354a8e4af47200..6891cce8fccf582bd688571822d7fdab7567d17b 100755 --- a/Source/Processors/Editors/AudioEditor.h +++ b/Source/Processors/Editors/AudioEditor.h @@ -131,7 +131,8 @@ private: AudioConfigurationWindow* acw; Slider* volumeSlider; - + Slider* noiseGateSlider; + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(AudioEditor); };