-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginProcessor.h
More file actions
171 lines (137 loc) · 6.18 KB
/
PluginProcessor.h
File metadata and controls
171 lines (137 loc) · 6.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
75
76
77
78
79
80
81
82
83
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
==============================================================================
This file contains the basic framework code for a JUCE plugin processor.
==============================================================================
*/
#pragma once
#include <JuceHeader.h>
#include "DSP/SingleChannelSampleFifo.h"
#include <array>
enum Slope
{
Slope_12,
Slope_24,
Slope_36,
Slope_48
};
struct ChainSettings
{
float peak1Freq { 0 }, peak1GainInDecibels{ 0 }, peak1Quality {1.f};
float peak2Freq { 0 }, peak2GainInDecibels{ 0 }, peak2Quality {1.f};
float peak3Freq { 0 }, peak3GainInDecibels{ 0 }, peak3Quality {1.f};
float lowCutFreq { 0 }, highCutFreq { 0 };
Slope lowCutSlope { Slope::Slope_12 }, highCutSlope { Slope::Slope_12 };
bool lowCutBypassed { false }, peak1Bypassed { false }, peak2Bypassed { false }, peak3Bypassed { false }, highCutBypassed { false };
};
ChainSettings getChainSettings(juce::AudioProcessorValueTreeState& apvts);
using Filter = juce::dsp::IIR::Filter<float>;
using CutFilter = juce::dsp::ProcessorChain<Filter, Filter, Filter, Filter>;
using MonoChain = juce::dsp::ProcessorChain<CutFilter, Filter, Filter, Filter, CutFilter>;
enum ChainPositions
{
LowCut,
Peak1,
Peak2,
Peak3,
HighCut
};
using Coefficients = Filter::CoefficientsPtr;
void updateCoefficients(Coefficients& old, const Coefficients& replacements);
//Coefficients makePeakFilter(const ChainSettings& chainSettings, double sampleRate);
Coefficients makePeakFilter(float freq, float quality, float decibels, double sampleRate);
template<int Index, typename ChainType, typename CoefficientType>
void update(ChainType& chain, const CoefficientType& coefficients)
{
updateCoefficients(chain.template get<Index>().coefficients, coefficients[Index]);
chain.template setBypassed<Index>(false);
}
template<typename ChainType, typename CoefficientType>
void updateCutFilter(ChainType& chain,
const CoefficientType& coefficients,
const Slope& slope)
{
chain.template setBypassed<0>(true);
chain.template setBypassed<1>(true);
chain.template setBypassed<2>(true);
chain.template setBypassed<3>(true);
switch( slope )
{
case Slope_48:
{
update<3>(chain, coefficients);
}
case Slope_36:
{
update<2>(chain, coefficients);
}
case Slope_24:
{
update<1>(chain, coefficients);
}
case Slope_12:
{
update<0>(chain, coefficients);
}
}
}
inline auto makeLowCutFilter(const ChainSettings& chainSettings, double sampleRate )
{
return juce::dsp::FilterDesign<float>::designIIRHighpassHighOrderButterworthMethod(chainSettings.lowCutFreq,
sampleRate,
2 * (chainSettings.lowCutSlope + 1));
}
inline auto makeHighCutFilter(const ChainSettings& chainSettings, double sampleRate )
{
return juce::dsp::FilterDesign<float>::designIIRLowpassHighOrderButterworthMethod(chainSettings.highCutFreq,
sampleRate,
2 * (chainSettings.highCutSlope + 1));
}
//==============================================================================
/**
*/
class SimpleEQAudioProcessor : public juce::AudioProcessor
{
public:
//==============================================================================
SimpleEQAudioProcessor();
~SimpleEQAudioProcessor() 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;
static juce::AudioProcessorValueTreeState::ParameterLayout createParameterLayout();
juce::AudioProcessorValueTreeState apvts {*this, nullptr, "Parameters", createParameterLayout()};
using BlockType = juce::AudioBuffer<float>;
SingleChannelSampleFifo<BlockType> leftChannelFifo { Channel::Left };
SingleChannelSampleFifo<BlockType> rightChannelFifo { Channel::Right };
private:
MonoChain leftChain, rightChain;
void updatePeakFilter(const ChainSettings& chainSettings);
void updateLowCutFilters(const ChainSettings& chainSettings);
void updateHighCutFilters(const ChainSettings& chainSettings);
void updateFilters();
juce::dsp::Oscillator<float> osc;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SimpleEQAudioProcessor)
};