PluginProcessor.h 5.63 KB
Newer Older
Jonathan Hyde's avatar
Jonathan Hyde committed
1 2 3 4
#ifndef PLUGINPROCESSOR_H_INCLUDED
#define PLUGINPROCESSOR_H_INCLUDED

#include "../JuceLibraryCode/JuceHeader.h"
Jonathan Hyde's avatar
Jonathan Hyde committed
5 6 7 8 9 10
#include <ATK/Core/InPointerFilter.h>
#include <ATK/EQ/ButterworthFilter.h>
#include <ATK/EQ/IIRFilter.h>
#include <ATK/Core/OutPointerFilter.h>
#include <ATK/Core/PipelineGlobalSinkFilter.h>

Jonathan Hyde's avatar
Jonathan Hyde committed
11
#define HPFORDER 2
Jonathan Hyde's avatar
Jonathan Hyde committed
12 13 14 15

//==============================================================================
/**
*/
Jonathan Hyde's avatar
Jonathan Hyde committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

class ValueSmoother
{
public:
	ValueSmoother();
	~ValueSmoother();
	void reset(double sampleRate, int samplesPerBlock, double initValue, double time);
	void setTarget(double target);
	float getNextValue();
	float getTarget();

private:
	float m_currentValue;
	float m_target;
	float m_interval;
	double m_sampleRate;
	double m_time;
	int m_samplesPerBlock;
};

Jonathan Hyde's avatar
Jonathan Hyde committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
class UtilityAudioProcessor  : public AudioProcessor
{
public:
    //==============================================================================
    UtilityAudioProcessor();
    ~UtilityAudioProcessor();

    //==============================================================================
    void prepareToPlay (double sampleRate, int samplesPerBlock) override;
    void releaseResources() override;

   #ifndef JucePlugin_PreferredChannelConfigurations
    bool isBusesLayoutSupported (const BusesLayout& layouts) const override;
   #endif

    void processBlock (AudioSampleBuffer&, MidiBuffer&) override;

    //==============================================================================
    AudioProcessorEditor* createEditor() override;
    bool hasEditor() const override;

    //==============================================================================
    const String getName() const override;

    bool acceptsMidi() const override;
    bool producesMidi() const override;
    double getTailLengthSeconds() const override;

    //==============================================================================
    int getNumPrograms() override;
    int getCurrentProgram() override;
    void setCurrentProgram (int index) override;
    const String getProgramName (int index) override;
    void changeProgramName (int index, const String& newName) override;

    //==============================================================================
    void getStateInformation (MemoryBlock& destData) override;
    void setStateInformation (const void* data, int sizeInBytes) override;

Jonathan Hyde's avatar
Jonathan Hyde committed
75 76 77 78
	AudioParameterFloat *p_panL;
	AudioParameterFloat *p_panR;
	AudioParameterFloat *p_prePan;

Jonathan Hyde's avatar
Jonathan Hyde committed
79 80 81
	AudioParameterInt *p_input;
	AudioParameterBool *p_mute;
	AudioParameterBool *p_pad;
82 83
	AudioParameterBool *p_DCoffset;

Jonathan Hyde's avatar
Jonathan Hyde committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
	AudioParameterFloat *p_gain;
	AudioParameterFloat *p_pan;

	AudioParameterFloat *p_gainL;
	AudioParameterFloat *p_gainR;
	AudioParameterBool *p_phaseL;
	AudioParameterBool *p_phaseR;
	AudioParameterBool *p_muteL;
	AudioParameterBool *p_muteR;
	
	AudioParameterFloat *p_gainM;
	AudioParameterFloat *p_gainS;
	AudioParameterFloat *p_width;
	AudioParameterBool *p_muteM;
	AudioParameterBool *p_muteS;

	AudioParameterFloat *p_lowPass;
	AudioParameterFloat *p_highPass;

	AudioParameterBool *p_hpfOn;
	AudioParameterBool *p_lpfOn;

	AudioParameterBool *p_hardClip;
	AudioParameterBool *p_softClip;

Jonathan Hyde's avatar
Jonathan Hyde committed
109
	FFAU::LevelMeterSource* getMeterSourceIn()
110 111 112
	{
		return &meterSourceIn;
	}
Jonathan Hyde's avatar
Jonathan Hyde committed
113
	FFAU::LevelMeterSource* getMeterSourceOut()
114 115 116 117
	{
		return &meterSourceOut;
	}

Jonathan Hyde's avatar
Jonathan Hyde committed
118 119
	double getFreq(float value);

Jonathan Hyde's avatar
Jonathan Hyde committed
120 121
private:
    //==============================================================================
Jonathan Hyde's avatar
Jonathan Hyde committed
122 123 124 125 126 127 128 129 130 131 132
	float m_prevPanL = 0.0f;
	float m_prevPanR = 1.0f;
	float l_prevRampGainL = 1.0f;
	float l_prevRampGainR = 0.0f;
	float r_prevRampGainL = 0.0f;
	float r_prevRampGainR = 1.0f;

