quantumVERB  1.0.0
A FOSS convolution reverb plugin
Equalizer.h
1 /*
2 ==============================================================================
3 
4 Equalizer.h
5 
6 ==============================================================================
7 */
8 
9 #pragma once
10 
11 #include "Task.h"
12 #include "Filter.h"
13 
14 #include <memory>
15 #include <exception>
16 #include <string>
17 
18 
19 namespace reverb {
20 
21  //==============================================================================
22  /**
23  * The Equalizer class cimplements by default four Filter class instances -one low-shelf, two peak filters and one high-shelf -
24  * and calibrates their individual gains to balance out the stacking effect thus making sure that the EQ band gains are equal to the ones set by the user.
25  *
26  *It acts as an interface between the GUI and the IIR filters.
27  *The class can support one low-shelf filter and one high-shelf with any number of peak filters in between; the total number is equal to the numFilters constructor argument.
28  *The filter instantiations are done in the class constructor.
29  */
30  class Equalizer : public Task
31  {
32 
33  public:
34 
35  Equalizer(juce::AudioProcessor * processor, int numFilters = 4);
36  virtual void updateParams(const juce::AudioProcessorValueTreeState& params,
37  const juce::String& blockId) override;
38 
39  using Ptr = std::shared_ptr<Equalizer>;
40 
41 
42  virtual AudioBlock exec(AudioBlock ir) override;
43 
44  virtual void updateSampleRate(double sr) override;
45 
46 
47  void calibrateFilters();
48 
49  float getdBAmplitude(float freq);
50 
51  int getNumFilters();
52  virtual bool needsToRun() const override;
53 
54 
55  protected:
56  juce::OwnedArray<Filter> filterSet;
57  std::vector<float> EQGains;
58  };
59 
60  struct InvalidFilterException : public std::exception
61  {
62  const char * what() const throw ()
63  {
64  return "Equalizer: Filter ID is invalid";
65  }
66  };
67 
68  struct ConvergenceException : public std::exception
69  {
70  const char * what() const throw ()
71  {
72  return "Equalizer: The calibration algorithm did not converge";
73  }
74  };
75 }
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
void calibrateFilters()
Calibrates the individual filter gains so that the total gains are equal to the user defined values...
Definition: Equalizer.cpp:138
float getdBAmplitude(float freq)
Returns the Equalizer amplitude response in dB at a given frequency.
Definition: Equalizer.cpp:232
int getNumFilters()
Returns the number of filters in the equalizer.
Definition: Equalizer.cpp:250
virtual void updateSampleRate(double sr) override
Update sample rate for task block.
Definition: Equalizer.cpp:119
virtual bool needsToRun() const override
Tells caller whether block must be run for current block.
Definition: Equalizer.cpp:255
virtual AudioBlock exec(AudioBlock ir) override
Processes the AudioBuffer input with the EQ filters.
Definition: Equalizer.cpp:106
virtual void updateParams(const juce::AudioProcessorValueTreeState &params, const juce::String &blockId) override
Read processor parameters and update block parameters as necessary.
Definition: Equalizer.cpp:66