PageRenderTime 19ms CodeModel.GetById 12ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/external/pysoundtouch14/libsoundtouch/FIRFilter.h

http://echo-nest-remix.googlecode.com/
C++ Header | 163 lines | 74 code | 33 blank | 56 comment | 0 complexity | 64fbcc3c2a3d7882ffb33d9ccfc95c94 MD5 | raw file
  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: 2008-02-10 18:26:55 +0200 (Sun, 10 Feb 2008) $
 15// File revision : $Revision: 4 $
 16//
 17// $Id: FIRFilter.h 11 2008-02-10 16:26:55Z 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 "STTypes.h"
 46
 47namespace soundtouch
 48{
 49
 50class FIRFilter 
 51{
 52protected:
 53    // Number of FIR filter taps
 54    uint length;    
 55    // Number of FIR filter taps divided by 8
 56    uint lengthDiv8;
 57
 58    // Result divider factor in 2^k format
 59    uint resultDivFactor;
 60
 61    // Result divider value.
 62    SAMPLETYPE resultDivider;
 63
 64    // Memory for filter coefficients
 65    SAMPLETYPE *filterCoeffs;
 66
 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;
 73
 74public:
 75    FIRFilter();
 76    virtual ~FIRFilter();
 77
 78    /// Operator 'new' is overloaded so that it automatically creates a suitable instance 
 79    /// depending on if we've a MMX-capable CPU available or not.
 80    static void * operator new(size_t s);
 81
 82    static FIRFilter *newInstance();
 83
 84    /// Applies the filter to the given sequence of samples. 
 85    /// Note : The amount of outputted samples is by value of 'filter_length' 
 86    /// smaller than the amount of input samples.
 87    ///
 88    /// \return Number of samples copied to 'dest'.
 89    uint evaluate(SAMPLETYPE *dest, 
 90                  const SAMPLETYPE *src, 
 91                  uint numSamples, 
 92                  uint numChannels) const;
 93
 94    uint getLength() const;
 95
 96    virtual void setCoefficients(const SAMPLETYPE *coeffs, 
 97                                 uint newLength, 
 98                                 uint uResultDivFactor);
 99};
100
101
102// Optional subclasses that implement CPU-specific optimizations:
103
104#ifdef ALLOW_MMX
105
106    /// Class that implements MMX optimized functions exclusive for 16bit integer samples type.
107    class FIRFilterMMX : public FIRFilter
108    {
109    protected:
110        short *filterCoeffsUnalign;
111        short *filterCoeffsAlign;
112
113        virtual uint evaluateFilterStereo(short *dest, const short *src, uint numSamples) const;
114    public:
115        FIRFilterMMX();
116        ~FIRFilterMMX();
117
118        virtual void setCoefficients(const short *coeffs, uint newLength, uint uResultDivFactor);
119    };
120
121#endif // ALLOW_MMX
122
123
124#ifdef ALLOW_3DNOW
125
126    /// Class that implements 3DNow! optimized functions exclusive for floating point samples type.
127    class FIRFilter3DNow : public FIRFilter
128    {
129    protected:
130        float *filterCoeffsUnalign;
131        float *filterCoeffsAlign;
132
133        virtual uint evaluateFilterStereo(float *dest, const float *src, uint numSamples) const;
134    public:
135        FIRFilter3DNow();
136        ~FIRFilter3DNow();
137        virtual void setCoefficients(const float *coeffs, uint newLength, uint uResultDivFactor);
138    };
139
140#endif  // ALLOW_3DNOW
141
142
143#ifdef ALLOW_SSE
144    /// Class that implements SSE optimized functions exclusive for floating point samples type.
145    class FIRFilterSSE : public FIRFilter
146    {
147    protected:
148        float *filterCoeffsUnalign;
149        float *filterCoeffsAlign;
150
151        virtual uint evaluateFilterStereo(float *dest, const float *src, uint numSamples) const;
152    public:
153        FIRFilterSSE();
154        ~FIRFilterSSE();
155
156        virtual void setCoefficients(const float *coeffs, uint newLength, uint uResultDivFactor);
157    };
158
159#endif // ALLOW_SSE
160
161}
162
163#endif  // FIRFilter_H