23 #pragma GCC diagnostic push 24 #pragma GCC diagnostic ignored "-Wignored-attributes" 25 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 26 #include <Eigen/Dense> 27 #include <unsupported/Eigen/FFT> 28 #pragma GCC diagnostic pop 30 #define FIR_BLOCKSIZE_MISMATCH_ERROR FIR_ERROR_OFFSET-1 31 #define FIR_H_EMPTY_ERROR FIR_ERROR_OFFSET-2 32 #define FIR_CHANNEL_MISMATCH_ERROR FIR_ERROR_OFFSET-3 41 errors[
FIR_H_EMPTY_ERROR]=std::string(
"The fileter h is empty, please load using loadTimeDomainCoefficients. ");
62 Eigen::FFT<FP_TYPE>
fft;
63 Eigen::Array<Eigen::FFT<FP_TYPE>::Complex, Eigen::Dynamic, Eigen::Dynamic>
H;
64 Eigen::Matrix<FP_TYPE, Eigen::Dynamic, Eigen::Dynamic>
h;
65 Eigen::Matrix<FP_TYPE, Eigen::Dynamic, Eigen::Dynamic>
x;
66 Eigen::Matrix<FP_TYPE, Eigen::Dynamic, 1>
yTemp;
67 Eigen::Array<Eigen::FFT<FP_TYPE>::Complex, Eigen::Dynamic, 1>
Y;
74 Eigen::Matrix<FP_TYPE, Eigen::Dynamic, Eigen::Dynamic>
y;
81 void init(
unsigned int blockSize);
88 int loadTimeDomainCoefficients(
const std::string fileName);
94 void loadTimeDomainCoefficients(
const Eigen::Matrix<FP_TYPE, Eigen::Dynamic, Eigen::Dynamic> hIn);
101 template<
typename Derived,
typename DerivedOther>
102 void filter(
const Eigen::MatrixBase<Derived> &input, Eigen::DenseBase<DerivedOther>
const &output) {
103 if (input.rows()!=
N){
107 if (input.cols()!=h.cols() || output.cols() != h.cols()){
116 if (x.cols() != input.cols()){
117 x.setZero(h.rows(), input.cols());
118 y.setZero(h.rows(), input.cols());
120 y.topRows(y.rows()-
N)=y.bottomRows(y.rows()-
N);
121 y.bottomRows(N).setZero();
125 for (
int i=0; i<x.cols(); i++){
126 fft.fwd(Y.data(), x.col(i).data(), x.rows());
128 fft.inv(yTemp.data(), Y.data(), Y.rows());
131 const_cast< Eigen::DenseBase<DerivedOther>&
>(output)=y.topRows(N);
void filter(const Eigen::MatrixBase< Derived > &input, Eigen::DenseBase< DerivedOther > const &output)
Eigen::Matrix< FP_TYPE, Eigen::Dynamic, Eigen::Dynamic > x
the time domain signal for filtering
std::map< int, std::string > errors
This will contain a map between error numbers and descriptive std::strings for the errors...
Eigen::Matrix< FP_TYPE, Eigen::Dynamic, Eigen::Dynamic > h
the time domain representation of the filter
Eigen::Array< Eigen::FFT< FP_TYPE >::Complex, Eigen::Dynamic, Eigen::Dynamic > H
The DFT of the FIR coefficients.
Eigen::Matrix< FP_TYPE, Eigen::Dynamic, Eigen::Dynamic > y
the time domain output signal
Eigen::Matrix< FP_TYPE, Eigen::Dynamic, 1 > yTemp
the time domain signal for filtering
#define FIR_CHANNEL_MISMATCH_ERROR
Eigen::FFT< FP_TYPE > fft
The fast Fourier transform.
double FP_TYPE
Internal processing type.
#define FIR_H_EMPTY_ERROR
Eigen::Array< Eigen::FFT< FP_TYPE >::Complex, Eigen::Dynamic, 1 > Y
the time domain filter output and also the DFT of one col of x
unsigned int N
Block size of the audio subsystem.
#define FIR_BLOCKSIZE_MISMATCH_ERROR