AAFilter.h (3154B)
1 //////////////////////////////////////////////////////////////////////////////// 2 /// 3 /// Sampled sound tempo changer/time stretch algorithm. Changes the sound tempo 4 /// while maintaining the original pitch by using a time domain WSOLA-like method 5 /// with several performance-increasing tweaks. 6 /// 7 /// Anti-alias filter is used to prevent folding of high frequencies when 8 /// transposing the sample rate with interpolation. 9 /// 10 /// Author : Copyright (c) Olli Parviainen 11 /// Author e-mail : oparviai 'at' iki.fi 12 /// SoundTouch WWW: http://www.surina.net/soundtouch 13 /// 14 //////////////////////////////////////////////////////////////////////////////// 15 // 16 // License : 17 // 18 // SoundTouch audio processing library 19 // Copyright (c) Olli Parviainen 20 // 21 // This library is free software; you can redistribute it and/or 22 // modify it under the terms of the GNU Lesser General Public 23 // License as published by the Free Software Foundation; either 24 // version 2.1 of the License, or (at your option) any later version. 25 // 26 // This library is distributed in the hope that it will be useful, 27 // but WITHOUT ANY WARRANTY; without even the implied warranty of 28 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 // Lesser General Public License for more details. 30 // 31 // You should have received a copy of the GNU Lesser General Public 32 // License along with this library; if not, write to the Free Software 33 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 34 // 35 //////////////////////////////////////////////////////////////////////////////// 36 37 #ifndef AAFilter_H 38 #define AAFilter_H 39 40 #include "STTypes.h" 41 #include "FIFOSampleBuffer.h" 42 43 namespace soundtouch 44 { 45 46 class AAFilter 47 { 48 protected: 49 class FIRFilter *pFIR; 50 51 /// Low-pass filter cut-off frequency, negative = invalid 52 double cutoffFreq; 53 54 /// num of filter taps 55 uint length; 56 57 /// Calculate the FIR coefficients realizing the given cutoff-frequency 58 void calculateCoeffs(); 59 public: 60 AAFilter(uint length); 61 62 ~AAFilter(); 63 64 /// Sets new anti-alias filter cut-off edge frequency, scaled to sampling 65 /// frequency (nyquist frequency = 0.5). The filter will cut off the 66 /// frequencies than that. 67 void setCutoffFreq(double newCutoffFreq); 68 69 /// Sets number of FIR filter taps, i.e. ~filter complexity 70 void setLength(uint newLength); 71 72 uint getLength() const; 73 74 /// Applies the filter to the given sequence of samples. 75 /// Note : The amount of outputted samples is by value of 'filter length' 76 /// smaller than the amount of input samples. 77 uint evaluate(SAMPLETYPE *dest, 78 const SAMPLETYPE *src, 79 uint numSamples, 80 uint numChannels) const; 81 82 /// Applies the filter to the given src & dest pipes, so that processed amount of 83 /// samples get removed from src, and produced amount added to dest 84 /// Note : The amount of outputted samples is by value of 'filter length' 85 /// smaller than the amount of input samples. 86 uint evaluate(FIFOSampleBuffer &dest, 87 FIFOSampleBuffer &src) const; 88 89 }; 90 91 } 92 93 #endif