I've added threshold and release and attack with ration and bypass and added the parameters to them still sound the same when I adjust the them I'm using the juce dsp compressor module as an alias and tying it to process with auto context which equals to processContextReplacing with the auto block that equals to AudioBlock with buffer inside of it and then using get parameters with attack, release, threshold, and ratio and then passing to the constructor.
pluginProcessor.h
/*
==============================================================================
This file contains the basic framework code for a JUCE plugin processor.
==============================================================================
*/
#pragma once
#include <JuceHeader.h>
//==============================================================================
/**
*/
class SimpMbCompAudioProcessor : public juce::AudioProcessor
{
public:
void do_work();
//==============================================================================
SimpMbCompAudioProcessor();
~SimpMbCompAudioProcessor() override;
//==============================================================================
void prepareToPlay(double sampleRate, int samplesPerBlock) override;
void releaseResources() override;
#ifndef JucePlugin_PreferredChannelConfigurations
bool isBusesLayoutSupported(const BusesLayout& layouts) const override;
#endif
void processBlock(juce::AudioBuffer<float>&, juce::MidiBuffer&) override;
//==============================================================================
juce::AudioProcessorEditor* createEditor() override;
bool hasEditor() const override;
//==============================================================================
const juce::String getName() const override;
bool acceptsMidi() const override;
bool producesMidi() const override;
bool isMidiEffect() const override;
double getTailLengthSeconds() const override;
//==============================================================================
int getNumPrograms() override;
int getCurrentProgram() override;
void setCurrentProgram(int index) override;
const juce::String getProgramName(int index) override;
void changeProgramName(int index, const juce::String& newName) override;
//==============================================================================
void getStateInformation(juce::MemoryBlock& destData) override;
void setStateInformation(const void* data, int sizeInBytes) override;
using APVTS = juce::AudioProcessorValueTreeState;
static APVTS::ParameterLayout createParameterLayout();
APVTS apvts = juce::AudioProcessorValueTreeState{
*this, nullptr,
"Parameters", createParameterLayout()
};
private:
using Filter = juce::dsp::IIR::Filter<float>;
using CutFilter = juce::dsp::ProcessorChain<Filter, Filter, Filter, Filter>;
using MonoChain = juce::dsp::ProcessorChain<CutFilter, Filter, CutFilter>;
MonoChain leftChain, rightChain;
juce::dsp::Compressor<float> comperessor;
juce::AudioParameterFloat* attack{nullptr};
juce::AudioParameterFloat* release{nullptr};
juce::AudioParameterFloat* threshold{nullptr};
juce::AudioParameterChoice* ratio{nullptr};
juce::AudioParameterBool* bypassed{ nullptr };
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SimpMbCompAudioProcessor)
};
pluginprocessor.cpp
/*
==============================================================================
This file contains the basic framework code for a JUCE plugin processor.
==============================================================================
*/
#include "PluginProcessor.h"
#include "PluginEditor.h"
//==============================================================================
SimpMbCompAudioProcessor::SimpMbCompAudioProcessor()
#ifndef JucePlugin_PreferredChannelConfigurations
: AudioProcessor (BusesProperties()
#if ! JucePlugin_IsMidiEffect
#if ! JucePlugin_IsSynth
.withInput ("Input", juce::AudioChannelSet::stereo(), true)
#endif
.withOutput ("Output", juce::AudioChannelSet::stereo(), true)
#endif
)
#endif
{
attack = dynamic_cast<juce::AudioParameterFloat*>(apvts.getParameter("Attack"));
jassert(attack != nullptr);
release = dynamic_cast<juce::AudioParameterFloat*>(apvts.getParameter("Release"));
jassert(release != nullptr);
threshold = dynamic_cast<juce::AudioParameterFloat*>(apvts.getParameter("Threshold"));
jassert(threshold != nullptr);
ratio = dynamic_cast<juce::AudioParameterChoice*>(apvts.getParameter("Ratio"));
jassert(ratio != nullptr);
bypassed = dynamic_cast<juce::AudioParameterBool*>(apvts.getParameter("Bypassed"));
jassert(bypassed != nullptr);
}
SimpMbCompAudioProcessor::~SimpMbCompAudioProcessor()
{
}
//==============================================================================
const juce::String SimpMbCompAudioProcessor::getName() const
{
return JucePlugin_Name;
}
bool SimpMbCompAudioProcessor::acceptsMidi() const
{
#if JucePlugin_WantsMidiInput
return true;
#else
return false;
#endif
}
bool SimpMbCompAudioProcessor::producesMidi() const
{
#if JucePlugin_ProducesMidiOutput
return true;
#else
return false;
#endif
}
bool SimpMbCompAudioProcessor::isMidiEffect() const
{
#if JucePlugin_IsMidiEffect
return true;
#else
return false;
#endif
}
double SimpMbCompAudioProcessor::getTailLengthSeconds() const
{
return 0.0;
}
int SimpMbCompAudioProcessor::getNumPrograms()
{
return 1; // NB: some hosts don't cope very well if you tell them there are 0 programs,
// so this should be at least 1, even if you're not really implementing programs.
}
int SimpMbCompAudioProcessor::getCurrentProgram()
{
return 0;
}
void SimpMbCompAudioProcessor::setCurrentProgram (int index)
{
}
const juce::String SimpMbCompAudioProcessor::getProgramName (int index)
{
return {};
}
void SimpMbCompAudioProcessor::changeProgramName (int index, const juce::String& newName)
{
}
//==============================================================================
void SimpMbCompAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
{
// Use this method as the place to do any pre-playback
// initialisation that you need..
juce::dsp::ProcessSpec spec;
spec.maximumBlockSize = samplesPerBlock;
spec.numChannels = getTotalNumOutputChannels();
spec.sampleRate = sampleRate;
comperessor.prepare(spec);
leftChain.prepare(spec);
rightChain.prepare(spec);
}
void SimpMbCompAudioProcessor::releaseResources()
{
// When playback stops, you can use this as an opportunity to free up any
// spare memory, etc.
}
#ifndef JucePlugin_PreferredChannelConfigurations
bool SimpMbCompAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
{
#if JucePlugin_IsMidiEffect
juce::ignoreUnused (layouts);
return true;
#else
// This is the place where you check if the layout is supported.
// In this template code we only support mono or stereo.
// Some plugin hosts, such as certain GarageBand versions, will only
// load plugins that support stereo bus layouts.
if (layouts.getMainOutputChannelSet() != juce::AudioChannelSet::mono()
&& layouts.getMainOutputChannelSet() != juce::AudioChannelSet::stereo())
return false;
// This checks if the input layout matches the output layout
#if ! JucePlugin_IsSynth
if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
return false;
#endif
return true;
#endif
}
#endif
void SimpMbCompAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
{
juce::ScopedNoDenormals noDenormals;
auto totalNumInputChannels = getTotalNumInputChannels();
auto totalNumOutputChannels = getTotalNumOutputChannels();
// In case we have more outputs than inputs, this code clears any output
// channels that didn't contain input data, (because these aren't
// guaranteed to be empty - they may contain garbage).
// This is here to avoid people getting screaming feedback
// when they first compile a plugin, but obviously you don't need to keep
// this code if your algorithm always overwrites all the output channels.
for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
buffer.clear (i, 0, buffer.getNumSamples());
comperessor.setAttack(attack->get());
comperessor.setRelease(release->get());
comperessor.setThreshold(threshold->get());
comperessor.setRatio(ratio->getCurrentChoiceName().getFloatValue());
auto block = juce::dsp::AudioBlock<float>(buffer);
auto context = juce::dsp::ProcessContextReplacing<float>(block);
context.isBypassed = bypassed->get();
comperessor.process(context);
auto leftBlock = block.getSingleChannelBlock(0);
auto rightBlock = block.getSingleChannelBlock(1);
juce::dsp::ProcessContextReplacing<float> leftContext(leftBlock);
juce::dsp::ProcessContextReplacing<float> rightContext(rightBlock);
leftChain.process(leftContext);
rightChain.process(rightContext);
}
//==============================================================================
bool SimpMbCompAudioProcessor::hasEditor() const
{
return true; // (change this to false if you choose to not supply an editor)
}
juce::AudioProcessorEditor* SimpMbCompAudioProcessor::createEditor()
{
// return new SimpMbCompAudioProcessorEditor (*this);
return new juce::GenericAudioProcessorEditor(*this);
}
//==============================================================================
void SimpMbCompAudioProcessor::getStateInformation (juce::MemoryBlock& destData)
{
juce::MemoryOutputStream mos(destData, true);
apvts.state.writeToStream(mos);
}
void SimpMbCompAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{
// You should use this method to restore your parameters from this memory block,
// whose contents will have been created by the getStateInformation() call.
auto tree = juce::ValueTree::readFromData(data, sizeInBytes);
if(tree.isValid())
{
apvts.replaceState(tree);
}
}
juce::AudioProcessorValueTreeState::ParameterLayout SimpMbCompAudioProcessor::createParameterLayout()
{
APVTS::ParameterLayout layout;
using namespace juce;
layout.add(std::make_unique<AudioParameterFloat>("Threshold", "Threshold", NormalisableRange<float>(-16, 12, 1, 1),
0));
auto attackReleaseRange = NormalisableRange<float>(5, 500, 1, 1);
layout.add(std::make_unique <AudioParameterFloat>("Attack", "Attack", attackReleaseRange, 50));
layout.add(std::make_unique<AudioParameterFloat>("Release", "Release", attackReleaseRange,
250));
auto choices = std::vector<double>{ 1,1.5,2,3,4,5,6,7,8,10,15,20,50,100 };
juce::StringArray sa;
for (auto choice : choices)
{
sa.add(juce::String(choice, 1));
}
layout.add(std::make_unique<AudioParameterChoice>("Ratio", "Ratio", sa, 3));
layout.add(std::make_unique<AudioParameterBool>("Bypassed", "Bypassed", false));
return layout;
}
//==============================================================================
// This creates new instances of the plugin..
juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter()
{
return new SimpMbCompAudioProcessor();
}