77 lines
2.1 KiB
C++
77 lines
2.1 KiB
C++
#pragma once
|
|
#include "lasp_filter.h"
|
|
|
|
/**
|
|
* @brief A set of Biquad filters in series.
|
|
*/
|
|
class SeriesBiquad : public Filter {
|
|
|
|
/// The filter coefficients for each of the filters in the Filterbank
|
|
/// The *first* axis is the filter no, the second axis contains the
|
|
/// filter coefficients, in the order, b_0, b_1, b_2, a_0, a_1, a_2, which
|
|
/// corresponds to the transfer function
|
|
/// b_0 + b_1 z^-1 + b_2 z^-2
|
|
/// H[z] = -------------------------
|
|
/// a_0 + a_1 z^-1 + a_2 z^-2
|
|
///
|
|
dmat sos; /// sos[coef, filter_no]
|
|
///
|
|
/// Storage for the current state of the output, first axis correspond to
|
|
/// the state axis, the second axis to the series filter no. For each filter
|
|
/// in series, two state coefficients are remembered.
|
|
dmat state;
|
|
|
|
public:
|
|
/**
|
|
* @brief Initalize a SeriesBiquad filter.
|
|
*
|
|
* @param filter_coefs Filter coefficients, should be given in the order as
|
|
* [b0, b1, b2, a0==1, a1, a2, b0,...]
|
|
*/
|
|
SeriesBiquad(const vd &filter_coefs);
|
|
|
|
virtual void filter(vd &inout) override final;
|
|
virtual ~SeriesBiquad() override {}
|
|
void reset() override final;
|
|
};
|
|
|
|
/**
|
|
* @brief Multiple biquad filters in parallel, each multiplied with a gain
|
|
* value, and finally all added together. This class can be used to create
|
|
* a graphic equalizer.
|
|
*/
|
|
class BiquadBank : public Filter {
|
|
std::vector<SeriesBiquad> _filters;
|
|
vd _gains;
|
|
|
|
public:
|
|
/**
|
|
* @brief Initialize biquadbank.
|
|
*
|
|
* @param filters Filters for each filter in the bank
|
|
* @param gains Gain values. Given as pointer, if not given (nulltpr), gains
|
|
* are initialized with unity gain.
|
|
*/
|
|
BiquadBank(const dmat &filters, const vd *gains = nullptr);
|
|
|
|
/**
|
|
* @brief Set new gain values for each filter in the BiquadBank
|
|
*
|
|
* @param gains Vector of gain values. Should be of same length as the number
|
|
* of filters installed.
|
|
*/
|
|
void setGains(const vd& gains);
|
|
|
|
/**
|
|
* @brief Returns the number of Filters
|
|
*
|
|
* @return The number of filters
|
|
*/
|
|
us nfilters() const {return _filters.size();}
|
|
|
|
virtual void filter(vd &inout) override final;
|
|
|
|
void reset() override final;
|
|
|
|
};
|