remove a bunch of explicit uses of '/' as a directory separator; use Glib::build_file...
[ardour2.git] / libs / soundtouch / FIRFilter.h
blob7cd265d59236e87c28e10f931a88d1be8eb2a642
1 ////////////////////////////////////////////////////////////////////////////////
2 ///
3 /// General FIR digital filter routines with MMX optimization.
4 ///
5 /// Note : MMX optimized functions reside in a separate, platform-specific file,
6 /// e.g. 'mmx_win.cpp' or 'mmx_gcc.cpp'
7 ///
8 /// Author : Copyright (c) Olli Parviainen
9 /// Author e-mail : oparviai @ iki.fi
10 /// SoundTouch WWW: http://www.iki.fi/oparviai/soundtouch
11 ///
12 ////////////////////////////////////////////////////////////////////////////////
14 // Last changed : $Date$
15 // File revision : $Revision$
17 // $Id$
19 ////////////////////////////////////////////////////////////////////////////////
21 // License :
23 // SoundTouch audio processing library
24 // Copyright (c) Olli Parviainen
26 // This library is free software; you can redistribute it and/or
27 // modify it under the terms of the GNU Lesser General Public
28 // License as published by the Free Software Foundation; either
29 // version 2.1 of the License, or (at your option) any later version.
31 // This library is distributed in the hope that it will be useful,
32 // but WITHOUT ANY WARRANTY; without even the implied warranty of
33 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
34 // Lesser General Public License for more details.
36 // You should have received a copy of the GNU Lesser General Public
37 // License along with this library; if not, write to the Free Software
38 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
40 ////////////////////////////////////////////////////////////////////////////////
42 #ifndef FIRFilter_H
43 #define FIRFilter_H
45 #include "STTypes.h"
47 namespace soundtouch
50 class FIRFilter
52 protected:
53 // Number of FIR filter taps
54 uint length;
55 // Number of FIR filter taps divided by 8
56 uint lengthDiv8;
58 // Result divider factor in 2^k format
59 uint resultDivFactor;
61 // Result divider value.
62 SAMPLETYPE resultDivider;
64 // Memory for filter coefficients
65 SAMPLETYPE *filterCoeffs;
67 virtual uint evaluateFilterStereo(SAMPLETYPE *dest,
68 const SAMPLETYPE *src,
69 uint numSamples) const;
70 virtual uint evaluateFilterMono(SAMPLETYPE *dest,
71 const SAMPLETYPE *src,
72 uint numSamples) const;
74 FIRFilter();
76 public:
77 virtual ~FIRFilter();
79 static FIRFilter *newInstance();
81 /// Applies the filter to the given sequence of samples.
82 /// Note : The amount of outputted samples is by value of 'filter_length'
83 /// smaller than the amount of input samples.
84 ///
85 /// \return Number of samples copied to 'dest'.
86 uint evaluate(SAMPLETYPE *dest,
87 const SAMPLETYPE *src,
88 uint numSamples,
89 uint numChannels) const;
91 uint getLength() const;
93 virtual void setCoefficients(const SAMPLETYPE *coeffs,
94 uint newLength,
95 uint uResultDivFactor);
99 // Optional subclasses that implement CPU-specific optimizations:
101 #ifdef ALLOW_MMX
103 /// Class that implements MMX optimized functions exclusive for 16bit integer samples type.
104 class FIRFilterMMX : public FIRFilter
106 protected:
107 short *filterCoeffsUnalign;
108 short *filterCoeffsAlign;
110 virtual uint evaluateFilterStereo(short *dest, const short *src, uint numSamples) const;
111 public:
112 FIRFilterMMX();
113 ~FIRFilterMMX();
115 virtual void setCoefficients(const short *coeffs, uint newLength, uint uResultDivFactor);
118 #endif // ALLOW_MMX
121 #ifdef ALLOW_3DNOW
123 /// Class that implements 3DNow! optimized functions exclusive for floating point samples type.
124 class FIRFilter3DNow : public FIRFilter
126 protected:
127 float *filterCoeffsUnalign;
128 float *filterCoeffsAlign;
130 virtual uint evaluateFilterStereo(float *dest, const float *src, uint numSamples) const;
131 public:
132 FIRFilter3DNow();
133 ~FIRFilter3DNow();
134 virtual void setCoefficients(const float *coeffs, uint newLength, uint uResultDivFactor);
137 #endif // ALLOW_3DNOW
140 #ifdef ALLOW_SSE
141 /// Class that implements SSE optimized functions exclusive for floating point samples type.
142 class FIRFilterSSE : public FIRFilter
144 protected:
145 float *filterCoeffsUnalign;
146 float *filterCoeffsAlign;
148 virtual uint evaluateFilterStereo(float *dest, const float *src, uint numSamples) const;
149 public:
150 FIRFilterSSE();
151 ~FIRFilterSSE();
153 virtual void setCoefficients(const float *coeffs, uint newLength, uint uResultDivFactor);
156 #endif // ALLOW_SSE
160 #endif // FIRFilter_H