Skip to content

Commit

Permalink
added some agc control
Browse files Browse the repository at this point in the history
  • Loading branch information
k9yyy committed Jun 8, 2019
1 parent 04bbf31 commit c20a51a
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 10 deletions.
34 changes: 25 additions & 9 deletions Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ThreadCutterAudioProcessorEditor::ThreadCutterAudioProcessorEditor(ThreadCutterA
{
// Make sure that before the constructor has finished, you've set the
// editor's size to whatever you need it to be.
setSize(400, 235);
setSize(400, 265);


this->addAndMakeVisible(&matchScoreDisplay);
Expand All @@ -21,6 +21,15 @@ ThreadCutterAudioProcessorEditor::ThreadCutterAudioProcessorEditor(ThreadCutterA
thresholdSlider.addListener(this);
addAndMakeVisible(&thresholdSlider);

agcSpeedSlider.setSliderStyle(Slider::LinearHorizontal);
agcSpeedSlider.setRange(0.0, 0.3, 0.01);
agcSpeedSlider.setTextBoxStyle(Slider::NoTextBox, false, 90, 16);
agcSpeedSlider.setPopupDisplayEnabled(true, false, this);
agcSpeedSlider.setValue(0.15);
agcSpeedSlider.setTextValueSuffix("(AGC Speed)");
agcSpeedSlider.addListener(this);
addAndMakeVisible(&agcSpeedSlider);

for (int i = 0; i < 3; ++i)
{
doSampleButton[i].setButtonText("Capture sample " + std::to_string(i + 1));
Expand Down Expand Up @@ -74,22 +83,29 @@ void ThreadCutterAudioProcessorEditor::resized()
// This is generally where you'll want to lay out the positions of any
// subcomponents in your editor..
thresholdSlider.setBounds(50, 60, 300, 30);
matchScoreDisplay.setBounds(50, 30, 300, 30);
matchScoreDisplay.setBounds(50, 30, 300, 30);
for (int i = 0; i < 3; ++i)
{
doSampleButton[i].setBounds(60 + i * 100, 100, 80, 30);
enableSampleButton[i].setBounds(60 + i * 100, 130, 80, 30);
doSampleButton[i].setBounds(60 + i * 100, 130, 80, 30);
enableSampleButton[i].setBounds(60 + i * 100, 160, 80, 30);
}

saveToFile.setBounds(80, 180, 110, 30);
loadFromFile.setBounds(210, 180, 110, 30);
saveToFile.setBounds(80, 210, 110, 30);
loadFromFile.setBounds(210, 210, 110, 30);

agcSpeedSlider.setBounds(50, 90, 300, 30);
}

void ThreadCutterAudioProcessorEditor::sliderValueChanged(Slider * slider)
{
processor.setMfccScoreOffset(mfccScoreOffsetSlider.getValue());
processor.setMfccScoreScale(mfccScoreScaleSlider.getValue());
processor.setMfccScoreThreshold(thresholdSlider.getValue());
if (slider == &agcSpeedSlider)
{
processor.setAgcSpeed(agcSpeedSlider.getValue());
}
else if (slider == &thresholdSlider)
{
processor.setMfccScoreThreshold(thresholdSlider.getValue());
}
}

void ThreadCutterAudioProcessorEditor::buttonClicked(Button * button)
Expand Down
1 change: 1 addition & 0 deletions Source/PluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ThreadCutterAudioProcessorEditor : public AudioProcessorEditor, private Sl
Slider mfccScoreOffsetSlider;
Slider mfccScoreScaleSlider;
Slider thresholdSlider;
Slider agcSpeedSlider;
TextButton doSampleButton[3];
ToggleButton enableSampleButton[3];

Expand Down
5 changes: 5 additions & 0 deletions Source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ void ThreadCutterAudioProcessor::setMfccScoreThreshold(double value)
processor[0].setMfccScoreThreshold(value);
}

void ThreadCutterAudioProcessor::setAgcSpeed(double value)
{
processor[0].setAgcSpeed(value);
}

void ThreadCutterAudioProcessor::doCaptureSample(int n)
{
processor[0].doCaptureSample(n);
Expand Down
1 change: 1 addition & 0 deletions Source/PluginProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ThreadCutterAudioProcessor : public AudioProcessor
void setMfccScoreOffset(double value);
void setMfccScoreScale(double value);
void setMfccScoreThreshold(double value);
void setAgcSpeed(double value);
void doCaptureSample(int n);
void setSampleEnabled(int n, bool en);

Expand Down
7 changes: 6 additions & 1 deletion Source/Processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ double Processor::getAgcGained(double sample)
double gained = sample * agcGain;
double _agcSpeed = agcSpeed / frameSize;
if (std::abs(gained) > 1) agcGain -= agcSpeed;
else agcGain += _agcSpeed;
else if (agcMaxGain > agcGain) agcGain += _agcSpeed;
return gained;
}

Expand Down Expand Up @@ -108,6 +108,11 @@ void Processor::setMfccScoreThreshold(double value)
threshold = value;
}

void Processor::setAgcSpeed(double value)
{
agcSpeed = value;
}

void Processor::reload()
{
if (doDetection)
Expand Down
2 changes: 2 additions & 0 deletions Source/Processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Processor
void setMfccScoreOffset(double value);
void setMfccScoreScale(double value);
void setMfccScoreThreshold(double value);
void setAgcSpeed(double value);
void reload();
void doCaptureSample(int n);
void setSampleEnabled(int n, bool en);
Expand Down Expand Up @@ -49,6 +50,7 @@ class Processor
double threshold = 0.5;
double agcSpeed = 0.2;
double agcGain = 1;
double agcMaxGain = 100.;

};

0 comments on commit c20a51a

Please sign in to comment.