quantumVERB  1.0.0
A FOSS convolution reverb plugin
Filter.h
1 /*
2 ==============================================================================
3 Filter.h
4 ==============================================================================
5 */
6 
7 #pragma once
8 
9 #include "Task.h"
10 
11 #include <memory>
12 
13 #ifndef M_PI
14 #define M_PI 3.14159265358979323846f
15 #endif
16 
17 namespace reverb
18 {
19 
20  //==============================================================================
21  /**
22  * The Filter class is the abstract class from which the three filter types of the plugin are derived.
23  */
24  class Filter : public Task,
25  protected juce::dsp::IIR::Filter<float>
26  {
27 
28  friend class Equalizer;
29  friend class EqualizerMocked;
30 
31  public:
32  //==============================================================================
33  Filter(juce::AudioProcessor * processor, float freq = 1000.0f, float q = 0.71f, float gain = 1.5f);
34 
35  //==============================================================================
36  using Ptr = std::shared_ptr<Filter>;
37 
38  //==============================================================================
39  virtual void updateParams(const juce::AudioProcessorValueTreeState& params,
40  const juce::String& blockId) override;
41 
42  virtual AudioBlock exec(AudioBlock ir) override;
43 
44  //==============================================================================
45  static float todB(float m)
46  {
47  return 20 * std::log10(m);
48  }
49 
50  //==============================================================================
51  static float invdB(float dB)
52  {
53  return pow(10, dB / 20);
54  }
55 
56  //==============================================================================
57 
58  float getAmplitude(float freq);
59  float getdBAmplitude(float freq);
60 
61  protected:
62  void setFrequency(float);
63  void setQ(float);
64  void setGain(float);
65 
66  virtual void buildFilter() = 0;
67 
68  float frequency;
69  float Q;
70  float gainFactor;
71 
72  };
73 
74 
75  //==============================================================================
76  /**
77  * This LowShelfFilter class implements a low-shelf IIR filter
78  * The inherited exec() function is used to process samples.
79  */
80  class LowShelfFilter : public Filter
81  {
82  public:
83  //==============================================================================
84  using Filter::Filter; // Inherit constructor
85 
86  //==============================================================================
87  virtual void buildFilter() override;
88  };
89 
90 
91  //==============================================================================
92  /**
93  * This HighShelfFilter class implements a high-shelf IIR filter
94  * The inherited exec() function is used to process samples.
95  */
96  class HighShelfFilter : public Filter
97  {
98  public:
99  //==============================================================================
100  using Filter::Filter; // Inherit constructor
101 
102  //==============================================================================
103  virtual void buildFilter() override;
104  };
105 
106 
107  //==============================================================================
108  /**
109  * This PeakFilter class implements a peaking IIR filter
110  * The inherited exec() function is used to process samples.
111  */
112  class PeakFilter : public Filter
113  {
114  public:
115  //==============================================================================
116  using Filter::Filter; // Inherit constructor
117 
118  //==============================================================================
119  virtual void buildFilter() override;
120  };
121 
122 }
float getdBAmplitude(float freq)
Returns the filter amplitude response in dB at a given frequency.
Definition: Filter.cpp:142
float getAmplitude(float freq)
Returns the filter absolute amplitude response at a given frequency.
Definition: Filter.cpp:109
float getParam(const juce::AudioProcessorValueTreeState &params, const juce::String &blockId) const
Internal method used to get (and check) a parameter&#39;s value.
Definition: Task.h:111
virtual void buildFilter() override
Generates and sets the peak IIR filter coefficients according to the current filter parameters...
Definition: Filter.cpp:221
void setQ(float)
Sets the filter Q factor and updates the IIR filter coefficients (Meant to be used by Equalizer class...
Definition: Filter.cpp:170
void setFrequency(float)
Sets the filter frequency and updates the IIR filter coefficients (Meant to be used by Equalizer clas...
Definition: Filter.cpp:155
virtual void updateParams(const juce::AudioProcessorValueTreeState &params, const juce::String &blockId) override
Updates parameters from processor parameter tree.
Definition: Filter.cpp:42
virtual AudioBlock exec(AudioBlock ir) override
Filters the audio in AudioSampleBuffer.
Definition: Filter.cpp:81
void setGain(float)
Sets the filter band gain and updates the IIR filter coefficients (Meant to be used by Equalizer clas...
Definition: Filter.cpp:184
virtual void buildFilter() override
Generates and sets the low-shelf IIR filter coefficients according to the current filter parameters...
Definition: Filter.cpp:197
virtual void buildFilter() override
Generates and sets the high-shelf IIR filter coefficients according to the current filter parameters...
Definition: Filter.cpp:209
Filter(juce::AudioProcessor *processor, float freq=1000.0f, float q=0.71f, float gain=1.5f)
Constructs a Filter object with optional frequency/gain/Q parameters.
Definition: Filter.cpp:29