update qm-dsp library
[ardour.git] / libs / qm-dsp / dsp / rateconversion / DecimatorB.h
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2 /*
3     QM DSP Library
4
5     Centre for Digital Music, Queen Mary, University of London.
6
7     This program is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License as
9     published by the Free Software Foundation; either version 2 of the
10     License, or (at your option) any later version.  See the file
11     COPYING included with this distribution for more information.
12 */
13
14 #ifndef DECIMATORB_H
15 #define DECIMATORB_H
16
17 #include <vector>
18
19 /**
20  * DecimatorB carries out a fast downsample by a power-of-two
21  * factor. It only knows how to decimate by a factor of 2, and will
22  * use repeated decimation for higher factors. A Butterworth filter of
23  * order 6 is used for the lowpass filter.
24  */
25 class DecimatorB
26 {
27 public:
28     void process( const double* src, double* dst );
29     void process( const float* src, float* dst );
30
31     /**
32      * Construct a DecimatorB to operate on input blocks of length
33      * inLength, with decimation factor decFactor.  inLength should be
34      * a multiple of decFactor.  Output blocks will be of length
35      * inLength / decFactor.
36      *
37      * decFactor must be a power of two.
38      */
39     DecimatorB(int inLength, int decFactor);
40     virtual ~DecimatorB();
41
42     int getFactor() const { return m_decFactor; }
43
44 private:
45     void deInitialise();
46     void initialise(int inLength, int decFactor);
47     void doAntiAlias(const double* src, double* dst, int length, int filteridx);
48     void doProcess();
49
50     int m_inputLength;
51     int m_outputLength;
52     int m_decFactor;
53
54     std::vector<std::vector<double> > m_o;
55
56     double m_a[7];
57     double m_b[7];
58         
59     double *m_aaBuffer;
60     double *m_tmpBuffer;
61 };
62
63 #endif
64