cannam@0: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ cannam@0: cannam@0: /* cannam@0: QM DSP Library cannam@0: cannam@0: Centre for Digital Music, Queen Mary, University of London. Chris@84: Chris@84: This program is free software; you can redistribute it and/or Chris@84: modify it under the terms of the GNU General Public License as Chris@84: published by the Free Software Foundation; either version 2 of the Chris@84: License, or (at your option) any later version. See the file Chris@84: COPYING included with this distribution for more information. cannam@0: */ cannam@0: cannam@0: #ifndef FILTER_H cannam@0: #define FILTER_H cannam@0: Chris@193: #include cannam@0: Chris@193: class Filter cannam@0: { cannam@0: public: Chris@193: struct Parameters { Chris@193: std::vector a; Chris@193: std::vector b; Chris@193: }; Chris@193: Chris@193: /** Chris@193: * Construct an IIR filter with numerators b and denominators Chris@193: * a. The filter will have order b.size()-1. To make an FIR Chris@193: * filter, leave the vector a in the param struct empty. Chris@193: * Otherwise, a and b must have the same number of values. Chris@193: */ Chris@193: Filter(Parameters params); Chris@193: Chris@193: ~Filter(); cannam@0: cannam@0: void reset(); cannam@0: Chris@193: /** Chris@193: * Filter the input sequence \arg in of length \arg n samples, and Chris@193: * write the resulting \arg n samples into \arg out. There must be Chris@193: * enough room in \arg out for \arg n samples to be written. Chris@193: */ Chris@193: void process(const double *const __restrict__ in, Chris@193: double *const __restrict__ out, Chris@193: const int n); cannam@0: Chris@193: int getOrder() const { return m_order; } Chris@193: cannam@0: private: Chris@193: int m_order; Chris@193: int m_sz; Chris@193: std::vector m_a; Chris@193: std::vector m_b; Chris@193: std::vector m_bufa; Chris@193: std::vector m_bufb; Chris@193: int m_offa; Chris@193: int m_offb; Chris@193: int m_offmax; Chris@193: bool m_fir; cannam@0: Chris@193: Filter(const Filter &); // not supplied Chris@193: Filter &operator=(const Filter &); // not supplied cannam@0: }; Chris@193: cannam@0: #endif