Only show user-presets in favorite sidebar
[ardour.git] / libs / qm-dsp / dsp / rateconversion / Decimator.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     This file 2005-2006 Christian Landone.
7
8     This program is free software; you can redistribute it and/or
9     modify it under the terms of the GNU General Public License as
10     published by the Free Software Foundation; either version 2 of the
11     License, or (at your option) any later version.  See the file
12     COPYING included with this distribution for more information.
13 */
14
15 #ifndef DECIMATOR_H
16 #define DECIMATOR_H
17
18 /**
19  * Decimator carries out a fast downsample by a power-of-two
20  * factor. Only a limited number of factors are supported, from two to
21  * whatever getHighestSupportedFactor() returns. This is much faster
22  * than Resampler but has a worse signal-noise ratio.
23  */
24 class Decimator  
25 {
26 public:
27     /**
28      * Construct a Decimator to operate on input blocks of length
29      * inLength, with decimation factor decFactor.  inLength should be
30      * a multiple of decFactor.  Output blocks will be of length
31      * inLength / decFactor.
32      *
33      * decFactor must be a power of two.  The highest supported factor
34      * is obtained through getHighestSupportedFactor(); for higher
35      * factors, you will need to chain more than one decimator.
36      */
37     Decimator( unsigned int inLength, unsigned int decFactor );
38     virtual ~Decimator();
39
40     /**
41      * Process inLength samples (as supplied to constructor) from src
42      * and write inLength / decFactor samples to dst.  Note that src
43      * and dst may be the same or overlap (an intermediate buffer is
44      * used).
45      */
46     void process( const double* src, double* dst );
47
48     /**
49      * Process inLength samples (as supplied to constructor) from src
50      * and write inLength / decFactor samples to dst.  Note that src
51      * and dst may be the same or overlap (an intermediate buffer is
52      * used).
53      */
54     void process( const float* src, float* dst );
55
56     int getFactor() const { return m_decFactor; }
57     static int getHighestSupportedFactor() { return 8; }
58
59     void resetFilter();
60
61 private:
62     void deInitialise();
63     void initialise( unsigned int inLength, unsigned int decFactor );
64     void doAntiAlias( const double* src, double* dst, unsigned int length );
65     void doAntiAlias( const float* src, double* dst, unsigned int length );
66
67     unsigned int m_inputLength;
68     unsigned int m_outputLength;
69     unsigned int m_decFactor;
70
71     double Input;
72     double Output ;
73
74     double o1,o2,o3,o4,o5,o6,o7;
75
76     double a[ 9 ];
77     double b[ 9 ];
78         
79     double* decBuffer;
80 };
81
82 #endif //