Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 2 | /// |
michael@0 | 3 | /// Sample rate transposer. Changes sample rate by using linear interpolation |
michael@0 | 4 | /// together with anti-alias filtering (first order interpolation with anti- |
michael@0 | 5 | /// alias filtering should be quite adequate for this application). |
michael@0 | 6 | /// |
michael@0 | 7 | /// Use either of the derived classes of 'RateTransposerInteger' or |
michael@0 | 8 | /// 'RateTransposerFloat' for corresponding integer/floating point tranposing |
michael@0 | 9 | /// algorithm implementation. |
michael@0 | 10 | /// |
michael@0 | 11 | /// Author : Copyright (c) Olli Parviainen |
michael@0 | 12 | /// Author e-mail : oparviai 'at' iki.fi |
michael@0 | 13 | /// SoundTouch WWW: http://www.surina.net/soundtouch |
michael@0 | 14 | /// |
michael@0 | 15 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 16 | // |
michael@0 | 17 | // Last changed : $Date: 2014-04-06 10:57:21 -0500 (Sun, 06 Apr 2014) $ |
michael@0 | 18 | // File revision : $Revision: 4 $ |
michael@0 | 19 | // |
michael@0 | 20 | // $Id: RateTransposer.h 195 2014-04-06 15:57:21Z oparviai $ |
michael@0 | 21 | // |
michael@0 | 22 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 23 | // |
michael@0 | 24 | // License : |
michael@0 | 25 | // |
michael@0 | 26 | // SoundTouch audio processing library |
michael@0 | 27 | // Copyright (c) Olli Parviainen |
michael@0 | 28 | // |
michael@0 | 29 | // This library is free software; you can redistribute it and/or |
michael@0 | 30 | // modify it under the terms of the GNU Lesser General Public |
michael@0 | 31 | // License as published by the Free Software Foundation; either |
michael@0 | 32 | // version 2.1 of the License, or (at your option) any later version. |
michael@0 | 33 | // |
michael@0 | 34 | // This library is distributed in the hope that it will be useful, |
michael@0 | 35 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
michael@0 | 36 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
michael@0 | 37 | // Lesser General Public License for more details. |
michael@0 | 38 | // |
michael@0 | 39 | // You should have received a copy of the GNU Lesser General Public |
michael@0 | 40 | // License along with this library; if not, write to the Free Software |
michael@0 | 41 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
michael@0 | 42 | // |
michael@0 | 43 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 44 | |
michael@0 | 45 | #ifndef RateTransposer_H |
michael@0 | 46 | #define RateTransposer_H |
michael@0 | 47 | |
michael@0 | 48 | #include <stddef.h> |
michael@0 | 49 | #include "AAFilter.h" |
michael@0 | 50 | #include "FIFOSamplePipe.h" |
michael@0 | 51 | #include "FIFOSampleBuffer.h" |
michael@0 | 52 | |
michael@0 | 53 | #include "STTypes.h" |
michael@0 | 54 | |
michael@0 | 55 | namespace soundtouch |
michael@0 | 56 | { |
michael@0 | 57 | |
michael@0 | 58 | /// Abstract base class for transposer implementations (linear, advanced vs integer, float etc) |
michael@0 | 59 | class TransposerBase |
michael@0 | 60 | { |
michael@0 | 61 | public: |
michael@0 | 62 | enum ALGORITHM { |
michael@0 | 63 | LINEAR = 0, |
michael@0 | 64 | CUBIC, |
michael@0 | 65 | SHANNON |
michael@0 | 66 | }; |
michael@0 | 67 | |
michael@0 | 68 | protected: |
michael@0 | 69 | virtual void resetRegisters() = 0; |
michael@0 | 70 | |
michael@0 | 71 | virtual int transposeMono(SAMPLETYPE *dest, |
michael@0 | 72 | const SAMPLETYPE *src, |
michael@0 | 73 | int &srcSamples) = 0; |
michael@0 | 74 | virtual int transposeStereo(SAMPLETYPE *dest, |
michael@0 | 75 | const SAMPLETYPE *src, |
michael@0 | 76 | int &srcSamples) = 0; |
michael@0 | 77 | virtual int transposeMulti(SAMPLETYPE *dest, |
michael@0 | 78 | const SAMPLETYPE *src, |
michael@0 | 79 | int &srcSamples) = 0; |
michael@0 | 80 | |
michael@0 | 81 | static ALGORITHM algorithm; |
michael@0 | 82 | |
michael@0 | 83 | public: |
michael@0 | 84 | float rate; |
michael@0 | 85 | int numChannels; |
michael@0 | 86 | |
michael@0 | 87 | TransposerBase(); |
michael@0 | 88 | virtual ~TransposerBase(); |
michael@0 | 89 | |
michael@0 | 90 | virtual int transpose(FIFOSampleBuffer &dest, FIFOSampleBuffer &src); |
michael@0 | 91 | virtual void setRate(float newRate); |
michael@0 | 92 | virtual void setChannels(int channels); |
michael@0 | 93 | |
michael@0 | 94 | // static factory function |
michael@0 | 95 | static TransposerBase *newInstance(); |
michael@0 | 96 | |
michael@0 | 97 | // static function to set interpolation algorithm |
michael@0 | 98 | static void setAlgorithm(ALGORITHM a); |
michael@0 | 99 | }; |
michael@0 | 100 | |
michael@0 | 101 | |
michael@0 | 102 | /// A common linear samplerate transposer class. |
michael@0 | 103 | /// |
michael@0 | 104 | class RateTransposer : public FIFOProcessor |
michael@0 | 105 | { |
michael@0 | 106 | protected: |
michael@0 | 107 | /// Anti-alias filter object |
michael@0 | 108 | AAFilter *pAAFilter; |
michael@0 | 109 | TransposerBase *pTransposer; |
michael@0 | 110 | |
michael@0 | 111 | /// Buffer for collecting samples to feed the anti-alias filter between |
michael@0 | 112 | /// two batches |
michael@0 | 113 | FIFOSampleBuffer inputBuffer; |
michael@0 | 114 | |
michael@0 | 115 | /// Buffer for keeping samples between transposing & anti-alias filter |
michael@0 | 116 | FIFOSampleBuffer midBuffer; |
michael@0 | 117 | |
michael@0 | 118 | /// Output sample buffer |
michael@0 | 119 | FIFOSampleBuffer outputBuffer; |
michael@0 | 120 | |
michael@0 | 121 | bool bUseAAFilter; |
michael@0 | 122 | |
michael@0 | 123 | |
michael@0 | 124 | /// Transposes sample rate by applying anti-alias filter to prevent folding. |
michael@0 | 125 | /// Returns amount of samples returned in the "dest" buffer. |
michael@0 | 126 | /// The maximum amount of samples that can be returned at a time is set by |
michael@0 | 127 | /// the 'set_returnBuffer_size' function. |
michael@0 | 128 | void processSamples(const SAMPLETYPE *src, |
michael@0 | 129 | uint numSamples); |
michael@0 | 130 | |
michael@0 | 131 | public: |
michael@0 | 132 | RateTransposer(); |
michael@0 | 133 | virtual ~RateTransposer(); |
michael@0 | 134 | |
michael@0 | 135 | /// Operator 'new' is overloaded so that it automatically creates a suitable instance |
michael@0 | 136 | /// depending on if we're to use integer or floating point arithmetics. |
michael@0 | 137 | // static void *operator new(size_t s); |
michael@0 | 138 | |
michael@0 | 139 | /// Use this function instead of "new" operator to create a new instance of this class. |
michael@0 | 140 | /// This function automatically chooses a correct implementation, depending on if |
michael@0 | 141 | /// integer ot floating point arithmetics are to be used. |
michael@0 | 142 | // static RateTransposer *newInstance(); |
michael@0 | 143 | |
michael@0 | 144 | /// Returns the output buffer object |
michael@0 | 145 | FIFOSamplePipe *getOutput() { return &outputBuffer; }; |
michael@0 | 146 | |
michael@0 | 147 | /// Returns the store buffer object |
michael@0 | 148 | // FIFOSamplePipe *getStore() { return &storeBuffer; }; |
michael@0 | 149 | |
michael@0 | 150 | /// Return anti-alias filter object |
michael@0 | 151 | AAFilter *getAAFilter(); |
michael@0 | 152 | |
michael@0 | 153 | /// Enables/disables the anti-alias filter. Zero to disable, nonzero to enable |
michael@0 | 154 | void enableAAFilter(bool newMode); |
michael@0 | 155 | |
michael@0 | 156 | /// Returns nonzero if anti-alias filter is enabled. |
michael@0 | 157 | bool isAAFilterEnabled() const; |
michael@0 | 158 | |
michael@0 | 159 | /// Sets new target rate. Normal rate = 1.0, smaller values represent slower |
michael@0 | 160 | /// rate, larger faster rates. |
michael@0 | 161 | virtual void setRate(float newRate); |
michael@0 | 162 | |
michael@0 | 163 | /// Sets the number of channels, 1 = mono, 2 = stereo |
michael@0 | 164 | void setChannels(int channels); |
michael@0 | 165 | |
michael@0 | 166 | /// Adds 'numSamples' pcs of samples from the 'samples' memory position into |
michael@0 | 167 | /// the input of the object. |
michael@0 | 168 | void putSamples(const SAMPLETYPE *samples, uint numSamples); |
michael@0 | 169 | |
michael@0 | 170 | /// Clears all the samples in the object |
michael@0 | 171 | void clear(); |
michael@0 | 172 | |
michael@0 | 173 | /// Returns nonzero if there aren't any samples available for outputting. |
michael@0 | 174 | int isEmpty() const; |
michael@0 | 175 | }; |
michael@0 | 176 | |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | #endif |