Startpunkten

This commit is contained in:
crille committed 2026-11-20 23:08:43 +01:00
commit e67d0afcdd
8 files changed
+371

No files matched your search

+115
View File
@@ -0,0 +1,115 @@
#include "PluginProcessor.h"
#include "PluginEditor.h"
#include <cmath>
namespace {
constexpr auto pid = [](const char* s) { return juce::ParameterID{s, 1}; };
float dbToGain(float db) { return juce::Decibels::decibelsToGain(db); }
}
CrilleBassStripAudioProcessor::CrilleBassStripAudioProcessor()
: AudioProcessor(BusesProperties().withInput("Input", juce::AudioChannelSet::stereo(), true)
.withOutput("Output", juce::AudioChannelSet::stereo(), true)),
apvts(*this, nullptr, "PARAMETERS", createParameterLayout()) {}
juce::AudioProcessorValueTreeState::ParameterLayout CrilleBassStripAudioProcessor::createParameterLayout()
{
using P = juce::AudioParameterFloat;
juce::AudioProcessorValueTreeState::ParameterLayout p;
p.add(std::make_unique<P>(pid("gateThreshold"), "Gate Threshold", juce::NormalisableRange<float>(-80.f, -10.f, 0.1f), -45.f, "dB"));
p.add(std::make_unique<P>(pid("gateRelease"), "Gate Release", juce::NormalisableRange<float>(20.f, 500.f, 1.f, 0.5f), 150.f, "ms"));
p.add(std::make_unique<P>(pid("gateGain"), "Gate Gain", juce::NormalisableRange<float>(-24.f, 12.f, 0.1f), 0.f, "dB"));
p.add(std::make_unique<P>(pid("compThreshold"), "Comp Threshold", juce::NormalisableRange<float>(-60.f, 0.f, 0.1f), -18.f, "dB"));
p.add(std::make_unique<P>(pid("compRatio"), "Comp Ratio", juce::NormalisableRange<float>(1.f, 20.f, 0.1f, 0.5f), 4.f, ":1"));
p.add(std::make_unique<P>(pid("compGain"), "Comp Gain", juce::NormalisableRange<float>(-12.f, 18.f, 0.1f), 3.f, "dB"));
p.add(std::make_unique<P>(pid("drive"), "Drive", juce::NormalisableRange<float>(0.f, 24.f, 0.1f), 5.f, "dB"));
p.add(std::make_unique<P>(pid("mix"), "Distortion Mix", juce::NormalisableRange<float>(0.f, 100.f, 1.f), 25.f, "%"));
p.add(std::make_unique<P>(pid("distGain"), "Distortion Gain", juce::NormalisableRange<float>(-18.f, 12.f, 0.1f), 0.f, "dB"));
p.add(std::make_unique<P>(pid("bass"), "Bass", juce::NormalisableRange<float>(-12.f, 12.f, 0.1f), 2.f, "dB"));
p.add(std::make_unique<P>(pid("lowMid"), "Low Mid", juce::NormalisableRange<float>(-12.f, 12.f, 0.1f), -2.f, "dB"));
p.add(std::make_unique<P>(pid("middle"), "Middle", juce::NormalisableRange<float>(-12.f, 12.f, 0.1f), 0.f, "dB"));
p.add(std::make_unique<P>(pid("treble"), "Treble", juce::NormalisableRange<float>(-12.f, 12.f, 0.1f), 1.f, "dB"));
p.add(std::make_unique<P>(pid("output"), "Output", juce::NormalisableRange<float>(-24.f, 12.f, 0.1f), -1.f, "dB"));
return p;
}
void CrilleBassStripAudioProcessor::prepareToPlay(double sr, int block)
{
currentSampleRate = sr;
juce::dsp::ProcessSpec spec{sr, static_cast<juce::uint32>(block), static_cast<juce::uint32>(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<size_t>(getTotalNumOutputChannels()), 0.f);
updateFilters();
}
bool CrilleBassStripAudioProcessor::isBusesLayoutSupported(const BusesLayout& l) const
{
const auto out = l.getMainOutputChannelSet();
return (out == juce::AudioChannelSet::mono() || out == juce::AudioChannelSet::stereo()) && out == l.getMainInputChannelSet();
}
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<float>::makeLowShelf(currentSampleRate, 80.0, 0.707, dbToGain(bass));
*lowMid.state = *juce::dsp::IIR::Coefficients<float>::makePeakFilter(currentSampleRate, 300.0, 0.8, dbToGain(lm));
*mid.state = *juce::dsp::IIR::Coefficients<float>::makePeakFilter(currentSampleRate, 900.0, 0.8, dbToGain(m));
*highShelf.state = *juce::dsp::IIR::Coefficients<float>::makeHighShelf(currentSampleRate, 3500.0, 0.707, dbToGain(tr));
}
void CrilleBassStripAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, juce::MidiBuffer&)
{
juce::ScopedNoDenormals noDenormals;
for (int c = getTotalNumInputChannels(); c < getTotalNumOutputChannels(); ++c) buffer.clear(c, 0, buffer.getNumSamples());
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<float>(currentSampleRate)));
const float gateGain = dbToGain(apvts.getRawParameterValue("gateGain")->load());
for (int c = 0; c < buffer.getNumChannels(); ++c) {
auto* x = buffer.getWritePointer(c); auto& env = gateEnvelope[static_cast<size_t>(c)];
for (int i = 0; i < buffer.getNumSamples(); ++i) {
const float target = std::abs(x[i]) >= threshold ? 1.f : 0.f;
env = target > env ? target : releaseCoeff * env;
x[i] *= env * gateGain;
}
}
compressor.setThreshold(apvts.getRawParameterValue("compThreshold")->load());
compressor.setRatio(apvts.getRawParameterValue("compRatio")->load());
compressor.setAttack(15.f); compressor.setRelease(100.f);
juce::dsp::AudioBlock<float> block(buffer);
juce::dsp::ProcessContextReplacing<float> context(block);
compressor.process(context);
buffer.applyGain(dbToGain(apvts.getRawParameterValue("compGain")->load()));
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) {
auto* x = buffer.getWritePointer(c);
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;
}
}
updateFilters();
lowShelf.process(context); lowMid.process(context); mid.process(context); highShelf.process(context);
buffer.applyGain(dbToGain(apvts.getRawParameterValue("output")->load()));
}
void CrilleBassStripAudioProcessor::getStateInformation(juce::MemoryBlock& dest)
{
if (auto xml = apvts.copyState().createXml()) copyXmlToBinary(*xml, dest);
}
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));
}
juce::AudioProcessorEditor* CrilleBassStripAudioProcessor::createEditor() { return new CrilleBassStripAudioProcessorEditor(*this); }
juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter() { return new CrilleBassStripAudioProcessor(); }