media/libsoundtouch/src/FIRFilter.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libsoundtouch/src/FIRFilter.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,146 @@
     1.4 +////////////////////////////////////////////////////////////////////////////////
     1.5 +///
     1.6 +/// General FIR digital filter routines with MMX optimization. 
     1.7 +///
     1.8 +/// Note : MMX optimized functions reside in a separate, platform-specific file, 
     1.9 +/// e.g. 'mmx_win.cpp' or 'mmx_gcc.cpp'
    1.10 +///
    1.11 +/// Author        : Copyright (c) Olli Parviainen
    1.12 +/// Author e-mail : oparviai 'at' iki.fi
    1.13 +/// SoundTouch WWW: http://www.surina.net/soundtouch
    1.14 +///
    1.15 +////////////////////////////////////////////////////////////////////////////////
    1.16 +//
    1.17 +// Last changed  : $Date: 2013-06-12 10:24:44 -0500 (Wed, 12 Jun 2013) $
    1.18 +// File revision : $Revision: 4 $
    1.19 +//
    1.20 +// $Id: FIRFilter.h 171 2013-06-12 15:24:44Z oparviai $
    1.21 +//
    1.22 +////////////////////////////////////////////////////////////////////////////////
    1.23 +//
    1.24 +// License :
    1.25 +//
    1.26 +//  SoundTouch audio processing library
    1.27 +//  Copyright (c) Olli Parviainen
    1.28 +//
    1.29 +//  This library is free software; you can redistribute it and/or
    1.30 +//  modify it under the terms of the GNU Lesser General Public
    1.31 +//  License as published by the Free Software Foundation; either
    1.32 +//  version 2.1 of the License, or (at your option) any later version.
    1.33 +//
    1.34 +//  This library is distributed in the hope that it will be useful,
    1.35 +//  but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.36 +//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.37 +//  Lesser General Public License for more details.
    1.38 +//
    1.39 +//  You should have received a copy of the GNU Lesser General Public
    1.40 +//  License along with this library; if not, write to the Free Software
    1.41 +//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.42 +//
    1.43 +////////////////////////////////////////////////////////////////////////////////
    1.44 +
    1.45 +#ifndef FIRFilter_H
    1.46 +#define FIRFilter_H
    1.47 +
    1.48 +#include <stddef.h>
    1.49 +#include "STTypes.h"
    1.50 +
    1.51 +namespace soundtouch
    1.52 +{
    1.53 +
    1.54 +class FIRFilter 
    1.55 +{
    1.56 +protected:
    1.57 +    // Number of FIR filter taps
    1.58 +    uint length;    
    1.59 +    // Number of FIR filter taps divided by 8
    1.60 +    uint lengthDiv8;
    1.61 +
    1.62 +    // Result divider factor in 2^k format
    1.63 +    uint resultDivFactor;
    1.64 +
    1.65 +    // Result divider value.
    1.66 +    SAMPLETYPE resultDivider;
    1.67 +
    1.68 +    // Memory for filter coefficients
    1.69 +    SAMPLETYPE *filterCoeffs;
    1.70 +
    1.71 +    virtual uint evaluateFilterStereo(SAMPLETYPE *dest, 
    1.72 +                                      const SAMPLETYPE *src, 
    1.73 +                                      uint numSamples) const;
    1.74 +    virtual uint evaluateFilterMono(SAMPLETYPE *dest, 
    1.75 +                                    const SAMPLETYPE *src, 
    1.76 +                                    uint numSamples) const;
    1.77 +    virtual uint evaluateFilterMulti(SAMPLETYPE *dest, const SAMPLETYPE *src, uint numSamples, uint numChannels) const;
    1.78 +
    1.79 +public:
    1.80 +    FIRFilter();
    1.81 +    virtual ~FIRFilter();
    1.82 +
    1.83 +    /// Operator 'new' is overloaded so that it automatically creates a suitable instance 
    1.84 +    /// depending on if we've a MMX-capable CPU available or not.
    1.85 +    static void * operator new(size_t s);
    1.86 +
    1.87 +    static FIRFilter *newInstance();
    1.88 +
    1.89 +    /// Applies the filter to the given sequence of samples. 
    1.90 +    /// Note : The amount of outputted samples is by value of 'filter_length' 
    1.91 +    /// smaller than the amount of input samples.
    1.92 +    ///
    1.93 +    /// \return Number of samples copied to 'dest'.
    1.94 +    uint evaluate(SAMPLETYPE *dest, 
    1.95 +                  const SAMPLETYPE *src, 
    1.96 +                  uint numSamples, 
    1.97 +                  uint numChannels) const;
    1.98 +
    1.99 +    uint getLength() const;
   1.100 +
   1.101 +    virtual void setCoefficients(const SAMPLETYPE *coeffs, 
   1.102 +                                 uint newLength, 
   1.103 +                                 uint uResultDivFactor);
   1.104 +};
   1.105 +
   1.106 +
   1.107 +// Optional subclasses that implement CPU-specific optimizations:
   1.108 +
   1.109 +#ifdef SOUNDTOUCH_ALLOW_MMX
   1.110 +
   1.111 +/// Class that implements MMX optimized functions exclusive for 16bit integer samples type.
   1.112 +    class FIRFilterMMX : public FIRFilter
   1.113 +    {
   1.114 +    protected:
   1.115 +        short *filterCoeffsUnalign;
   1.116 +        short *filterCoeffsAlign;
   1.117 +
   1.118 +        virtual uint evaluateFilterStereo(short *dest, const short *src, uint numSamples) const;
   1.119 +    public:
   1.120 +        FIRFilterMMX();
   1.121 +        ~FIRFilterMMX();
   1.122 +
   1.123 +        virtual void setCoefficients(const short *coeffs, uint newLength, uint uResultDivFactor);
   1.124 +    };
   1.125 +
   1.126 +#endif // SOUNDTOUCH_ALLOW_MMX
   1.127 +
   1.128 +
   1.129 +#ifdef SOUNDTOUCH_ALLOW_SSE
   1.130 +    /// Class that implements SSE optimized functions exclusive for floating point samples type.
   1.131 +    class FIRFilterSSE : public FIRFilter
   1.132 +    {
   1.133 +    protected:
   1.134 +        float *filterCoeffsUnalign;
   1.135 +        float *filterCoeffsAlign;
   1.136 +
   1.137 +        virtual uint evaluateFilterStereo(float *dest, const float *src, uint numSamples) const;
   1.138 +    public:
   1.139 +        FIRFilterSSE();
   1.140 +        ~FIRFilterSSE();
   1.141 +
   1.142 +        virtual void setCoefficients(const float *coeffs, uint newLength, uint uResultDivFactor);
   1.143 +    };
   1.144 +
   1.145 +#endif // SOUNDTOUCH_ALLOW_SSE
   1.146 +
   1.147 +}
   1.148 +
   1.149 +#endif  // FIRFilter_H

mercurial