Skip to content

Commit

Permalink
added input gain slider
Browse files Browse the repository at this point in the history
  • Loading branch information
greyboxaudio committed Nov 28, 2022
1 parent 4d7b667 commit 6a5cc66
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
# `project()` command. `project()` sets up some helpful variables that describe source/binary
# directories, and the current project version. This is a standard CMake command.

project(SG323 VERSION 0.3.2)
project(SG323 VERSION 0.4.0)

# If you've installed JUCE somehow (via a package manager, or directly using the CMake install
# target), you'll need to tell this project that it depends on the installed copy of JUCE. If you've
Expand Down
63 changes: 39 additions & 24 deletions Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,35 @@
SG323AudioProcessorEditor::SG323AudioProcessorEditor(SG323AudioProcessor& p)
: AudioProcessorEditor(&p), audioProcessor(p)
{
inputGainSlider.setSliderStyle(juce::Slider::SliderStyle::LinearBarVertical);
inputGainSlider.setTextBoxIsEditable(false);
addAndMakeVisible(inputGainSlider);
inputGainSliderAttachment = std::make_unique<juce::AudioProcessorValueTreeState::SliderAttachment>(audioProcessor.apvts, "INPUT", inputGainSlider);
addAndMakeVisible(inputGainLabel);
inputGainLabel.setText("INPUT", juce::dontSendNotification);
inputGainLabel.attachToComponent(&inputGainSlider, false);
inputGainLabel.setJustificationType(juce::Justification::centred);

highPassSlider.setSliderStyle(juce::Slider::SliderStyle::LinearBarVertical);
highPassSlider.setTextBoxIsEditable(false);
addAndMakeVisible(highPassSlider);
highPassSliderAttachment = std::make_unique<juce::AudioProcessorValueTreeState::SliderAttachment>(audioProcessor.apvts, "HPF", highPassSlider);
addAndMakeVisible(highPassLabel);
highPassLabel.setText("HPF", juce::dontSendNotification);
highPassLabel.attachToComponent(&highPassSlider, false);
highPassLabel.setJustificationType(juce::Justification::centred);

lowPassSlider.setSliderStyle(juce::Slider::SliderStyle::LinearBarVertical);
lowPassSlider.setTextBoxIsEditable(false);
addAndMakeVisible(lowPassSlider);
lowPassSliderAttachment = std::make_unique<juce::AudioProcessorValueTreeState::SliderAttachment>(audioProcessor.apvts, "LPF", lowPassSlider);
addAndMakeVisible(lowPassLabel);
lowPassLabel.setText("LPF", juce::dontSendNotification);
lowPassLabel.attachToComponent(&lowPassSlider, false);
lowPassLabel.setJustificationType(juce::Justification::centred);

predelaySlider.setSliderStyle(juce::Slider::SliderStyle::LinearBarVertical);
predelaySlider.setTextBoxIsEditable(false);
addAndMakeVisible(predelaySlider);
predelaySliderAttachment = std::make_unique<juce::AudioProcessorValueTreeState::SliderAttachment>(audioProcessor.apvts, "PREDELAY", predelaySlider);
addAndMakeVisible(predelayLabel);
Expand All @@ -22,6 +50,7 @@ SG323AudioProcessorEditor::SG323AudioProcessorEditor(SG323AudioProcessor& p)
predelayLabel.setJustificationType(juce::Justification::centred);

decaySlider.setSliderStyle(juce::Slider::SliderStyle::LinearBarVertical);
decaySlider.setTextBoxIsEditable(false);
addAndMakeVisible(decaySlider);
decaySliderAttachment = std::make_unique<juce::AudioProcessorValueTreeState::SliderAttachment>(audioProcessor.apvts, "DECAY", decaySlider);
addAndMakeVisible(decayLabel);
Expand All @@ -30,29 +59,14 @@ SG323AudioProcessorEditor::SG323AudioProcessorEditor(SG323AudioProcessor& p)
decayLabel.setJustificationType(juce::Justification::centred);

wetDrySlider.setSliderStyle(juce::Slider::SliderStyle::LinearBarVertical);
wetDrySlider.setTextBoxIsEditable(false);
addAndMakeVisible(wetDrySlider);
wetDrySliderAttachment = std::make_unique<juce::AudioProcessorValueTreeState::SliderAttachment>(audioProcessor.apvts, "WETDRY", wetDrySlider);
addAndMakeVisible(wetDryLabel);
wetDryLabel.setText("MIX", juce::dontSendNotification);
wetDryLabel.attachToComponent(&wetDrySlider, false);
wetDryLabel.setJustificationType(juce::Justification::centred);

highPassSlider.setSliderStyle(juce::Slider::SliderStyle::LinearBarVertical);
addAndMakeVisible(highPassSlider);
highPassSliderAttachment = std::make_unique<juce::AudioProcessorValueTreeState::SliderAttachment>(audioProcessor.apvts, "HPF", highPassSlider);
addAndMakeVisible(highPassLabel);
highPassLabel.setText("HPF", juce::dontSendNotification);
highPassLabel.attachToComponent(&highPassSlider, false);
highPassLabel.setJustificationType(juce::Justification::centred);

lowPassSlider.setSliderStyle(juce::Slider::SliderStyle::LinearBarVertical);
addAndMakeVisible(lowPassSlider);
lowPassSliderAttachment = std::make_unique<juce::AudioProcessorValueTreeState::SliderAttachment>(audioProcessor.apvts, "LPF", lowPassSlider);
addAndMakeVisible(lowPassLabel);
lowPassLabel.setText("LPF", juce::dontSendNotification);
lowPassLabel.attachToComponent(&lowPassSlider, false);
lowPassLabel.setJustificationType(juce::Justification::centred);

programBox.addItem("Plate 1", 1);
programBox.addItem("Plate 2", 2);
programBox.addItem("Chamber", 3);
Expand All @@ -66,7 +80,7 @@ SG323AudioProcessorEditor::SG323AudioProcessorEditor(SG323AudioProcessor& p)
programBoxAttachment = std::make_unique<juce::AudioProcessorValueTreeState::ComboBoxAttachment>(audioProcessor.apvts, "PROGRAM", programBox);
// Make sure that before the constructor has finished, you've set the
// editor's size to whatever you need it to be.
setSize(400, 350);
setSize(475, 350);
}

