| 1 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,216 +0,0 @@ |
| 1 |
-//////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
-/// |
|
| 3 |
-/// 'FIFOSamplePipe' : An abstract base class for classes that manipulate sound |
|
| 4 |
-/// samples by operating like a first-in-first-out pipe: New samples are fed |
|
| 5 |
-/// into one end of the pipe with the 'putSamples' function, and the processed |
|
| 6 |
-/// samples are received from the other end with the 'receiveSamples' function. |
|
| 7 |
-/// |
|
| 8 |
-/// 'FIFOProcessor' : A base class for classes the do signal processing with |
|
| 9 |
-/// the samples while operating like a first-in-first-out pipe. When samples |
|
| 10 |
-/// are input with the 'putSamples' function, the class processes them |
|
| 11 |
-/// and moves the processed samples to the given 'output' pipe object, which |
|
| 12 |
-/// may be either another processing stage, or a fifo sample buffer object. |
|
| 13 |
-/// |
|
| 14 |
-/// Author : Copyright (c) Olli Parviainen |
|
| 15 |
-/// Author e-mail : oparviai 'at' iki.fi |
|
| 16 |
-/// SoundTouch WWW: http://www.surina.net/soundtouch |
|
| 17 |
-/// |
|
| 18 |
-//////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
-// |
|
| 20 |
-// Last changed : $Date: 2012-06-13 16:29:53 -0300 (qua, 13 jun 2012) $ |
|
| 21 |
-// File revision : $Revision: 4 $ |
|
| 22 |
-// |
|
| 23 |
-// $Id: FIFOSamplePipe.h 143 2012-06-13 19:29:53Z oparviai $ |
|
| 24 |
-// |
|
| 25 |
-//////////////////////////////////////////////////////////////////////////////// |
|
| 26 |
-// |
|
| 27 |
-// License : |
|
| 28 |
-// |
|
| 29 |
-// SoundTouch audio processing library |
|
| 30 |
-// Copyright (c) Olli Parviainen |
|
| 31 |
-// |
|
| 32 |
-// This library is free software; you can redistribute it and/or |
|
| 33 |
-// modify it under the terms of the GNU Lesser General Public |
|
| 34 |
-// License as published by the Free Software Foundation; either |
|
| 35 |
-// version 2.1 of the License, or (at your option) any later version. |
|
| 36 |
-// |
|
| 37 |
-// This library is distributed in the hope that it will be useful, |
|
| 38 |
-// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 39 |
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 40 |
-// Lesser General Public License for more details. |
|
| 41 |
-// |
|
| 42 |
-// You should have received a copy of the GNU Lesser General Public |
|
| 43 |
-// License along with this library; if not, write to the Free Software |
|
| 44 |
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 45 |
-// |
|
| 46 |
-//////////////////////////////////////////////////////////////////////////////// |
|
| 47 |
- |
|
| 48 |
-#pragma once |
|
| 49 |
- |
|
| 50 |
-#include <cassert> |
|
| 51 |
-#include "STTypes.h" |
|
| 52 |
- |
|
| 53 |
-namespace soundtouch |
|
| 54 |
-{
|
|
| 55 |
- |
|
| 56 |
-/// Abstract base class for FIFO (first-in-first-out) sample processing classes. |
|
| 57 |
-class FIFOSamplePipe |
|
| 58 |
-{
|
|
| 59 |
-public: |
|
| 60 |
- // virtual default destructor |
|
| 61 |
- virtual ~FIFOSamplePipe() { }
|
|
| 62 |
- |
|
| 63 |
- /// Returns a pointer to the beginning of the output samples. |
|
| 64 |
- /// This function is provided for accessing the output samples directly. |
|
| 65 |
- /// Please be careful for not to corrupt the book-keeping! |
|
| 66 |
- /// |
|
| 67 |
- /// When using this function to output samples, also remember to 'remove' the |
|
| 68 |
- /// output samples from the buffer by calling the |
|
| 69 |
- /// 'receiveSamples(numSamples)' function |
|
| 70 |
- virtual SAMPLETYPE *ptrBegin() = 0; |
|
| 71 |
- |
|
| 72 |
- /// Adds 'numSamples' pcs of samples from the 'samples' memory position to |
|
| 73 |
- /// the sample buffer. |
|
| 74 |
- virtual void putSamples(const SAMPLETYPE *samples, ///< Pointer to samples. |
|
| 75 |
- uint32_t numSamples ///< Number of samples to insert. |
|
| 76 |
- ) = 0; |
|
| 77 |
- |
|
| 78 |
- // Moves samples from the 'other' pipe instance to this instance. |
|
| 79 |
- void moveSamples(FIFOSamplePipe &other ///< Other pipe instance where from the receive the data. |
|
| 80 |
- ) |
|
| 81 |
- {
|
|
| 82 |
- int oNumSamples = other.numSamples(); |
|
| 83 |
- |
|
| 84 |
- this->putSamples(other.ptrBegin(), oNumSamples); |
|
| 85 |
- other.receiveSamples(oNumSamples); |
|
| 86 |
- } |
|
| 87 |
- |
|
| 88 |
- /// Output samples from beginning of the sample buffer. Copies requested samples to |
|
| 89 |
- /// output buffer and removes them from the sample buffer. If there are less than |
|
| 90 |
- /// 'numsample' samples in the buffer, returns all that available. |
|
| 91 |
- /// |
|
| 92 |
- /// \return Number of samples returned. |
|
| 93 |
- virtual uint32_t receiveSamples(SAMPLETYPE *output, ///< Buffer where to copy output samples. |
|
| 94 |
- uint32_t maxSamples ///< How many samples to receive at max. |
|
| 95 |
- ) = 0; |
|
| 96 |
- |
|
| 97 |
- /// Adjusts book-keeping so that given number of samples are removed from beginning of the |
|
| 98 |
- /// sample buffer without copying them anywhere. |
|
| 99 |
- /// |
|
| 100 |
- /// Used to reduce the number of samples in the buffer when accessing the sample buffer directly |
|
| 101 |
- /// with 'ptrBegin' function. |
|
| 102 |
- virtual uint32_t receiveSamples(uint32_t maxSamples ///< Remove this many samples from the beginning of pipe. |
|
| 103 |
- ) = 0; |
|
| 104 |
- |
|
| 105 |
- /// Returns number of samples currently available. |
|
| 106 |
- virtual uint32_t numSamples() const = 0; |
|
| 107 |
- |
|
| 108 |
- // Returns nonzero if there aren't any samples available for outputting. |
|
| 109 |
- virtual bool isEmpty() const = 0; |
|
| 110 |
- |
|
| 111 |
- /// Clears all the samples. |
|
| 112 |
- virtual void clear() = 0; |
|
| 113 |
- |
|
| 114 |
- /// allow trimming (downwards) amount of samples in pipeline. |
|
| 115 |
- /// Returns adjusted amount of samples |
|
| 116 |
- virtual uint32_t adjustAmountOfSamples(uint32_t numSamples) = 0; |
|
| 117 |
-}; |
|
| 118 |
- |
|
| 119 |
-/// Base-class for sound processing routines working in FIFO principle. With this base |
|
| 120 |
-/// class it's easy to implement sound processing stages that can be chained together, |
|
| 121 |
-/// so that samples that are fed into beginning of the pipe automatically go through |
|
| 122 |
-/// all the processing stages. |
|
| 123 |
-/// |
|
| 124 |
-/// When samples are input to this class, they're first processed and then put to |
|
| 125 |
-/// the FIFO pipe that's defined as output of this class. This output pipe can be |
|
| 126 |
-/// either other processing stage or a FIFO sample buffer. |
|
| 127 |
-class FIFOProcessor :public FIFOSamplePipe |
|
| 128 |
-{
|
|
| 129 |
-protected: |
|
| 130 |
- /// Internal pipe where processed samples are put. |
|
| 131 |
- FIFOSamplePipe *output; |
|
| 132 |
- |
|
| 133 |
- /// Sets output pipe. |
|
| 134 |
- void setOutPipe(FIFOSamplePipe *pOutput) |
|
| 135 |
- {
|
|
| 136 |
- assert(!this->output); |
|
| 137 |
- assert(pOutput); |
|
| 138 |
- this->output = pOutput; |
|
| 139 |
- } |
|
| 140 |
- |
|
| 141 |
- /// Constructor. Doesn't define output pipe; it has to be set be |
|
| 142 |
- /// 'setOutPipe' function. |
|
| 143 |
- FIFOProcessor() |
|
| 144 |
- {
|
|
| 145 |
- this->output = nullptr; |
|
| 146 |
- } |
|
| 147 |
- |
|
| 148 |
- /// Constructor. Configures output pipe. |
|
| 149 |
- FIFOProcessor(FIFOSamplePipe *pOutput ///< Output pipe. |
|
| 150 |
- ) |
|
| 151 |
- {
|
|
| 152 |
- this->output = pOutput; |
|
| 153 |
- } |
|
| 154 |
- |
|
| 155 |
- /// Destructor. |
|
| 156 |
- virtual ~FIFOProcessor() |
|
| 157 |
- {
|
|
| 158 |
- } |
|
| 159 |
- |
|
| 160 |
- /// Returns a pointer to the beginning of the output samples. |
|
| 161 |
- /// This function is provided for accessing the output samples directly. |
|
| 162 |
- /// Please be careful for not to corrupt the book-keeping! |
|
| 163 |
- /// |
|
| 164 |
- /// When using this function to output samples, also remember to 'remove' the |
|
| 165 |
- /// output samples from the buffer by calling the |
|
| 166 |
- /// 'receiveSamples(numSamples)' function |
|
| 167 |
- virtual SAMPLETYPE *ptrBegin() |
|
| 168 |
- {
|
|
| 169 |
- return this->output->ptrBegin(); |
|
| 170 |
- } |
|
| 171 |
- |
|
| 172 |
-public: |
|
| 173 |
- /// Output samples from beginning of the sample buffer. Copies requested samples to |
|
| 174 |
- /// output buffer and removes them from the sample buffer. If there are less than |
|
| 175 |
- /// 'numsample' samples in the buffer, returns all that available. |
|
| 176 |
- /// |
|
| 177 |
- /// \return Number of samples returned. |
|
| 178 |
- virtual uint32_t receiveSamples(SAMPLETYPE *outBuffer, ///< Buffer where to copy output samples. |
|
| 179 |
- uint32_t maxSamples ///< How many samples to receive at max. |
|
| 180 |
- ) |
|
| 181 |
- {
|
|
| 182 |
- return this->output->receiveSamples(outBuffer, maxSamples); |
|
| 183 |
- } |
|
| 184 |
- |
|
| 185 |
- /// Adjusts book-keeping so that given number of samples are removed from beginning of the |
|
| 186 |
- /// sample buffer without copying them anywhere. |
|
| 187 |
- /// |
|
| 188 |
- /// Used to reduce the number of samples in the buffer when accessing the sample buffer directly |
|
| 189 |
- /// with 'ptrBegin' function. |
|
| 190 |
- virtual uint32_t receiveSamples(uint32_t maxSamples ///< Remove this many samples from the beginning of pipe. |
|
| 191 |
- ) |
|
| 192 |
- {
|
|
| 193 |
- return this->output->receiveSamples(maxSamples); |
|
| 194 |
- } |
|
| 195 |
- |
|
| 196 |
- /// Returns number of samples currently available. |
|
| 197 |
- virtual uint32_t numSamples() const |
|
| 198 |
- {
|
|
| 199 |
- return this->output->numSamples(); |
|
| 200 |
- } |
|
| 201 |
- |
|
| 202 |
- /// Returns nonzero if there aren't any samples available for outputting. |
|
| 203 |
- virtual bool isEmpty() const |
|
| 204 |
- {
|
|
| 205 |
- return this->output->isEmpty(); |
|
| 206 |
- } |
|
| 207 |
- |
|
| 208 |
- /// allow trimming (downwards) amount of samples in pipeline. |
|
| 209 |
- /// Returns adjusted amount of samples |
|
| 210 |
- virtual uint32_t adjustAmountOfSamples(uint32_t numSmpls) |
|
| 211 |
- {
|
|
| 212 |
- return this->output->adjustAmountOfSamples(numSmpls); |
|
| 213 |
- } |
|
| 214 |
-}; |
|
| 215 |
- |
|
| 216 |
-} |
* Removed a couple files that were not being used.
* Cleanups found with clang's -Weverything (and shutting it up about a
lot of things that were ridiculous, as well as ignoring some of the
warnings still coming up).
| ... | ... |
@@ -83,7 +83,7 @@ public: |
| 83 | 83 |
|
| 84 | 84 |
this->putSamples(other.ptrBegin(), oNumSamples); |
| 85 | 85 |
other.receiveSamples(oNumSamples); |
| 86 |
- }; |
|
| 86 |
+ } |
|
| 87 | 87 |
|
| 88 | 88 |
/// Output samples from beginning of the sample buffer. Copies requested samples to |
| 89 | 89 |
/// output buffer and removes them from the sample buffer. If there are less than |
* [2SF] Used more up-to-date asmjit, despite the ugly looking code.
| ... | ... |
@@ -207,9 +207,9 @@ public: |
| 207 | 207 |
|
| 208 | 208 |
/// allow trimming (downwards) amount of samples in pipeline. |
| 209 | 209 |
/// Returns adjusted amount of samples |
| 210 |
- virtual uint32_t adjustAmountOfSamples(uint32_t numSamples) |
|
| 210 |
+ virtual uint32_t adjustAmountOfSamples(uint32_t numSmpls) |
|
| 211 | 211 |
{
|
| 212 |
- return this->output->adjustAmountOfSamples(numSamples); |
|
| 212 |
+ return this->output->adjustAmountOfSamples(numSmpls); |
|
| 213 | 213 |
} |
| 214 | 214 |
}; |
| 215 | 215 |
|
| ... | ... |
@@ -45,8 +45,7 @@ |
| 45 | 45 |
// |
| 46 | 46 |
//////////////////////////////////////////////////////////////////////////////// |
| 47 | 47 |
|
| 48 |
-#ifndef FIFOSamplePipe_H |
|
| 49 |
-#define FIFOSamplePipe_H |
|
| 48 |
+#pragma once |
|
| 50 | 49 |
|
| 51 | 50 |
#include <cassert> |
| 52 | 51 |
#include "STTypes.h" |
| ... | ... |
@@ -215,5 +214,3 @@ public: |
| 215 | 214 |
}; |
| 216 | 215 |
|
| 217 | 216 |
} |
| 218 |
- |
|
| 219 |
-#endif |
| ... | ... |
@@ -17,10 +17,10 @@ |
| 17 | 17 |
/// |
| 18 | 18 |
//////////////////////////////////////////////////////////////////////////////// |
| 19 | 19 |
// |
| 20 |
-// Last changed : $Date: 2006/02/05 16:44:06 $ |
|
| 21 |
-// File revision : $Revision: 1.8 $ |
|
| 20 |
+// Last changed : $Date: 2012-06-13 16:29:53 -0300 (qua, 13 jun 2012) $ |
|
| 21 |
+// File revision : $Revision: 4 $ |
|
| 22 | 22 |
// |
| 23 |
-// $Id: FIFOSamplePipe.h,v 1.8 2006/02/05 16:44:06 Olli Exp $ |
|
| 23 |
+// $Id: FIFOSamplePipe.h 143 2012-06-13 19:29:53Z oparviai $ |
|
| 24 | 24 |
// |
| 25 | 25 |
//////////////////////////////////////////////////////////////////////////////// |
| 26 | 26 |
// |
| ... | ... |
@@ -49,7 +49,6 @@ |
| 49 | 49 |
#define FIFOSamplePipe_H |
| 50 | 50 |
|
| 51 | 51 |
#include <cassert> |
| 52 |
-#include <cstdlib> |
|
| 53 | 52 |
#include "STTypes.h" |
| 54 | 53 |
|
| 55 | 54 |
namespace soundtouch |
| ... | ... |
@@ -59,6 +58,9 @@ namespace soundtouch |
| 59 | 58 |
class FIFOSamplePipe |
| 60 | 59 |
{
|
| 61 | 60 |
public: |
| 61 |
+ // virtual default destructor |
|
| 62 |
+ virtual ~FIFOSamplePipe() { }
|
|
| 63 |
+ |
|
| 62 | 64 |
/// Returns a pointer to the beginning of the output samples. |
| 63 | 65 |
/// This function is provided for accessing the output samples directly. |
| 64 | 66 |
/// Please be careful for not to corrupt the book-keeping! |
| ... | ... |
@@ -66,12 +68,12 @@ public: |
| 66 | 68 |
/// When using this function to output samples, also remember to 'remove' the |
| 67 | 69 |
/// output samples from the buffer by calling the |
| 68 | 70 |
/// 'receiveSamples(numSamples)' function |
| 69 |
- virtual SAMPLETYPE *ptrBegin() const = 0; |
|
| 71 |
+ virtual SAMPLETYPE *ptrBegin() = 0; |
|
| 70 | 72 |
|
| 71 | 73 |
/// Adds 'numSamples' pcs of samples from the 'samples' memory position to |
| 72 | 74 |
/// the sample buffer. |
| 73 | 75 |
virtual void putSamples(const SAMPLETYPE *samples, ///< Pointer to samples. |
| 74 |
- uint32_t numSamples ///< Number of samples to insert. |
|
| 76 |
+ uint32_t numSamples ///< Number of samples to insert. |
|
| 75 | 77 |
) = 0; |
| 76 | 78 |
|
| 77 | 79 |
// Moves samples from the 'other' pipe instance to this instance. |
| ... | ... |
@@ -109,6 +111,10 @@ public: |
| 109 | 111 |
|
| 110 | 112 |
/// Clears all the samples. |
| 111 | 113 |
virtual void clear() = 0; |
| 114 |
+ |
|
| 115 |
+ /// allow trimming (downwards) amount of samples in pipeline. |
|
| 116 |
+ /// Returns adjusted amount of samples |
|
| 117 |
+ virtual uint32_t adjustAmountOfSamples(uint32_t numSamples) = 0; |
|
| 112 | 118 |
}; |
| 113 | 119 |
|
| 114 | 120 |
/// Base-class for sound processing routines working in FIFO principle. With this base |
| ... | ... |
@@ -128,23 +134,23 @@ protected: |
| 128 | 134 |
/// Sets output pipe. |
| 129 | 135 |
void setOutPipe(FIFOSamplePipe *pOutput) |
| 130 | 136 |
{
|
| 131 |
- assert(!output); |
|
| 137 |
+ assert(!this->output); |
|
| 132 | 138 |
assert(pOutput); |
| 133 |
- output = pOutput; |
|
| 139 |
+ this->output = pOutput; |
|
| 134 | 140 |
} |
| 135 | 141 |
|
| 136 | 142 |
/// Constructor. Doesn't define output pipe; it has to be set be |
| 137 | 143 |
/// 'setOutPipe' function. |
| 138 | 144 |
FIFOProcessor() |
| 139 | 145 |
{
|
| 140 |
- output = NULL; |
|
| 146 |
+ this->output = nullptr; |
|
| 141 | 147 |
} |
| 142 | 148 |
|
| 143 | 149 |
/// Constructor. Configures output pipe. |
| 144 | 150 |
FIFOProcessor(FIFOSamplePipe *pOutput ///< Output pipe. |
| 145 | 151 |
) |
| 146 | 152 |
{
|
| 147 |
- output = pOutput; |
|
| 153 |
+ this->output = pOutput; |
|
| 148 | 154 |
} |
| 149 | 155 |
|
| 150 | 156 |
/// Destructor. |
| ... | ... |
@@ -159,9 +165,9 @@ protected: |
| 159 | 165 |
/// When using this function to output samples, also remember to 'remove' the |
| 160 | 166 |
/// output samples from the buffer by calling the |
| 161 | 167 |
/// 'receiveSamples(numSamples)' function |
| 162 |
- virtual SAMPLETYPE *ptrBegin() const |
|
| 168 |
+ virtual SAMPLETYPE *ptrBegin() |
|
| 163 | 169 |
{
|
| 164 |
- return output->ptrBegin(); |
|
| 170 |
+ return this->output->ptrBegin(); |
|
| 165 | 171 |
} |
| 166 | 172 |
|
| 167 | 173 |
public: |
| ... | ... |
@@ -174,7 +180,7 @@ public: |
| 174 | 180 |
uint32_t maxSamples ///< How many samples to receive at max. |
| 175 | 181 |
) |
| 176 | 182 |
{
|
| 177 |
- return output->receiveSamples(outBuffer, maxSamples); |
|
| 183 |
+ return this->output->receiveSamples(outBuffer, maxSamples); |
|
| 178 | 184 |
} |
| 179 | 185 |
|
| 180 | 186 |
/// Adjusts book-keeping so that given number of samples are removed from beginning of the |
| ... | ... |
@@ -185,19 +191,26 @@ public: |
| 185 | 191 |
virtual uint32_t receiveSamples(uint32_t maxSamples ///< Remove this many samples from the beginning of pipe. |
| 186 | 192 |
) |
| 187 | 193 |
{
|
| 188 |
- return output->receiveSamples(maxSamples); |
|
| 194 |
+ return this->output->receiveSamples(maxSamples); |
|
| 189 | 195 |
} |
| 190 | 196 |
|
| 191 | 197 |
/// Returns number of samples currently available. |
| 192 | 198 |
virtual uint32_t numSamples() const |
| 193 | 199 |
{
|
| 194 |
- return output->numSamples(); |
|
| 200 |
+ return this->output->numSamples(); |
|
| 195 | 201 |
} |
| 196 | 202 |
|
| 197 | 203 |
/// Returns nonzero if there aren't any samples available for outputting. |
| 198 | 204 |
virtual bool isEmpty() const |
| 199 | 205 |
{
|
| 200 |
- return output->isEmpty(); |
|
| 206 |
+ return this->output->isEmpty(); |
|
| 207 |
+ } |
|
| 208 |
+ |
|
| 209 |
+ /// allow trimming (downwards) amount of samples in pipeline. |
|
| 210 |
+ /// Returns adjusted amount of samples |
|
| 211 |
+ virtual uint32_t adjustAmountOfSamples(uint32_t numSamples) |
|
| 212 |
+ {
|
|
| 213 |
+ return this->output->adjustAmountOfSamples(numSamples); |
|
| 201 | 214 |
} |
| 202 | 215 |
}; |
| 203 | 216 |
|
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,206 @@ |
| 1 |
+//////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
+/// |
|
| 3 |
+/// 'FIFOSamplePipe' : An abstract base class for classes that manipulate sound |
|
| 4 |
+/// samples by operating like a first-in-first-out pipe: New samples are fed |
|
| 5 |
+/// into one end of the pipe with the 'putSamples' function, and the processed |
|
| 6 |
+/// samples are received from the other end with the 'receiveSamples' function. |
|
| 7 |
+/// |
|
| 8 |
+/// 'FIFOProcessor' : A base class for classes the do signal processing with |
|
| 9 |
+/// the samples while operating like a first-in-first-out pipe. When samples |
|
| 10 |
+/// are input with the 'putSamples' function, the class processes them |
|
| 11 |
+/// and moves the processed samples to the given 'output' pipe object, which |
|
| 12 |
+/// may be either another processing stage, or a fifo sample buffer object. |
|
| 13 |
+/// |
|
| 14 |
+/// Author : Copyright (c) Olli Parviainen |
|
| 15 |
+/// Author e-mail : oparviai 'at' iki.fi |
|
| 16 |
+/// SoundTouch WWW: http://www.surina.net/soundtouch |
|
| 17 |
+/// |
|
| 18 |
+//////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
+// |
|
| 20 |
+// Last changed : $Date: 2006/02/05 16:44:06 $ |
|
| 21 |
+// File revision : $Revision: 1.8 $ |
|
| 22 |
+// |
|
| 23 |
+// $Id: FIFOSamplePipe.h,v 1.8 2006/02/05 16:44:06 Olli Exp $ |
|
| 24 |
+// |
|
| 25 |
+//////////////////////////////////////////////////////////////////////////////// |
|
| 26 |
+// |
|
| 27 |
+// License : |
|
| 28 |
+// |
|
| 29 |
+// SoundTouch audio processing library |
|
| 30 |
+// Copyright (c) Olli Parviainen |
|
| 31 |
+// |
|
| 32 |
+// This library is free software; you can redistribute it and/or |
|
| 33 |
+// modify it under the terms of the GNU Lesser General Public |
|
| 34 |
+// License as published by the Free Software Foundation; either |
|
| 35 |
+// version 2.1 of the License, or (at your option) any later version. |
|
| 36 |
+// |
|
| 37 |
+// This library is distributed in the hope that it will be useful, |
|
| 38 |
+// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 39 |
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 40 |
+// Lesser General Public License for more details. |
|
| 41 |
+// |
|
| 42 |
+// You should have received a copy of the GNU Lesser General Public |
|
| 43 |
+// License along with this library; if not, write to the Free Software |
|
| 44 |
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 45 |
+// |
|
| 46 |
+//////////////////////////////////////////////////////////////////////////////// |
|
| 47 |
+ |
|
| 48 |
+#ifndef FIFOSamplePipe_H |
|
| 49 |
+#define FIFOSamplePipe_H |
|
| 50 |
+ |
|
| 51 |
+#include <cassert> |
|
| 52 |
+#include <cstdlib> |
|
| 53 |
+#include "STTypes.h" |
|
| 54 |
+ |
|
| 55 |
+namespace soundtouch |
|
| 56 |
+{
|
|
| 57 |
+ |
|
| 58 |
+/// Abstract base class for FIFO (first-in-first-out) sample processing classes. |
|
| 59 |
+class FIFOSamplePipe |
|
| 60 |
+{
|
|
| 61 |
+public: |
|
| 62 |
+ /// Returns a pointer to the beginning of the output samples. |
|
| 63 |
+ /// This function is provided for accessing the output samples directly. |
|
| 64 |
+ /// Please be careful for not to corrupt the book-keeping! |
|
| 65 |
+ /// |
|
| 66 |
+ /// When using this function to output samples, also remember to 'remove' the |
|
| 67 |
+ /// output samples from the buffer by calling the |
|
| 68 |
+ /// 'receiveSamples(numSamples)' function |
|
| 69 |
+ virtual SAMPLETYPE *ptrBegin() const = 0; |
|
| 70 |
+ |
|
| 71 |
+ /// Adds 'numSamples' pcs of samples from the 'samples' memory position to |
|
| 72 |
+ /// the sample buffer. |
|
| 73 |
+ virtual void putSamples(const SAMPLETYPE *samples, ///< Pointer to samples. |
|
| 74 |
+ uint32_t numSamples ///< Number of samples to insert. |
|
| 75 |
+ ) = 0; |
|
| 76 |
+ |
|
| 77 |
+ // Moves samples from the 'other' pipe instance to this instance. |
|
| 78 |
+ void moveSamples(FIFOSamplePipe &other ///< Other pipe instance where from the receive the data. |
|
| 79 |
+ ) |
|
| 80 |
+ {
|
|
| 81 |
+ int oNumSamples = other.numSamples(); |
|
| 82 |
+ |
|
| 83 |
+ putSamples(other.ptrBegin(), oNumSamples); |
|
| 84 |
+ other.receiveSamples(oNumSamples); |
|
| 85 |
+ }; |
|
| 86 |
+ |
|
| 87 |
+ /// Output samples from beginning of the sample buffer. Copies requested samples to |
|
| 88 |
+ /// output buffer and removes them from the sample buffer. If there are less than |
|
| 89 |
+ /// 'numsample' samples in the buffer, returns all that available. |
|
| 90 |
+ /// |
|
| 91 |
+ /// \return Number of samples returned. |
|
| 92 |
+ virtual uint32_t receiveSamples(SAMPLETYPE *output, ///< Buffer where to copy output samples. |
|
| 93 |
+ uint32_t maxSamples ///< How many samples to receive at max. |
|
| 94 |
+ ) = 0; |
|
| 95 |
+ |
|
| 96 |
+ /// Adjusts book-keeping so that given number of samples are removed from beginning of the |
|
| 97 |
+ /// sample buffer without copying them anywhere. |
|
| 98 |
+ /// |
|
| 99 |
+ /// Used to reduce the number of samples in the buffer when accessing the sample buffer directly |
|
| 100 |
+ /// with 'ptrBegin' function. |
|
| 101 |
+ virtual uint32_t receiveSamples(uint32_t maxSamples ///< Remove this many samples from the beginning of pipe. |
|
| 102 |
+ ) = 0; |
|
| 103 |
+ |
|
| 104 |
+ /// Returns number of samples currently available. |
|
| 105 |
+ virtual uint32_t numSamples() const = 0; |
|
| 106 |
+ |
|
| 107 |
+ // Returns nonzero if there aren't any samples available for outputting. |
|
| 108 |
+ virtual bool isEmpty() const = 0; |
|
| 109 |
+ |
|
| 110 |
+ /// Clears all the samples. |
|
| 111 |
+ virtual void clear() = 0; |
|
| 112 |
+}; |
|
| 113 |
+ |
|
| 114 |
+/// Base-class for sound processing routines working in FIFO principle. With this base |
|
| 115 |
+/// class it's easy to implement sound processing stages that can be chained together, |
|
| 116 |
+/// so that samples that are fed into beginning of the pipe automatically go through |
|
| 117 |
+/// all the processing stages. |
|
| 118 |
+/// |
|
| 119 |
+/// When samples are input to this class, they're first processed and then put to |
|
| 120 |
+/// the FIFO pipe that's defined as output of this class. This output pipe can be |
|
| 121 |
+/// either other processing stage or a FIFO sample buffer. |
|
| 122 |
+class FIFOProcessor :public FIFOSamplePipe |
|
| 123 |
+{
|
|
| 124 |
+protected: |
|
| 125 |
+ /// Internal pipe where processed samples are put. |
|
| 126 |
+ FIFOSamplePipe *output; |
|
| 127 |
+ |
|
| 128 |
+ /// Sets output pipe. |
|
| 129 |
+ void setOutPipe(FIFOSamplePipe *pOutput) |
|
| 130 |
+ {
|
|
| 131 |
+ assert(!output); |
|
| 132 |
+ assert(pOutput); |
|
| 133 |
+ output = pOutput; |
|
| 134 |
+ } |
|
| 135 |
+ |
|
| 136 |
+ /// Constructor. Doesn't define output pipe; it has to be set be |
|
| 137 |
+ /// 'setOutPipe' function. |
|
| 138 |
+ FIFOProcessor() |
|
| 139 |
+ {
|
|
| 140 |
+ output = NULL; |
|
| 141 |
+ } |
|
| 142 |
+ |
|
| 143 |
+ /// Constructor. Configures output pipe. |
|
| 144 |
+ FIFOProcessor(FIFOSamplePipe *pOutput ///< Output pipe. |
|
| 145 |
+ ) |
|
| 146 |
+ {
|
|
| 147 |
+ output = pOutput; |
|
| 148 |
+ } |
|
| 149 |
+ |
|
| 150 |
+ /// Destructor. |
|
| 151 |
+ virtual ~FIFOProcessor() |
|
| 152 |
+ {
|
|
| 153 |
+ } |
|
| 154 |
+ |
|
| 155 |
+ /// Returns a pointer to the beginning of the output samples. |
|
| 156 |
+ /// This function is provided for accessing the output samples directly. |
|
| 157 |
+ /// Please be careful for not to corrupt the book-keeping! |
|
| 158 |
+ /// |
|
| 159 |
+ /// When using this function to output samples, also remember to 'remove' the |
|
| 160 |
+ /// output samples from the buffer by calling the |
|
| 161 |
+ /// 'receiveSamples(numSamples)' function |
|
| 162 |
+ virtual SAMPLETYPE *ptrBegin() const |
|
| 163 |
+ {
|
|
| 164 |
+ return output->ptrBegin(); |
|
| 165 |
+ } |
|
| 166 |
+ |
|
| 167 |
+public: |
|
| 168 |
+ /// Output samples from beginning of the sample buffer. Copies requested samples to |
|
| 169 |
+ /// output buffer and removes them from the sample buffer. If there are less than |
|
| 170 |
+ /// 'numsample' samples in the buffer, returns all that available. |
|
| 171 |
+ /// |
|
| 172 |
+ /// \return Number of samples returned. |
|
| 173 |
+ virtual uint32_t receiveSamples(SAMPLETYPE *outBuffer, ///< Buffer where to copy output samples. |
|
| 174 |
+ uint32_t maxSamples ///< How many samples to receive at max. |
|
| 175 |
+ ) |
|
| 176 |
+ {
|
|
| 177 |
+ return output->receiveSamples(outBuffer, maxSamples); |
|
| 178 |
+ } |
|
| 179 |
+ |
|
| 180 |
+ /// Adjusts book-keeping so that given number of samples are removed from beginning of the |
|
| 181 |
+ /// sample buffer without copying them anywhere. |
|
| 182 |
+ /// |
|
| 183 |
+ /// Used to reduce the number of samples in the buffer when accessing the sample buffer directly |
|
| 184 |
+ /// with 'ptrBegin' function. |
|
| 185 |
+ virtual uint32_t receiveSamples(uint32_t maxSamples ///< Remove this many samples from the beginning of pipe. |
|
| 186 |
+ ) |
|
| 187 |
+ {
|
|
| 188 |
+ return output->receiveSamples(maxSamples); |
|
| 189 |
+ } |
|
| 190 |
+ |
|
| 191 |
+ /// Returns number of samples currently available. |
|
| 192 |
+ virtual uint32_t numSamples() const |
|
| 193 |
+ {
|
|
| 194 |
+ return output->numSamples(); |
|
| 195 |
+ } |
|
| 196 |
+ |
|
| 197 |
+ /// Returns nonzero if there aren't any samples available for outputting. |
|
| 198 |
+ virtual bool isEmpty() const |
|
| 199 |
+ {
|
|
| 200 |
+ return output->isEmpty(); |
|
| 201 |
+ } |
|
| 202 |
+}; |
|
| 203 |
+ |
|
| 204 |
+} |
|
| 205 |
+ |
|
| 206 |
+#endif |