	float m_prevPrePan = 0.5f;
	float m_prevPreGainL = 0.5f;
	float m_prevPreGainR = 0.5f;

Jonathan Hyde's avatar
Jonathan Hyde committed
133 134 135 136 137 138
	float m_gainF = 1.0f;
	float m_gainLF = 1.0f;
	float m_gainRF = 1.0f;
	float m_gainMF = 1.0f;
	float m_gainSF = 1.0f;

Jonathan Hyde's avatar
Jonathan Hyde committed
139 140 141 142 143 144
	float m_prevGain = 1.0f;
	float m_prevGainL = 1.0f;
	float m_prevGainR = 1.0f;
	float m_prevGainM = 1.0f;
	float m_prevGainS = 1.0f;

Jonathan Hyde's avatar
Jonathan Hyde committed
145 146 147 148 149 150
	float m_prevGainDB = 0.0f;
	float m_prevGainLDB = 0.0f;
	float m_prevGainRDB = 0.0f;
	float m_prevGainMDB = 0.0f;
	float m_prevGainSDB = 0.0f;

151 152
	bool m_firstBuffer = true;

Jonathan Hyde's avatar
Jonathan Hyde committed
153 154 155
	void convertMono(AudioSampleBuffer &buffer);
	void midSideProcess(AudioSampleBuffer &buffer);
	void clipSamples(AudioSampleBuffer &buffer);
156
	void dcOffset(AudioSampleBuffer &buffer);
Jonathan Hyde's avatar
Jonathan Hyde committed
157
	void channelPans(AudioSampleBuffer &buffer);
Jonathan Hyde's avatar
Jonathan Hyde committed
158 159 160

	AudioSampleBuffer m_midBuffer;
	AudioSampleBuffer m_sideBuffer;
Jonathan Hyde's avatar
Jonathan Hyde committed
161
	AudioSampleBuffer m_tempBuffer;
Jonathan Hyde's avatar
Jonathan Hyde committed
162

Jonathan Hyde's avatar
Jonathan Hyde committed
163 164
	float m_prevLowPass = 0.0;
	float m_prevHighPass = 100.0;
Jonathan Hyde's avatar
Jonathan Hyde committed
165

Jonathan Hyde's avatar
Jonathan Hyde committed
166
	double m_sampleRate = 44100.0f;
Jonathan Hyde's avatar
Jonathan Hyde committed
167

Jonathan Hyde's avatar
Jonathan Hyde committed
168 169
	ValueSmoother m_lowPassSmoother;
	ValueSmoother m_highPassSmoother;
Jonathan Hyde's avatar
Jonathan Hyde committed
170

171 172 173 174 175 176
	double m_prevInL = 0.0f;
	double m_prevOutL = 0.0f;
	double m_prevInR = 0.0f;
	double m_prevOutR = 0.0f;
	double m_eps; 

Jonathan Hyde's avatar
Jonathan Hyde committed
177 178
	FFAU::LevelMeterSource meterSourceIn;
	FFAU::LevelMeterSource meterSourceOut;
179

Jonathan Hyde's avatar
Jonathan Hyde committed
180 181
	const int hpforder = HPFORDER;

Jonathan Hyde's avatar
Jonathan Hyde committed
182 183
	bool m_monoSet;

Jonathan Hyde's avatar
Jonathan Hyde committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
	ATK::InPointerFilter<float> inFilterL;
	ATK::InPointerFilter<float> inFilterL2;
	ATK::InPointerFilter<float> inFilterR;
	ATK::InPointerFilter<float> inFilterR2;
	ATK::IIRFilter<ATK::ButterworthLowPassCoefficients<double> > lowpassFilterL;
	ATK::IIRTDF2Filter<ATK::ButterworthHighPassCoefficients<double> > highpassFilterL;
	ATK::IIRFilter<ATK::ButterworthLowPassCoefficients<double> > lowpassFilterR;
	ATK::IIRTDF2Filter<ATK::ButterworthHighPassCoefficients<double> > highpassFilterR;
	ATK::OutPointerFilter<float> outFilterL;
	ATK::OutPointerFilter<float> outFilterL2;
	ATK::OutPointerFilter<float> outFilterR;
	ATK::OutPointerFilter<float> outFilterR2;

	ATK::PipelineGlobalSinkFilter endpoint;
	ATK::PipelineGlobalSinkFilter endpoint2;

Jonathan Hyde's avatar
Jonathan Hyde committed
200 201 202 203
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (UtilityAudioProcessor)
};

#endif  // PLUGINPROCESSOR_H_INCLUDED