media/libsoundtouch/src/FIRFilter.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial