29 Filter::
Filter(juce::AudioProcessor * processor,
float freq,
float q,
float gain)
43 const juce::String& blockId)
46 float _frequency = getParam(params,
47 blockId + AudioProcessor::PID_FILTER_FREQ_SUFFIX);
49 if (frequency != _frequency)
51 frequency = _frequency;
57 float _Q = getParam(params,
58 blockId + AudioProcessor::PID_FILTER_Q_SUFFIX);
85 if (ir.getNumChannels() != 1)
87 logger.dualPrint(Logger::Level::Warning,
"Filter: AudioBuffer channel count is not 1");
91 juce::dsp::ProcessContextReplacing<
float> context(ir);
92 juce::dsp::IIR::Filter<
float>::process(context);
111 float * coeffs = coefficients->getRawCoefficients();
113 float b0 = coeffs[0];
114 float b1 = coeffs[1];
115 float b2 = coeffs[2];
116 float a1 = coeffs[3];
117 float a2 = coeffs[4];
120 std::complex<
float> input;
121 std::complex<
float> output;
123 float minusOmega = -(2 *
M_PI * freq) / processor->getSampleRate();
125 input.real(std::cos(minusOmega));
126 input.imag(std::sin(minusOmega));
130 return std::abs(b0 + b1 * input + b2 * std::pow(input, 2)) / std::abs(1.0f + a1 * input + a2 * std::pow(input, 2));
200 coefficients = juce::dsp::IIR::Coefficients<
float>::makeLowShelf(processor->getSampleRate(),
201 frequency, Q, gainFactor);
212 coefficients = juce::dsp::IIR::Coefficients<
float>::makeHighShelf(processor->getSampleRate(),
213 frequency, Q, gainFactor);
224 coefficients = juce::dsp::IIR::Coefficients<
float>::makePeakFilter(processor->getSampleRate(),
225 frequency, Q, gainFactor);
float getdBAmplitude(float freq)
Returns the filter amplitude response in dB at a given frequency.
float getAmplitude(float freq)
Returns the filter absolute amplitude response at a given frequency.
float getParam(const juce::AudioProcessorValueTreeState ¶ms, const juce::String &blockId) const
Internal method used to get (and check) a parameter's value.
virtual void buildFilter() override
Generates and sets the peak IIR filter coefficients according to the current filter parameters...
void setQ(float)
Sets the filter Q factor and updates the IIR filter coefficients (Meant to be used by Equalizer class...
void setFrequency(float)
Sets the filter frequency and updates the IIR filter coefficients (Meant to be used by Equalizer clas...
virtual void updateParams(const juce::AudioProcessorValueTreeState ¶ms, const juce::String &blockId) override
Updates parameters from processor parameter tree.
virtual AudioBlock exec(AudioBlock ir) override
Filters the audio in AudioSampleBuffer.
void setGain(float)
Sets the filter band gain and updates the IIR filter coefficients (Meant to be used by Equalizer clas...
virtual void buildFilter() override
Generates and sets the low-shelf IIR filter coefficients according to the current filter parameters...
virtual void buildFilter() override
Generates and sets the high-shelf IIR filter coefficients according to the current filter parameters...
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.