media/libsoundtouch/src/FIRFilter.h

branch
TOR_BUG_9701
changeset 8
97036ab72558
equal deleted inserted replaced
-1:000000000000 0:21def926f4ca
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 'at' iki.fi
10 /// SoundTouch WWW: http://www.surina.net/soundtouch
11 ///
12 ////////////////////////////////////////////////////////////////////////////////
13 //
14 // Last changed : $Date: 2013-06-12 10:24:44 -0500 (Wed, 12 Jun 2013) $
15 // File revision : $Revision: 4 $
16 //
17 // $Id: FIRFilter.h 171 2013-06-12 15:24:44Z oparviai $
18 //
19 ////////////////////////////////////////////////////////////////////////////////
20 //
21 // License :
22 //
23 // SoundTouch audio processing library
24 // Copyright (c) Olli Parviainen
25 //
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.
30 //
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.
35 //
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
39 //
40 ////////////////////////////////////////////////////////////////////////////////
41
42 #ifndef FIRFilter_H
43 #define FIRFilter_H
44
45 #include <stddef.h>
46 #include "STTypes.h"
47
48 namespace soundtouch
49 {
50
51 class FIRFilter
52 {
53 protected:
54 // Number of FIR filter taps
55 uint length;
56 // Number of FIR filter taps divided by 8
57 uint lengthDiv8;
58
59 // Result divider factor in 2^k format
60 uint resultDivFactor;
61
62 // Result divider value.
63 SAMPLETYPE resultDivider;
64
65 // Memory for filter coefficients
66 SAMPLETYPE *filterCoeffs;
67
68 virtual uint evaluateFilterStereo(SAMPLETYPE *dest,
69 const SAMPLETYPE *src,
70 uint numSamples) const;
71 virtual uint evaluateFilterMono(SAMPLETYPE *dest,
72 const SAMPLETYPE *src,
73 uint numSamples) const;
74 virtual uint evaluateFilterMulti(SAMPLETYPE *dest, const SAMPLETYPE *src, uint numSamples, uint numChannels) const;
75
76 public:
77 FIRFilter();
78 virtual ~FIRFilter();
79
80 /// Operator 'new' is overloaded so that it automatically creates a suitable instance
81 /// depending on if we've a MMX-capable CPU available or not.
82 static void * operator new(size_t s);
83
84 static FIRFilter *newInstance();
85
86 /// Applies the filter to the given sequence of samples.
87 /// Note : The amount of outputted samples is by value of 'filter_length'
88 /// smaller than the amount of input samples.
89 ///
90 /// \return Number of samples copied to 'dest'.
91 uint evaluate(SAMPLETYPE *dest,
92 const SAMPLETYPE *src,
93 uint numSamples,
94 uint numChannels) const;
95
96 uint getLength() const;
97
98 virtual void setCoefficients(const SAMPLETYPE *coeffs,
99 uint newLength,
100 uint uResultDivFactor);
101 };
102
103
104 // Optional subclasses that implement CPU-specific optimizations:
105
106 #ifdef SOUNDTOUCH_ALLOW_MMX
107
108 /// Class that implements MMX optimized functions exclusive for 16bit integer samples type.
109 class FIRFilterMMX : public FIRFilter
110 {
111 protected:
112 short *filterCoeffsUnalign;
113 short *filterCoeffsAlign;
114
115 virtual uint evaluateFilterStereo(short *dest, const short *src, uint numSamples) const;
116 public:
117 FIRFilterMMX();
118 ~FIRFilterMMX();
119
120 virtual void setCoefficients(const short *coeffs, uint newLength, uint uResultDivFactor);
121 };
122
123 #endif // SOUNDTOUCH_ALLOW_MMX
124
125
126 #ifdef SOUNDTOUCH_ALLOW_SSE
127 /// Class that implements SSE optimized functions exclusive for floating point samples type.
128 class FIRFilterSSE : public FIRFilter
129 {
130 protected:
131 float *filterCoeffsUnalign;
132 float *filterCoeffsAlign;
133
134 virtual uint evaluateFilterStereo(float *dest, const float *src, uint numSamples) const;
135 public:
136 FIRFilterSSE();
137 ~FIRFilterSSE();
138
139 virtual void setCoefficients(const float *coeffs, uint newLength, uint uResultDivFactor);
140 };
141
142 #endif // SOUNDTOUCH_ALLOW_SSE
143
144 }
145
146 #endif // FIRFilter_H

mercurial