SG323AudioProcessorEditor::~SG323AudioProcessorEditor()
Expand All @@ -81,18 +95,19 @@ void SG323AudioProcessorEditor::paint(juce::Graphics& g)

g.setColour(juce::Colours::white);
g.setFont(15.0f);
g.drawFittedText ("v0.3.2", getLocalBounds(), juce::Justification::bottomRight, 1);
g.drawFittedText ("v0.4.0", getLocalBounds(), juce::Justification::bottomRight, 1);
}

void SG323AudioProcessorEditor::resized()
{
// This is generally where you'll want to lay out the positions of any
// subcomponents in your editor..
juce::Rectangle<int> bounds = getLocalBounds();
programBox.setBounds(225, 25, 150, 50);
highPassSlider.setBounds(25, 120, 50, 200);
lowPassSlider.setBounds(100, 120, 50, 200);
predelaySlider.setBounds(175, 120, 50, 200);
decaySlider.setBounds(250, 120, 50, 200);
wetDrySlider.setBounds(325, 120, 50, 200);
programBox.setBounds(300, 25, 150, 50);
inputGainSlider.setBounds(25, 120, 50, 200);
highPassSlider.setBounds(100, 120, 50, 200);
lowPassSlider.setBounds(175, 120, 50, 200);
predelaySlider.setBounds(250, 120, 50, 200);
decaySlider.setBounds(325, 120, 50, 200);
wetDrySlider.setBounds(400, 120, 50, 200);
}
3 changes: 3 additions & 0 deletions Source/PluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,22 @@ class SG323AudioProcessorEditor : public juce::AudioProcessorEditor
juce::Slider wetDrySlider;
juce::Slider highPassSlider;
juce::Slider lowPassSlider;
juce::Slider inputGainSlider;
juce::ComboBox programBox;

juce::Label predelayLabel;
juce::Label decayLabel;
juce::Label wetDryLabel;
juce::Label highPassLabel;
juce::Label lowPassLabel;
juce::Label inputGainLabel;

std::unique_ptr<juce::AudioProcessorValueTreeState::SliderAttachment> decaySliderAttachment;
std::unique_ptr<juce::AudioProcessorValueTreeState::SliderAttachment> predelaySliderAttachment;
std::unique_ptr<juce::AudioProcessorValueTreeState::SliderAttachment> wetDrySliderAttachment;
std::unique_ptr<juce::AudioProcessorValueTreeState::SliderAttachment> highPassSliderAttachment;
std::unique_ptr<juce::AudioProcessorValueTreeState::SliderAttachment> lowPassSliderAttachment;
std::unique_ptr<juce::AudioProcessorValueTreeState::SliderAttachment> inputGainSliderAttachment;
std::unique_ptr<juce::AudioProcessorValueTreeState::ComboBoxAttachment> programBoxAttachment;
SG323AudioProcessor& audioProcessor;

