(
- pid("downTuneOn"),
- "DownTune",
- false));
- p.add(std::make_unique(pid("gateThreshold"), "Gate Threshold", juce::NormalisableRange(-80.f, -10.f, 0.1f), -45.f, "dB"));
- p.add(std::make_unique(pid("gateRelease"), "Gate Release", juce::NormalisableRange(20.f, 500.f, 1.f, 0.5f), 150.f, "ms"));
- p.add(std::make_unique(pid("gateGain"), "Gate Gain", juce::NormalisableRange(-24.f, 12.f, 0.1f), 0.f, "dB"));
- p.add(std::make_unique(pid("compThreshold"), "Comp Threshold", juce::NormalisableRange(-60.f, 0.f, 0.1f), -18.f, "dB"));
- p.add(std::make_unique(pid("compRatio"), "Comp Ratio", juce::NormalisableRange(1.f, 20.f, 0.1f, 0.5f), 4.f, ":1"));
- p.add(std::make_unique(pid("compGain"), "Comp Gain", juce::NormalisableRange(-12.f, 18.f, 0.1f), 3.f, "dB"));
- p.add(std::make_unique(pid("drive"), "Drive", juce::NormalisableRange(0.f, 24.f, 0.1f), 5.f, "dB"));
- p.add(std::make_unique(pid("mix"), "Distortion Mix", juce::NormalisableRange(0.f, 100.f, 1.f), 25.f, "%"));
- p.add(std::make_unique(pid("distGain"), "Distortion Gain", juce::NormalisableRange(-18.f, 12.f, 0.1f), 0.f, "dB"));
- p.add(std::make_unique(pid("bass"), "Bass", juce::NormalisableRange(-12.f, 12.f, 0.1f), 2.f, "dB"));
- p.add(std::make_unique(pid("lowMid"), "Low Mid", juce::NormalisableRange(-12.f, 12.f, 0.1f), -2.f, "dB"));
- p.add(std::make_unique(pid("middle"), "Middle", juce::NormalisableRange(-12.f, 12.f, 0.1f), 0.f, "dB"));
- p.add(std::make_unique(pid("treble"), "Treble", juce::NormalisableRange(-12.f, 12.f, 0.1f), 1.f, "dB"));
- p.add(std::make_unique(pid("output"), "Output", juce::NormalisableRange(-24.f, 12.f, 0.1f), -1.f, "dB"));
+ pid("downTuneOn"),
+ "DownTune",
+ false));
+
+ p.add(std::make_unique(
+ pid("gateOn"),
+ "Gate On",
+ true));
+
+ p.add(std::make_unique(
+ pid("compressorOn"),
+ "Compressor On",
+ true));
+
+ p.add(std::make_unique(
+ pid("distortionOn"),
+ "Distortion On",
+ true));
+
+ p.add(std::make_unique(
+ pid("eqOn"),
+ "EQ On",
+ true));
+
+ p.add(std::make_unique(
+ pid("gateThreshold"),
+ "Gate Threshold",
+ juce::NormalisableRange(-80.f, -10.f, 0.1f),
+ -55.f,
+ "dB"));
+
+ p.add(std::make_unique(
+ pid("gateRelease"),
+ "Gate Release",
+ juce::NormalisableRange(20.f, 500.f, 1.f, 0.5f),
+ 150.f,
+ "ms"));
+
+ p.add(std::make_unique(
+ pid("gateGain"),
+ "Gate Gain",
+ juce::NormalisableRange(-24.f, 12.f, 0.1f),
+ 0.f,
+ "dB"));
+
+ p.add(std::make_unique(
+ pid("compThreshold"),
+ "Comp Threshold",
+ juce::NormalisableRange(-60.f, 0.f, 0.1f),
+ -30.f,
+ "dB"));
+
+ p.add(std::make_unique(
+ pid("compRatio"),
+ "Comp Ratio",
+ juce::NormalisableRange(1.f, 20.f, 0.1f, 0.5f),
+ 3.f,
+ ":1"));
+
+ p.add(std::make_unique(
+ pid("compGain"),
+ "Comp Gain",
+ juce::NormalisableRange(-12.f, 18.f, 0.1f),
+ 2.f,
+ "dB"));
+
+ p.add(std::make_unique(
+ pid("drive"),
+ "Drive",
+ juce::NormalisableRange(0.f, 24.f, 0.1f),
+ 5.f,
+ "dB"));
+
+ p.add(std::make_unique(
+ pid("mix"),
+ "Distortion Mix",
+ juce::NormalisableRange(0.f, 100.f, 1.f),
+ 25.f,
+ "%"));
+
+ p.add(std::make_unique(
+ pid("distGain"),
+ "Distortion Gain",
+ juce::NormalisableRange(-18.f, 12.f, 0.1f),
+ 0.f,
+ "dB"));
+
+ p.add(std::make_unique(
+ pid("bass"),
+ "Bass",
+ juce::NormalisableRange(-12.f, 12.f, 0.1f),
+ 0.f,
+ "dB"));
+
+ p.add(std::make_unique(
+ pid("lowMid"),
+ "Low Mid",
+ juce::NormalisableRange(-12.f, 12.f, 0.1f),
+ 0.f,
+ "dB"));
+
+ p.add(std::make_unique(
+ pid("middle"),
+ "Middle",
+ juce::NormalisableRange(-12.f, 12.f, 0.1f),
+ 0.f,
+ "dB"));
+
+ p.add(std::make_unique(
+ pid("treble"),
+ "Treble",
+ juce::NormalisableRange(-12.f, 12.f, 0.1f),
+ 0.f,
+ "dB"));
+
+ p.add(std::make_unique(
+ pid("output"),
+ "Output",
+ juce::NormalisableRange(-24.f, 12.f, 0.1f),
+ 0.f,
+ "dB"));
+
return p;
}
@@ -60,14 +166,16 @@ void CrilleBassStripAudioProcessor::prepareToPlay(double sr, int block)
setLatencySamples(
downTune.inputLatency() +
downTune.outputLatency());
+
downTuneLatencyMs =
- 1000.0 *
- (downTune.inputLatency() + downTune.outputLatency()) /
- sr;
+ 1000.0 *
+ (downTune.inputLatency() + downTune.outputLatency()) /
+ sr;
+
//debug börjar
DBG("DownTune input latency: "
- << downTune.inputLatency()
- << " samples");
+ << downTune.inputLatency()
+ << " samples");
DBG("DownTune output latency: "
<< downTune.outputLatency()
@@ -80,40 +188,61 @@ void CrilleBassStripAudioProcessor::prepareToPlay(double sr, int block)
DBG("DownTune latency ms: "
<< 1000.0 * (downTune.inputLatency() + downTune.outputLatency()) / sr);
// debug slutar
- juce::dsp::ProcessSpec spec { sr, static_cast(block), static_cast(getTotalNumOutputChannels()) };
+
+ juce::dsp::ProcessSpec spec {
+ sr,
+ static_cast(block),
+ static_cast(getTotalNumOutputChannels())
+ };
+
compressor.prepare(spec);
lowShelf.prepare(spec);
lowMid.prepare(spec);
mid.prepare(spec);
highShelf.prepare(spec);
+
compressor.reset();
lowShelf.reset();
lowMid.reset();
mid.reset();
highShelf.reset();
- gateEnvelope.assign(static_cast(getTotalNumOutputChannels()), 0.f);
+
+ gateEnvelope.assign(
+ static_cast(getTotalNumOutputChannels()),
+ 0.f);
+
gateInputLevelDb.store(meterFloorDb);
compressorInputLevelDb.store(meterFloorDb);
compressorGainReductionDb.store(0.0f);
+
updateFilters();
}
bool CrilleBassStripAudioProcessor::isBusesLayoutSupported(const BusesLayout& layouts) const
{
- const auto input = layouts.getMainInputChannelSet();
+ const auto input = layouts.getMainInputChannelSet();
const auto output = layouts.getMainOutputChannelSet();
return input == juce::AudioChannelSet::mono()
&& output == juce::AudioChannelSet::stereo();
}
-float CrilleBassStripAudioProcessor::getBufferPeak(const juce::AudioBuffer& buffer) noexcept
+float CrilleBassStripAudioProcessor::getBufferPeak(
+ const juce::AudioBuffer& buffer) noexcept
{
float peak = 0.0f;
+
for (int channel = 0; channel < buffer.getNumChannels(); ++channel)
- peak = juce::jmax(peak, buffer.getMagnitude(channel, 0, buffer.getNumSamples()));
+ peak = juce::jmax(
+ peak,
+ buffer.getMagnitude(
+ channel,
+ 0,
+ buffer.getNumSamples()));
+
return peak;
}
+
void CrilleBassStripAudioProcessor::updatePitchDetector(
const float* input,
int numSamples)
@@ -302,21 +431,67 @@ void CrilleBassStripAudioProcessor::analysePitch()
void CrilleBassStripAudioProcessor::updateFilters()
{
- const auto bass = apvts.getRawParameterValue("bass")->load();
- const auto lm = apvts.getRawParameterValue("lowMid")->load();
- const auto m = apvts.getRawParameterValue("middle")->load();
- const auto tr = apvts.getRawParameterValue("treble")->load();
- *lowShelf.state = *juce::dsp::IIR::Coefficients::makeLowShelf(currentSampleRate, 80.0, 0.707, dbToGain(bass));
- *lowMid.state = *juce::dsp::IIR::Coefficients::makePeakFilter(currentSampleRate, 300.0, 0.8, dbToGain(lm));
- *mid.state = *juce::dsp::IIR::Coefficients::makePeakFilter(currentSampleRate, 900.0, 0.8, dbToGain(m));
- *highShelf.state = *juce::dsp::IIR::Coefficients::makeHighShelf(currentSampleRate, 3500.0, 0.707, dbToGain(tr));
+ const auto bass =
+ apvts.getRawParameterValue("bass")->load();
+
+ const auto lm =
+ apvts.getRawParameterValue("lowMid")->load();
+
+ const auto m =
+ apvts.getRawParameterValue("middle")->load();
+
+ const auto tr =
+ apvts.getRawParameterValue("treble")->load();
+
+ *lowShelf.state =
+ *juce::dsp::IIR::Coefficients::makeLowShelf(
+ currentSampleRate,
+ 80.0,
+ 0.707,
+ dbToGain(bass));
+
+ *lowMid.state =
+ *juce::dsp::IIR::Coefficients::makePeakFilter(
+ currentSampleRate,
+ 300.0,
+ 0.8,
+ dbToGain(lm));
+
+ *mid.state =
+ *juce::dsp::IIR::Coefficients::makePeakFilter(
+ currentSampleRate,
+ 900.0,
+ 0.8,
+ dbToGain(m));
+
+ *highShelf.state =
+ *juce::dsp::IIR::Coefficients::makeHighShelf(
+ currentSampleRate,
+ 3500.0,
+ 0.707,
+ dbToGain(tr));
}
-void CrilleBassStripAudioProcessor::processBlock(juce::AudioBuffer& buffer, juce::MidiBuffer&)
+void CrilleBassStripAudioProcessor::processBlock(
+ juce::AudioBuffer& buffer,
+ juce::MidiBuffer&)
{
juce::ScopedNoDenormals noDenormals;
const int numSamples = buffer.getNumSamples();
+
+ const bool gateEnabled =
+ apvts.getRawParameterValue("gateOn")->load() > 0.5f;
+
+ const bool compressorEnabled =
+ apvts.getRawParameterValue("compressorOn")->load() > 0.5f;
+
+ const bool distortionEnabled =
+ apvts.getRawParameterValue("distortionOn")->load() > 0.5f;
+
+ const bool eqEnabled =
+ apvts.getRawParameterValue("eqOn")->load() > 0.5f;
+
if (buffer.getNumChannels() > 0)
{
updatePitchDetector(
@@ -370,47 +545,65 @@ void CrilleBassStripAudioProcessor::processBlock(juce::AudioBuffer& buffe
// Copy the processed mono bass signal to both stereo output channels.
if (buffer.getNumChannels() >= 2)
buffer.copyFrom(1, 0, buffer, 0, 0, numSamples);
-
+
// Measure input level before the noise gate.
const float gateInputPeak = getBufferPeak(buffer);
+
gateInputLevelDb.store(
- juce::Decibels::gainToDecibels(gateInputPeak, meterFloorDb),
+ juce::Decibels::gainToDecibels(
+ gateInputPeak,
+ meterFloorDb),
std::memory_order_relaxed);
// Noise gate
- const float threshold =
- dbToGain(apvts.getRawParameterValue("gateThreshold")->load());
-
- const float releaseMs =
- apvts.getRawParameterValue("gateRelease")->load();
-
- const float releaseCoeff =
- std::exp(-1.f / (0.001f * releaseMs *
- static_cast(currentSampleRate)));
-
- const float gateGain =
- dbToGain(apvts.getRawParameterValue("gateGain")->load());
-
- for (int c = 0; c < buffer.getNumChannels(); ++c)
+ if (gateEnabled)
{
- auto* x = buffer.getWritePointer(c);
- auto& env = gateEnvelope[static_cast(c)];
+ const float threshold =
+ dbToGain(
+ apvts.getRawParameterValue("gateThreshold")->load());
- for (int i = 0; i < buffer.getNumSamples(); ++i)
+ const float releaseMs =
+ apvts.getRawParameterValue("gateRelease")->load();
+
+ const float releaseCoeff =
+ std::exp(
+ -1.f /
+ (0.001f * releaseMs *
+ static_cast(currentSampleRate)));
+
+ const float gateGain =
+ dbToGain(
+ apvts.getRawParameterValue("gateGain")->load());
+
+ for (int c = 0; c < buffer.getNumChannels(); ++c)
{
- const float target =
- std::abs(x[i]) >= threshold ? 1.f : 0.f;
+ auto* x = buffer.getWritePointer(c);
+ auto& env = gateEnvelope[static_cast(c)];
- env = target > env
- ? target
- : releaseCoeff * env;
+ for (int i = 0; i < buffer.getNumSamples(); ++i)
+ {
+ const float target =
+ std::abs(x[i]) >= threshold ? 1.f : 0.f;
- x[i] *= env * gateGain;
+ env = target > env
+ ? target
+ : releaseCoeff * env;
+
+ x[i] *= env * gateGain;
+ }
}
}
+ else
+ {
+ std::fill(
+ gateEnvelope.begin(),
+ gateEnvelope.end(),
+ 1.0f);
+ }
// Measure compressor input level.
- const float compressorInputPeak = getBufferPeak(buffer);
+ const float compressorInputPeak =
+ getBufferPeak(buffer);
compressorInputLevelDb.store(
juce::Decibels::gainToDecibels(
@@ -418,73 +611,95 @@ void CrilleBassStripAudioProcessor::processBlock(juce::AudioBuffer& buffe
meterFloorDb),
std::memory_order_relaxed);
- // Compressor
- compressor.setThreshold(
- apvts.getRawParameterValue("compThreshold")->load());
-
- compressor.setRatio(
- apvts.getRawParameterValue("compRatio")->load());
-
- compressor.setAttack(15.f);
- compressor.setRelease(100.f);
-
juce::dsp::AudioBlock block(buffer);
juce::dsp::ProcessContextReplacing context(block);
- compressor.process(context);
+ // Compressor
+ if (compressorEnabled)
+ {
+ compressor.setThreshold(
+ apvts.getRawParameterValue("compThreshold")->load());
- // Calculate compressor gain reduction.
- const float compressorOutputPeak = getBufferPeak(buffer);
+ compressor.setRatio(
+ apvts.getRawParameterValue("compRatio")->load());
- const float gainReduction =
- compressorInputPeak > 0.0f
- ? juce::jmax(
- 0.0f,
- juce::Decibels::gainToDecibels(
- compressorInputPeak /
- juce::jmax(compressorOutputPeak, 1.0e-9f)))
- : 0.0f;
+ compressor.setAttack(15.f);
+ compressor.setRelease(100.f);
+ compressor.process(context);
- compressorGainReductionDb.store(
- juce::jlimit(0.0f, 24.0f, gainReduction),
- std::memory_order_relaxed);
+ // Calculate compressor gain reduction.
+ const float compressorOutputPeak =
+ getBufferPeak(buffer);
- // Compressor makeup gain.
- buffer.applyGain(
- dbToGain(
- apvts.getRawParameterValue("compGain")->load()));
+ const float gainReduction =
+ compressorInputPeak > 0.0f
+ ? juce::jmax(
+ 0.0f,
+ juce::Decibels::gainToDecibels(
+ compressorInputPeak /
+ juce::jmax(
+ compressorOutputPeak,
+ 1.0e-9f)))
+ : 0.0f;
+
+ compressorGainReductionDb.store(
+ juce::jlimit(
+ 0.0f,
+ 24.0f,
+ gainReduction),
+ std::memory_order_relaxed);
+
+ // Compressor makeup gain.
+ buffer.applyGain(
+ dbToGain(
+ apvts.getRawParameterValue("compGain")->load()));
+ }
+ else
+ {
+ compressorGainReductionDb.store(
+ 0.0f,
+ std::memory_order_relaxed);
+ }
// Distortion
- const float drive =
- dbToGain(apvts.getRawParameterValue("drive")->load());
-
- const float mix =
- apvts.getRawParameterValue("mix")->load() * 0.01f;
-
- const float dg =
- dbToGain(apvts.getRawParameterValue("distGain")->load());
-
- for (int c = 0; c < buffer.getNumChannels(); ++c)
+ if (distortionEnabled)
{
- auto* x = buffer.getWritePointer(c);
+ const float drive =
+ dbToGain(
+ apvts.getRawParameterValue("drive")->load());
- for (int i = 0; i < buffer.getNumSamples(); ++i)
+ const float mix =
+ apvts.getRawParameterValue("mix")->load() * 0.01f;
+
+ const float dg =
+ dbToGain(
+ apvts.getRawParameterValue("distGain")->load());
+
+ for (int c = 0; c < buffer.getNumChannels(); ++c)
{
- const float dry = x[i];
- const float wet = std::tanh(dry * drive);
+ auto* x = buffer.getWritePointer(c);
- x[i] =
- ((1.f - mix) * dry + mix * wet) * dg;
+ for (int i = 0; i < buffer.getNumSamples(); ++i)
+ {
+ const float dry = x[i];
+ const float wet = std::tanh(dry * drive);
+
+ x[i] =
+ ((1.f - mix) * dry + mix * wet) * dg;
+ }
}
}
// EQ
- updateFilters();
+ if (eqEnabled)
+ {
+ updateFilters();
- lowShelf.process(context);
- lowMid.process(context);
- mid.process(context);
- highShelf.process(context);
+ lowShelf.process(context);
+ lowMid.process(context);
+ mid.process(context);
+ highShelf.process(context);
+ }
// Final output gain.
buffer.applyGain(
@@ -492,20 +707,28 @@ void CrilleBassStripAudioProcessor::processBlock(juce::AudioBuffer& buffe
apvts.getRawParameterValue("output")->load()));
}
-void CrilleBassStripAudioProcessor::getStateInformation(juce::MemoryBlock& dest)
+void CrilleBassStripAudioProcessor::getStateInformation(
+ juce::MemoryBlock& dest)
{
if (auto xml = apvts.copyState().createXml())
copyXmlToBinary(*xml, dest);
}
-void CrilleBassStripAudioProcessor::setStateInformation(const void* data, int size)
+void CrilleBassStripAudioProcessor::setStateInformation(
+ const void* data,
+ int size)
{
if (auto xml = getXmlFromBinary(data, size);
- xml != nullptr && xml->hasTagName(apvts.state.getType()))
- apvts.replaceState(juce::ValueTree::fromXml(*xml));
+ xml != nullptr
+ && xml->hasTagName(apvts.state.getType()))
+ {
+ apvts.replaceState(
+ juce::ValueTree::fromXml(*xml));
+ }
}
-juce::AudioProcessorEditor* CrilleBassStripAudioProcessor::createEditor()
+juce::AudioProcessorEditor*
+CrilleBassStripAudioProcessor::createEditor()
{
return new CrilleBassStripAudioProcessorEditor(*this);
}
@@ -513,4 +736,4 @@ juce::AudioProcessorEditor* CrilleBassStripAudioProcessor::createEditor()
juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter()
{
return new CrilleBassStripAudioProcessor();
-}
+}
\ No newline at end of file