comparison 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
comparison
equal deleted inserted replaced
416:1f3244a6884c 417:fa851e147e3f
2 2
3 /* 3 /*
4 QM DSP Library 4 QM DSP Library
5 5
6 Centre for Digital Music, Queen Mary, University of London. 6 Centre for Digital Music, Queen Mary, University of London.
7 This file 2005-2006 Christian Landone.
8 7
9 This program is free software; you can redistribute it and/or 8 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as 9 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the 10 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file 11 License, or (at your option) any later version. See the file
14 */ 13 */
15 14
16 #ifndef FILTER_H 15 #ifndef FILTER_H
17 #define FILTER_H 16 #define FILTER_H
18 17
19 #ifndef NULL 18 #include <vector>
20 #define NULL 0
21 #endif
22 19
23 /** 20 class Filter
24 * Filter specification. For a filter of order ord, the ACoeffs and
25 * BCoeffs arrays must point to ord+1 values each. ACoeffs provides
26 * the denominator and BCoeffs the numerator coefficients of the
27 * filter.
28 */
29 struct FilterConfig{
30 unsigned int ord;
31 double* ACoeffs;
32 double* BCoeffs;
33 };
34
35 /**
36 * Digital filter specified through FilterConfig structure.
37 */
38 class Filter
39 { 21 {
40 public: 22 public:
41 Filter( FilterConfig Config ); 23 struct Parameters {
42 virtual ~Filter(); 24 std::vector<double> a;
25 std::vector<double> b;
26 };
27
28 /**
29 * Construct an IIR filter with numerators b and denominators
30 * a. The filter will have order b.size()-1. To make an FIR
31 * filter, leave the vector a in the param struct empty.
32 * Otherwise, a and b must have the same number of values.
33 */
34 Filter(Parameters params);
35
36 ~Filter();
43 37
44 void reset(); 38 void reset();
45 39
46 void process( double *src, double *dst, unsigned int length ); 40 /**
41 * Filter the input sequence \arg in of length \arg n samples, and
42 * write the resulting \arg n samples into \arg out. There must be
43 * enough room in \arg out for \arg n samples to be written.
44 */
45 void process(const double *const __restrict__ in,
46 double *const __restrict__ out,
47 const int n);
47 48
49 int getOrder() const { return m_order; }
50
48 private: 51 private:
49 void initialise( FilterConfig Config ); 52 int m_order;
50 void deInitialise(); 53 int m_sz;
54 std::vector<double> m_a;
55 std::vector<double> m_b;
56 std::vector<double> m_bufa;
57 std::vector<double> m_bufb;
58 int m_offa;
59 int m_offb;
60 int m_offmax;
61 bool m_fir;
51 62
52 unsigned int m_ord; 63 Filter(const Filter &); // not supplied
53 64 Filter &operator=(const Filter &); // not supplied
54 double* m_inBuffer;
55 double* m_outBuffer;
56
57 double* m_ACoeffs;
58 double* m_BCoeffs;
59 }; 65 };
60 66
61 #endif 67 #endif