michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: /// michael@0: /// General FIR digital filter routines with MMX optimization. michael@0: /// michael@0: /// Note : MMX optimized functions reside in a separate, platform-specific file, michael@0: /// e.g. 'mmx_win.cpp' or 'mmx_gcc.cpp' michael@0: /// michael@0: /// Author : Copyright (c) Olli Parviainen michael@0: /// Author e-mail : oparviai 'at' iki.fi michael@0: /// SoundTouch WWW: http://www.surina.net/soundtouch michael@0: /// michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // michael@0: // Last changed : $Date: 2013-06-12 10:24:44 -0500 (Wed, 12 Jun 2013) $ michael@0: // File revision : $Revision: 4 $ michael@0: // michael@0: // $Id: FIRFilter.h 171 2013-06-12 15:24:44Z oparviai $ michael@0: // michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // michael@0: // License : michael@0: // michael@0: // SoundTouch audio processing library michael@0: // Copyright (c) Olli Parviainen michael@0: // michael@0: // This library is free software; you can redistribute it and/or michael@0: // modify it under the terms of the GNU Lesser General Public michael@0: // License as published by the Free Software Foundation; either michael@0: // version 2.1 of the License, or (at your option) any later version. michael@0: // michael@0: // This library is distributed in the hope that it will be useful, michael@0: // but WITHOUT ANY WARRANTY; without even the implied warranty of michael@0: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU michael@0: // Lesser General Public License for more details. michael@0: // michael@0: // You should have received a copy of the GNU Lesser General Public michael@0: // License along with this library; if not, write to the Free Software michael@0: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA michael@0: // michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: #ifndef FIRFilter_H michael@0: #define FIRFilter_H michael@0: michael@0: #include michael@0: #include "STTypes.h" michael@0: michael@0: namespace soundtouch michael@0: { michael@0: michael@0: class FIRFilter michael@0: { michael@0: protected: michael@0: // Number of FIR filter taps michael@0: uint length; michael@0: // Number of FIR filter taps divided by 8 michael@0: uint lengthDiv8; michael@0: michael@0: // Result divider factor in 2^k format michael@0: uint resultDivFactor; michael@0: michael@0: // Result divider value. michael@0: SAMPLETYPE resultDivider; michael@0: michael@0: // Memory for filter coefficients michael@0: SAMPLETYPE *filterCoeffs; michael@0: michael@0: virtual uint evaluateFilterStereo(SAMPLETYPE *dest, michael@0: const SAMPLETYPE *src, michael@0: uint numSamples) const; michael@0: virtual uint evaluateFilterMono(SAMPLETYPE *dest, michael@0: const SAMPLETYPE *src, michael@0: uint numSamples) const; michael@0: virtual uint evaluateFilterMulti(SAMPLETYPE *dest, const SAMPLETYPE *src, uint numSamples, uint numChannels) const; michael@0: michael@0: public: michael@0: FIRFilter(); michael@0: virtual ~FIRFilter(); michael@0: michael@0: /// Operator 'new' is overloaded so that it automatically creates a suitable instance michael@0: /// depending on if we've a MMX-capable CPU available or not. michael@0: static void * operator new(size_t s); michael@0: michael@0: static FIRFilter *newInstance(); michael@0: michael@0: /// Applies the filter to the given sequence of samples. michael@0: /// Note : The amount of outputted samples is by value of 'filter_length' michael@0: /// smaller than the amount of input samples. michael@0: /// michael@0: /// \return Number of samples copied to 'dest'. michael@0: uint evaluate(SAMPLETYPE *dest, michael@0: const SAMPLETYPE *src, michael@0: uint numSamples, michael@0: uint numChannels) const; michael@0: michael@0: uint getLength() const; michael@0: michael@0: virtual void setCoefficients(const SAMPLETYPE *coeffs, michael@0: uint newLength, michael@0: uint uResultDivFactor); michael@0: }; michael@0: michael@0: michael@0: // Optional subclasses that implement CPU-specific optimizations: michael@0: michael@0: #ifdef SOUNDTOUCH_ALLOW_MMX michael@0: michael@0: /// Class that implements MMX optimized functions exclusive for 16bit integer samples type. michael@0: class FIRFilterMMX : public FIRFilter michael@0: { michael@0: protected: michael@0: short *filterCoeffsUnalign; michael@0: short *filterCoeffsAlign; michael@0: michael@0: virtual uint evaluateFilterStereo(short *dest, const short *src, uint numSamples) const; michael@0: public: michael@0: FIRFilterMMX(); michael@0: ~FIRFilterMMX(); michael@0: michael@0: virtual void setCoefficients(const short *coeffs, uint newLength, uint uResultDivFactor); michael@0: }; michael@0: michael@0: #endif // SOUNDTOUCH_ALLOW_MMX michael@0: michael@0: michael@0: #ifdef SOUNDTOUCH_ALLOW_SSE michael@0: /// Class that implements SSE optimized functions exclusive for floating point samples type. michael@0: class FIRFilterSSE : public FIRFilter michael@0: { michael@0: protected: michael@0: float *filterCoeffsUnalign; michael@0: float *filterCoeffsAlign; michael@0: michael@0: virtual uint evaluateFilterStereo(float *dest, const float *src, uint numSamples) const; michael@0: public: michael@0: FIRFilterSSE(); michael@0: ~FIRFilterSSE(); michael@0: michael@0: virtual void setCoefficients(const float *coeffs, uint newLength, uint uResultDivFactor); michael@0: }; michael@0: michael@0: #endif // SOUNDTOUCH_ALLOW_SSE michael@0: michael@0: } michael@0: michael@0: #endif // FIRFilter_H