annotate dsp/signalconditioning/Filter.h @ 417:fa851e147e3f

Faster filter implementation with explicit FIR support
author Chris Cannam <c.cannam@qmul.ac.uk>
date Wed, 07 Oct 2015 10:36:09 +0100
parents f5b5f64835b9
children ccd2019190bf
rev   line source
c@225 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
c@225 2
c@225 3 /*
c@225 4 QM DSP Library
c@225 5
c@225 6 Centre for Digital Music, Queen Mary, University of London.
c@309 7
c@309 8 This program is free software; you can redistribute it and/or
c@309 9 modify it under the terms of the GNU General Public License as
c@309 10 published by the Free Software Foundation; either version 2 of the
c@309 11 License, or (at your option) any later version. See the file
c@309 12 COPYING included with this distribution for more information.
c@225 13 */
c@225 14
c@225 15 #ifndef FILTER_H
c@225 16 #define FILTER_H
c@225 17
c@417 18 #include <vector>
c@225 19
c@417 20 class Filter
c@225 21 {
c@225 22 public:
c@417 23 struct Parameters {
c@417 24 std::vector<double> a;
c@417 25 std::vector<double> b;
c@417 26 };
c@417 27
c@417 28 /**
c@417 29 * Construct an IIR filter with numerators b and denominators
c@417 30 * a. The filter will have order b.size()-1. To make an FIR
c@417 31 * filter, leave the vector a in the param struct empty.
c@417 32 * Otherwise, a and b must have the same number of values.
c@417 33 */
c@417 34 Filter(Parameters params);
c@417 35
c@417 36 ~Filter();
c@225 37
c@225 38 void reset();
c@225 39
c@417 40 /**
c@417 41 * Filter the input sequence \arg in of length \arg n samples, and
c@417 42 * write the resulting \arg n samples into \arg out. There must be
c@417 43 * enough room in \arg out for \arg n samples to be written.
c@417 44 */
c@417 45 void process(const double *const __restrict__ in,
c@417 46 double *const __restrict__ out,
c@417 47 const int n);
c@225 48
c@417 49 int getOrder() const { return m_order; }
c@417 50
c@225 51 private:
c@417 52 int m_order;
c@417 53 int m_sz;
c@417 54 std::vector<double> m_a;
c@417 55 std::vector<double> m_b;
c@417 56 std::vector<double> m_bufa;
c@417 57 std::vector<double> m_bufb;
c@417 58 int m_offa;
c@417 59 int m_offb;
c@417 60 int m_offmax;
c@417 61 bool m_fir;
c@225 62
c@417 63 Filter(const Filter &); // not supplied
c@417 64 Filter &operator=(const Filter &); // not supplied
c@225 65 };
c@417 66
c@225 67 #endif