Expand Down
18 changes: 12 additions & 6 deletions Source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,13 @@ void SG323AudioProcessor::prepareToPlay(double sampleRate, int samplesPerBlock)
//set up filters
lastSampleRate = sampleRate;
float smoothSlow{ 0.1f };
float smoothFast{ 0.001f };
wetDrySmooth.reset(sampleRate, smoothFast);
predelaySmooth.reset(sampleRate, smoothSlow);
decaySmooth.reset(sampleRate, smoothSlow);
float smoothFast{ 0.0005f };
inputGainSmooth.reset(sampleRate, smoothFast);
highPassSmooth.reset(sampleRate, smoothFast);
lowPassSmooth.reset(sampleRate, smoothFast);
predelaySmooth.reset(sampleRate, smoothSlow);
decaySmooth.reset(sampleRate, smoothSlow);
wetDrySmooth.reset(sampleRate, smoothFast);
juce::dsp::ProcessSpec spec;
spec.sampleRate = sampleRate;
spec.maximumBlockSize = samplesPerBlock;
Expand Down Expand Up @@ -360,9 +361,9 @@ void SG323AudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, juce::M
}
//set up dsp elements
juce::dsp::AudioBlock <float> monoBlock(monoBuffer);
juce::dsp::AudioBlock <float> randomBlock(randomBuffer);
juce::dsp::AudioBlock <float> feedbackBlock(feedbackBuffer);
juce::dsp::AudioBlock <float> outputBlock(outputBuffer);
juce::dsp::AudioBlock <float> randomBlock(randomBuffer);
//update filters
float highPassValue = *apvts.getRawParameterValue("HPF");
highPassSmooth.setTargetValue(highPassValue);
Expand All @@ -378,7 +379,11 @@ void SG323AudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, juce::M
//sum input channels together
monoBuffer.copyFrom(0, 0, buffer, 0, 0, bufferSize);
monoBuffer.addFrom(0, 0, buffer, 1, 0, bufferSize);
gainModule.setGainLinear(0.5f);
//apply input gain
float inputGainValue = *apvts.getRawParameterValue("INPUT");
inputGainSmooth.setTargetValue(inputGainValue * 0.5f);
nextInputGainValue = inputGainSmooth.getNextValue();
gainModule.setGainLinear(nextInputGainValue);
gainModule.process(juce::dsp::ProcessContextReplacing <float>(monoBlock));
//copy & filter random Sample buffer
randomBuffer.clear(0, 0, bufferSize);
Expand Down Expand Up @@ -630,6 +635,7 @@ juce::AudioProcessorValueTreeState::ParameterLayout SG323AudioProcessor::createP
parameters.push_back(std::make_unique<juce::AudioParameterFloat>("WETDRY", "WetDry", 0.0f, 1.0f, 0.5f));
parameters.push_back(std::make_unique<juce::AudioParameterFloat>("HPF", "highPassFilter", 20.0f, 480.0f, 20.0f));
parameters.push_back(std::make_unique<juce::AudioParameterFloat>("LPF", "lowPassFilter", 3000.0f, 16000.0f, 16000.0f));
parameters.push_back(std::make_unique<juce::AudioParameterFloat>("INPUT", "inputGain", 0.0f, 2.0f, 1.0f));

return { parameters.begin(), parameters.end() };
}
18 changes: 11 additions & 7 deletions Source/PluginProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,19 @@ class SG323AudioProcessor : public juce::AudioProcessor

private:
juce::AudioProcessorValueTreeState::ParameterLayout createParameters();
juce::AudioBuffer<float> inputBuffer;
juce::AudioBuffer<float> monoBuffer;
juce::AudioBuffer<float> randomBuffer;
juce::AudioBuffer<float> feedbackBuffer;
juce::AudioBuffer<float> outputBuffer;
juce::AudioBuffer<float> inputBuffer;
juce::AudioBuffer<float> monoBuffer;
juce::LinearSmoothedValue<float> wetDrySmooth{};
juce::LinearSmoothedValue<float> predelaySmooth{};
juce::LinearSmoothedValue<float> decaySmooth{};

juce::LinearSmoothedValue<float> inputGainSmooth{};
juce::LinearSmoothedValue<float> highPassSmooth{};
juce::LinearSmoothedValue<float> lowPassSmooth{};
juce::LinearSmoothedValue<float> predelaySmooth{};
juce::LinearSmoothedValue<float> decaySmooth{};
juce::LinearSmoothedValue<float> wetDrySmooth{};

juce::dsp::Gain<float> gainModule;
juce::dsp::DelayLine<float, juce::dsp::DelayLineInterpolationTypes::Linear> fractionalDelay;
juce::dsp::ProcessorDuplicator <juce::dsp::IIR::Filter <float>, juce::dsp::IIR::Coefficients <float>> inputHighPass;
Expand All @@ -91,13 +94,12 @@ class SG323AudioProcessor : public juce::AudioProcessor
unsigned long delayTaps[24];
unsigned char gainCeiling[24];
signed char signMod[24];
unsigned int modClockOut{};
unsigned int modCount{};
int initSampleRateCount{};
float lastSampleRate{};
float adjustablePreDelay{};
float adjustableDecay{ 1.0f };
float adjustableWetDry{ 0.5f };
float nextInputGainValue{ 1.0f };
float nextHighPassValue{ 20.0f };
float nextLowPassValue{ 16000.0f };
int writeAddress{ 16383 };
Expand All @@ -106,6 +108,8 @@ class SG323AudioProcessor : public juce::AudioProcessor
unsigned int modRateCeiling{ 16 };
float modScale{ 1.0f };
unsigned char MCCK{};
unsigned int modClockOut{};
unsigned int modCount{};
unsigned int gainModContBaseAddr{};
unsigned int gainModBaseAddr{};
unsigned int delayModBaseAddr{};
Expand Down

0 comments on commit 6a5cc66

Please sign in to comment.