Lade till visuella mätare på Gate och Kompressor
This commit is contained in:
1 parent
5b1d22c745
commit
f0570b1313
4 files changed
+300
-43
No files matched your search
+82
-20
@@ -2,15 +2,19 @@
|
||||
#include "PluginEditor.h"
|
||||
#include <cmath>
|
||||
|
||||
namespace {
|
||||
constexpr auto pid = [](const char* s) { return juce::ParameterID{s, 1}; };
|
||||
namespace
|
||||
{
|
||||
constexpr auto pid = [](const char* s) { return juce::ParameterID { s, 1 }; };
|
||||
float dbToGain(float db) { return juce::Decibels::decibelsToGain(db); }
|
||||
constexpr float meterFloorDb = -80.0f;
|
||||
}
|
||||
|
||||
CrilleBassStripAudioProcessor::CrilleBassStripAudioProcessor()
|
||||
: AudioProcessor(BusesProperties().withInput("Input", juce::AudioChannelSet::stereo(), true)
|
||||
.withOutput("Output", juce::AudioChannelSet::stereo(), true)),
|
||||
apvts(*this, nullptr, "PARAMETERS", createParameterLayout()) {}
|
||||
apvts(*this, nullptr, "PARAMETERS", createParameterLayout())
|
||||
{
|
||||
}
|
||||
|
||||
juce::AudioProcessorValueTreeState::ParameterLayout CrilleBassStripAudioProcessor::createParameterLayout()
|
||||
{
|
||||
@@ -36,17 +40,37 @@ juce::AudioProcessorValueTreeState::ParameterLayout CrilleBassStripAudioProcesso
|
||||
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();
|
||||
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);
|
||||
gateInputLevelDb.store(meterFloorDb);
|
||||
compressorInputLevelDb.store(meterFloorDb);
|
||||
compressorGainReductionDb.store(0.0f);
|
||||
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();
|
||||
return (out == juce::AudioChannelSet::mono() || out == juce::AudioChannelSet::stereo())
|
||||
&& out == l.getMainInputChannelSet();
|
||||
}
|
||||
|
||||
float CrilleBassStripAudioProcessor::getBufferPeak(const juce::AudioBuffer<float>& buffer) noexcept
|
||||
{
|
||||
float peak = 0.0f;
|
||||
for (int channel = 0; channel < buffer.getNumChannels(); ++channel)
|
||||
peak = juce::jmax(peak, buffer.getMagnitude(channel, 0, buffer.getNumSamples()));
|
||||
return peak;
|
||||
}
|
||||
|
||||
void CrilleBassStripAudioProcessor::updateFilters()
|
||||
@@ -64,52 +88,90 @@ void CrilleBassStripAudioProcessor::updateFilters()
|
||||
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());
|
||||
for (int c = getTotalNumInputChannels(); c < getTotalNumOutputChannels(); ++c)
|
||||
buffer.clear(c, 0, buffer.getNumSamples());
|
||||
|
||||
const float gateInputPeak = getBufferPeak(buffer);
|
||||
gateInputLevelDb.store(juce::Decibels::gainToDecibels(gateInputPeak, meterFloorDb), std::memory_order_relaxed);
|
||||
|
||||
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) {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
const float compressorInputPeak = getBufferPeak(buffer);
|
||||
compressorInputLevelDb.store(juce::Decibels::gainToDecibels(compressorInputPeak, meterFloorDb), std::memory_order_relaxed);
|
||||
|
||||
compressor.setThreshold(apvts.getRawParameterValue("compThreshold")->load());
|
||||
compressor.setRatio(apvts.getRawParameterValue("compRatio")->load());
|
||||
compressor.setAttack(15.f); compressor.setRelease(100.f);
|
||||
compressor.setAttack(15.f);
|
||||
compressor.setRelease(100.f);
|
||||
|
||||
juce::dsp::AudioBlock<float> block(buffer);
|
||||
juce::dsp::ProcessContextReplacing<float> context(block);
|
||||
compressor.process(context);
|
||||
|
||||
const float compressorOutputPeak = getBufferPeak(buffer);
|
||||
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);
|
||||
|
||||
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) {
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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));
|
||||
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();
|
||||
}
|
||||
juce::AudioProcessorEditor* CrilleBassStripAudioProcessor::createEditor() { return new CrilleBassStripAudioProcessorEditor(*this); }
|
||||
juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter() { return new CrilleBassStripAudioProcessor(); }
|
||||
Reference in new issue
Block a user