FIRFilter.h (4498B)
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 // License : 15 // 16 // SoundTouch audio processing library 17 // Copyright (c) Olli Parviainen 18 // 19 // This library is free software; you can redistribute it and/or 20 // modify it under the terms of the GNU Lesser General Public 21 // License as published by the Free Software Foundation; either 22 // version 2.1 of the License, or (at your option) any later version. 23 // 24 // This library is distributed in the hope that it will be useful, 25 // but WITHOUT ANY WARRANTY; without even the implied warranty of 26 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 // Lesser General Public License for more details. 28 // 29 // You should have received a copy of the GNU Lesser General Public 30 // License along with this library; if not, write to the Free Software 31 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 32 // 33 //////////////////////////////////////////////////////////////////////////////// 34 35 #ifndef FIRFilter_H 36 #define FIRFilter_H 37 38 #include <stddef.h> 39 #include "STTypes.h" 40 41 namespace soundtouch 42 { 43 44 class FIRFilter 45 { 46 protected: 47 // Number of FIR filter taps 48 uint length; 49 // Number of FIR filter taps divided by 8 50 uint lengthDiv8; 51 52 // Result divider factor in 2^k format 53 uint resultDivFactor; 54 55 // Result divider value. 56 SAMPLETYPE resultDivider; 57 58 // Memory for filter coefficients 59 SAMPLETYPE *filterCoeffs; 60 SAMPLETYPE *filterCoeffsStereo; 61 62 virtual uint evaluateFilterStereo(SAMPLETYPE *dest, 63 const SAMPLETYPE *src, 64 uint numSamples) const; 65 virtual uint evaluateFilterMono(SAMPLETYPE *dest, 66 const SAMPLETYPE *src, 67 uint numSamples) const; 68 virtual uint evaluateFilterMulti(SAMPLETYPE *dest, const SAMPLETYPE *src, uint numSamples, uint numChannels); 69 70 public: 71 FIRFilter(); 72 virtual ~FIRFilter(); 73 74 /// Operator 'new' is overloaded so that it automatically creates a suitable instance 75 /// depending on if we've a MMX-capable CPU available or not. 76 static void * operator new(size_t s); 77 78 static FIRFilter *newInstance(); 79 80 /// Applies the filter to the given sequence of samples. 81 /// Note : The amount of outputted samples is by value of 'filter_length' 82 /// smaller than the amount of input samples. 83 /// 84 /// \return Number of samples copied to 'dest'. 85 uint evaluate(SAMPLETYPE *dest, 86 const SAMPLETYPE *src, 87 uint numSamples, 88 uint numChannels); 89 90 uint getLength() const; 91 92 virtual void setCoefficients(const SAMPLETYPE *coeffs, 93 uint newLength, 94 uint uResultDivFactor); 95 }; 96 97 98 // Optional subclasses that implement CPU-specific optimizations: 99 100 #ifdef SOUNDTOUCH_ALLOW_MMX 101 102 /// Class that implements MMX optimized functions exclusive for 16bit integer samples type. 103 class FIRFilterMMX : public FIRFilter 104 { 105 protected: 106 short *filterCoeffsUnalign; 107 short *filterCoeffsAlign; 108 109 virtual uint evaluateFilterStereo(short *dest, const short *src, uint numSamples) const; 110 public: 111 FIRFilterMMX(); 112 ~FIRFilterMMX(); 113 114 virtual void setCoefficients(const short *coeffs, uint newLength, uint uResultDivFactor); 115 }; 116 117 #endif // SOUNDTOUCH_ALLOW_MMX 118 119 120 #ifdef SOUNDTOUCH_ALLOW_SSE 121 /// Class that implements SSE optimized functions exclusive for floating point samples type. 122 class FIRFilterSSE : public FIRFilter 123 { 124 protected: 125 float *filterCoeffsUnalign; 126 float *filterCoeffsAlign; 127 128 virtual uint evaluateFilterStereo(float *dest, const float *src, uint numSamples) const; 129 public: 130 FIRFilterSSE(); 131 ~FIRFilterSSE(); 132 133 virtual void setCoefficients(const float *coeffs, uint newLength, uint uResultDivFactor); 134 }; 135 136 #endif // SOUNDTOUCH_ALLOW_SSE 137 138 } 139 140 #endif // FIRFilter_H