| 1 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,172 +0,0 @@ |
| 1 |
-//////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
-/// |
|
| 3 |
-/// A buffer class for temporarily storaging sound samples, operates as a |
|
| 4 |
-/// first-in-first-out pipe. |
|
| 5 |
-/// |
|
| 6 |
-/// Samples are added to the end of the sample buffer with the 'putSamples' |
|
| 7 |
-/// function, and are received from the beginning of the buffer by calling |
|
| 8 |
-/// the 'receiveSamples' function. The class automatically removes the |
|
| 9 |
-/// output samples from the buffer as well as grows the storage size |
|
| 10 |
-/// whenever necessary. |
|
| 11 |
-/// |
|
| 12 |
-/// Author : Copyright (c) Olli Parviainen |
|
| 13 |
-/// Author e-mail : oparviai 'at' iki.fi |
|
| 14 |
-/// SoundTouch WWW: http://www.surina.net/soundtouch |
|
| 15 |
-/// |
|
| 16 |
-//////////////////////////////////////////////////////////////////////////////// |
|
| 17 |
-// |
|
| 18 |
-// Last changed : $Date: 2012-06-13 16:29:53 -0300 (qua, 13 jun 2012) $ |
|
| 19 |
-// File revision : $Revision: 4 $ |
|
| 20 |
-// |
|
| 21 |
-// $Id: FIFOSampleBuffer.h 143 2012-06-13 19:29:53Z oparviai $ |
|
| 22 |
-// |
|
| 23 |
-//////////////////////////////////////////////////////////////////////////////// |
|
| 24 |
-// |
|
| 25 |
-// License : |
|
| 26 |
-// |
|
| 27 |
-// SoundTouch audio processing library |
|
| 28 |
-// Copyright (c) Olli Parviainen |
|
| 29 |
-// |
|
| 30 |
-// This library is free software; you can redistribute it and/or |
|
| 31 |
-// modify it under the terms of the GNU Lesser General Public |
|
| 32 |
-// License as published by the Free Software Foundation; either |
|
| 33 |
-// version 2.1 of the License, or (at your option) any later version. |
|
| 34 |
-// |
|
| 35 |
-// This library is distributed in the hope that it will be useful, |
|
| 36 |
-// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 37 |
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 38 |
-// Lesser General Public License for more details. |
|
| 39 |
-// |
|
| 40 |
-// You should have received a copy of the GNU Lesser General Public |
|
| 41 |
-// License along with this library; if not, write to the Free Software |
|
| 42 |
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 43 |
-// |
|
| 44 |
-//////////////////////////////////////////////////////////////////////////////// |
|
| 45 |
- |
|
| 46 |
-#pragma once |
|
| 47 |
- |
|
| 48 |
-#include <memory> |
|
| 49 |
-#include "FIFOSamplePipe.h" |
|
| 50 |
- |
|
| 51 |
-namespace soundtouch |
|
| 52 |
-{
|
|
| 53 |
- |
|
| 54 |
-/// Sample buffer working in FIFO (first-in-first-out) principle. The class takes |
|
| 55 |
-/// care of storage size adjustment and data moving during input/output operations. |
|
| 56 |
-/// |
|
| 57 |
-/// Notice that in case of stereo audio, one sample is considered to consist of |
|
| 58 |
-/// both channel data. |
|
| 59 |
-class FIFOSampleBuffer : public FIFOSamplePipe |
|
| 60 |
-{
|
|
| 61 |
-private: |
|
| 62 |
- /// Sample buffer. |
|
| 63 |
- SAMPLETYPE *buffer; |
|
| 64 |
- |
|
| 65 |
- // Raw unaligned buffer memory. 'buffer' is made aligned by pointing it to first |
|
| 66 |
- // 16-byte aligned location of this buffer |
|
| 67 |
- std::unique_ptr<SAMPLETYPE[]> bufferUnaligned; |
|
| 68 |
- |
|
| 69 |
- /// Sample buffer size in bytes |
|
| 70 |
- uint32_t sizeInBytes; |
|
| 71 |
- |
|
| 72 |
- /// How many samples are currently in buffer. |
|
| 73 |
- uint32_t samplesInBuffer; |
|
| 74 |
- |
|
| 75 |
- /// Channels, 1=mono, 2=stereo. |
|
| 76 |
- uint32_t channels; |
|
| 77 |
- |
|
| 78 |
- /// Current position pointer to the buffer. This pointer is increased when samples are |
|
| 79 |
- /// removed from the pipe so that it's necessary to actually rewind buffer (move data) |
|
| 80 |
- /// only new data when is put to the pipe. |
|
| 81 |
- uint32_t bufferPos; |
|
| 82 |
- |
|
| 83 |
- /// Rewind the buffer by moving data from position pointed by 'bufferPos' to real |
|
| 84 |
- /// beginning of the buffer. |
|
| 85 |
- void rewind(); |
|
| 86 |
- |
|
| 87 |
- /// Ensures that the buffer has capacity for at least this many samples. |
|
| 88 |
- void ensureCapacity(uint32_t capacityRequirement); |
|
| 89 |
- |
|
| 90 |
- /// Returns current capacity. |
|
| 91 |
- uint32_t getCapacity() const; |
|
| 92 |
- |
|
| 93 |
-public: |
|
| 94 |
- /// Constructor |
|
| 95 |
- FIFOSampleBuffer(int32_t numChannels = 2 ///< Number of channels, 1=mono, 2=stereo. |
|
| 96 |
- ///< Default is stereo. |
|
| 97 |
- ); |
|
| 98 |
- |
|
| 99 |
- /// Returns a pointer to the beginning of the output samples. |
|
| 100 |
- /// This function is provided for accessing the output samples directly. |
|
| 101 |
- /// Please be careful for not to corrupt the book-keeping! |
|
| 102 |
- /// |
|
| 103 |
- /// When using this function to output samples, also remember to 'remove' the |
|
| 104 |
- /// output samples from the buffer by calling the |
|
| 105 |
- /// 'receiveSamples(numSamples)' function |
|
| 106 |
- SAMPLETYPE *ptrBegin(); |
|
| 107 |
- |
|
| 108 |
- /// Returns a pointer to the end of the used part of the sample buffer (i.e. |
|
| 109 |
- /// where the new samples are to be inserted). This function may be used for |
|
| 110 |
- /// inserting new samples into the sample buffer directly. Please be careful |
|
| 111 |
- /// not corrupt the book-keeping! |
|
| 112 |
- /// |
|
| 113 |
- /// When using this function as means for inserting new samples, also remember |
|
| 114 |
- /// to increase the sample count afterwards, by calling the |
|
| 115 |
- /// 'putSamples(numSamples)' function. |
|
| 116 |
- SAMPLETYPE *ptrEnd( |
|
| 117 |
- uint32_t slackCapacity ///< How much free capacity (in samples) there _at least_ |
|
| 118 |
- ///< should be so that the caller can succesfully insert the |
|
| 119 |
- ///< desired samples to the buffer. If necessary, the function |
|
| 120 |
- ///< grows the buffer size to comply with this requirement. |
|
| 121 |
- ); |
|
| 122 |
- |
|
| 123 |
- /// Adds 'numSamples' pcs of samples from the 'samples' memory position to |
|
| 124 |
- /// the sample buffer. |
|
| 125 |
- void putSamples(const SAMPLETYPE *samples, ///< Pointer to samples. |
|
| 126 |
- uint32_t numSamples ///< Number of samples to insert. |
|
| 127 |
- ); |
|
| 128 |
- |
|
| 129 |
- /// Adjusts the book-keeping to increase number of samples in the buffer without |
|
| 130 |
- /// copying any actual samples. |
|
| 131 |
- /// |
|
| 132 |
- /// This function is used to update the number of samples in the sample buffer |
|
| 133 |
- /// when accessing the buffer directly with 'ptrEnd' function. Please be |
|
| 134 |
- /// careful though! |
|
| 135 |
- void putSamples(uint32_t numSamples ///< Number of samples been inserted. |
|
| 136 |
- ); |
|
| 137 |
- |
|
| 138 |
- /// Output samples from beginning of the sample buffer. Copies requested samples to |
|
| 139 |
- /// output buffer and removes them from the sample buffer. If there are less than |
|
| 140 |
- /// 'numsample' samples in the buffer, returns all that available. |
|
| 141 |
- /// |
|
| 142 |
- /// \return Number of samples returned. |
|
| 143 |
- uint32_t receiveSamples(SAMPLETYPE *output, ///< Buffer where to copy output samples. |
|
| 144 |
- uint32_t maxSamples ///< How many samples to receive at max. |
|
| 145 |
- ); |
|
| 146 |
- |
|
| 147 |
- /// Adjusts book-keeping so that given number of samples are removed from beginning of the |
|
| 148 |
- /// sample buffer without copying them anywhere. |
|
| 149 |
- /// |
|
| 150 |
- /// Used to reduce the number of samples in the buffer when accessing the sample buffer directly |
|
| 151 |
- /// with 'ptrBegin' function. |
|
| 152 |
- uint32_t receiveSamples(uint32_t maxSamples ///< Remove this many samples from the beginning of pipe. |
|
| 153 |
- ); |
|
| 154 |
- |
|
| 155 |
- /// Returns number of samples currently available. |
|
| 156 |
- uint32_t numSamples() const; |
|
| 157 |
- |
|
| 158 |
- /// Sets number of channels, 1 = mono, 2 = stereo. |
|
| 159 |
- void setChannels(int32_t numChannels); |
|
| 160 |
- |
|
| 161 |
- /// Returns nonzero if there aren't any samples available for outputting. |
|
| 162 |
- bool isEmpty() const; |
|
| 163 |
- |
|
| 164 |
- /// Clears all the samples. |
|
| 165 |
- void clear(); |
|
| 166 |
- |
|
| 167 |
- /// allow trimming (downwards) amount of samples in pipeline. |
|
| 168 |
- /// Returns adjusted amount of samples |
|
| 169 |
- uint32_t adjustAmountOfSamples(uint32_t numSamples); |
|
| 170 |
-}; |
|
| 171 |
- |
|
| 172 |
-} |
| ... | ... |
@@ -43,8 +43,7 @@ |
| 43 | 43 |
// |
| 44 | 44 |
//////////////////////////////////////////////////////////////////////////////// |
| 45 | 45 |
|
| 46 |
-#ifndef FIFOSampleBuffer_H |
|
| 47 |
-#define FIFOSampleBuffer_H |
|
| 46 |
+#pragma once |
|
| 48 | 47 |
|
| 49 | 48 |
#include <memory> |
| 50 | 49 |
#include "FIFOSamplePipe.h" |
| ... | ... |
@@ -171,5 +170,3 @@ public: |
| 171 | 170 |
}; |
| 172 | 171 |
|
| 173 | 172 |
} |
| 174 |
- |
|
| 175 |
-#endif |
| ... | ... |
@@ -97,9 +97,6 @@ public: |
| 97 | 97 |
///< Default is stereo. |
| 98 | 98 |
); |
| 99 | 99 |
|
| 100 |
- /// destructor |
|
| 101 |
- virtual ~FIFOSampleBuffer(); |
|
| 102 |
- |
|
| 103 | 100 |
/// Returns a pointer to the beginning of the output samples. |
| 104 | 101 |
/// This function is provided for accessing the output samples directly. |
| 105 | 102 |
/// Please be careful for not to corrupt the book-keeping! |
| ... | ... |
@@ -107,7 +104,7 @@ public: |
| 107 | 104 |
/// When using this function to output samples, also remember to 'remove' the |
| 108 | 105 |
/// output samples from the buffer by calling the |
| 109 | 106 |
/// 'receiveSamples(numSamples)' function |
| 110 |
- virtual SAMPLETYPE *ptrBegin(); |
|
| 107 |
+ SAMPLETYPE *ptrBegin(); |
|
| 111 | 108 |
|
| 112 | 109 |
/// Returns a pointer to the end of the used part of the sample buffer (i.e. |
| 113 | 110 |
/// where the new samples are to be inserted). This function may be used for |
| ... | ... |
@@ -126,7 +123,7 @@ public: |
| 126 | 123 |
|
| 127 | 124 |
/// Adds 'numSamples' pcs of samples from the 'samples' memory position to |
| 128 | 125 |
/// the sample buffer. |
| 129 |
- virtual void putSamples(const SAMPLETYPE *samples, ///< Pointer to samples. |
|
| 126 |
+ void putSamples(const SAMPLETYPE *samples, ///< Pointer to samples. |
|
| 130 | 127 |
uint32_t numSamples ///< Number of samples to insert. |
| 131 | 128 |
); |
| 132 | 129 |
|
| ... | ... |
@@ -136,7 +133,7 @@ public: |
| 136 | 133 |
/// This function is used to update the number of samples in the sample buffer |
| 137 | 134 |
/// when accessing the buffer directly with 'ptrEnd' function. Please be |
| 138 | 135 |
/// careful though! |
| 139 |
- virtual void putSamples(uint32_t numSamples ///< Number of samples been inserted. |
|
| 136 |
+ void putSamples(uint32_t numSamples ///< Number of samples been inserted. |
|
| 140 | 137 |
); |
| 141 | 138 |
|
| 142 | 139 |
/// Output samples from beginning of the sample buffer. Copies requested samples to |
| ... | ... |
@@ -144,7 +141,7 @@ public: |
| 144 | 141 |
/// 'numsample' samples in the buffer, returns all that available. |
| 145 | 142 |
/// |
| 146 | 143 |
/// \return Number of samples returned. |
| 147 |
- virtual uint32_t receiveSamples(SAMPLETYPE *output, ///< Buffer where to copy output samples. |
|
| 144 |
+ uint32_t receiveSamples(SAMPLETYPE *output, ///< Buffer where to copy output samples. |
|
| 148 | 145 |
uint32_t maxSamples ///< How many samples to receive at max. |
| 149 | 146 |
); |
| 150 | 147 |
|
| ... | ... |
@@ -153,26 +150,26 @@ public: |
| 153 | 150 |
/// |
| 154 | 151 |
/// Used to reduce the number of samples in the buffer when accessing the sample buffer directly |
| 155 | 152 |
/// with 'ptrBegin' function. |
| 156 |
- virtual uint32_t receiveSamples(uint32_t maxSamples ///< Remove this many samples from the beginning of pipe. |
|
| 153 |
+ uint32_t receiveSamples(uint32_t maxSamples ///< Remove this many samples from the beginning of pipe. |
|
| 157 | 154 |
); |
| 158 | 155 |
|
| 159 | 156 |
/// Returns number of samples currently available. |
| 160 |
- virtual uint32_t numSamples() const; |
|
| 157 |
+ uint32_t numSamples() const; |
|
| 161 | 158 |
|
| 162 | 159 |
/// Sets number of channels, 1 = mono, 2 = stereo. |
| 163 | 160 |
void setChannels(int32_t numChannels); |
| 164 | 161 |
|
| 165 | 162 |
/// Returns nonzero if there aren't any samples available for outputting. |
| 166 |
- virtual bool isEmpty() const; |
|
| 163 |
+ bool isEmpty() const; |
|
| 167 | 164 |
|
| 168 | 165 |
/// Clears all the samples. |
| 169 |
- virtual void clear(); |
|
| 166 |
+ void clear(); |
|
| 170 | 167 |
|
| 171 | 168 |
/// allow trimming (downwards) amount of samples in pipeline. |
| 172 | 169 |
/// Returns adjusted amount of samples |
| 173 | 170 |
uint32_t adjustAmountOfSamples(uint32_t numSamples); |
| 174 | 171 |
}; |
| 175 |
- |
|
| 172 |
+ |
|
| 176 | 173 |
} |
| 177 | 174 |
|
| 178 | 175 |
#endif |
| ... | ... |
@@ -15,10 +15,10 @@ |
| 15 | 15 |
/// |
| 16 | 16 |
//////////////////////////////////////////////////////////////////////////////// |
| 17 | 17 |
// |
| 18 |
-// Last changed : $Date: 2006/02/05 16:44:06 $ |
|
| 19 |
-// File revision : $Revision: 1.9 $ |
|
| 18 |
+// Last changed : $Date: 2012-06-13 16:29:53 -0300 (qua, 13 jun 2012) $ |
|
| 19 |
+// File revision : $Revision: 4 $ |
|
| 20 | 20 |
// |
| 21 |
-// $Id: FIFOSampleBuffer.h,v 1.9 2006/02/05 16:44:06 Olli Exp $ |
|
| 21 |
+// $Id: FIFOSampleBuffer.h 143 2012-06-13 19:29:53Z oparviai $ |
|
| 22 | 22 |
// |
| 23 | 23 |
//////////////////////////////////////////////////////////////////////////////// |
| 24 | 24 |
// |
| ... | ... |
@@ -46,6 +46,7 @@ |
| 46 | 46 |
#ifndef FIFOSampleBuffer_H |
| 47 | 47 |
#define FIFOSampleBuffer_H |
| 48 | 48 |
|
| 49 |
+#include <memory> |
|
| 49 | 50 |
#include "FIFOSamplePipe.h" |
| 50 | 51 |
|
| 51 | 52 |
namespace soundtouch |
| ... | ... |
@@ -64,7 +65,7 @@ private: |
| 64 | 65 |
|
| 65 | 66 |
// Raw unaligned buffer memory. 'buffer' is made aligned by pointing it to first |
| 66 | 67 |
// 16-byte aligned location of this buffer |
| 67 |
- SAMPLETYPE *bufferUnaligned; |
|
| 68 |
+ std::unique_ptr<SAMPLETYPE[]> bufferUnaligned; |
|
| 68 | 69 |
|
| 69 | 70 |
/// Sample buffer size in bytes |
| 70 | 71 |
uint32_t sizeInBytes; |
| ... | ... |
@@ -85,19 +86,19 @@ private: |
| 85 | 86 |
void rewind(); |
| 86 | 87 |
|
| 87 | 88 |
/// Ensures that the buffer has capacity for at least this many samples. |
| 88 |
- void ensureCapacity(const uint32_t capacityRequirement); |
|
| 89 |
+ void ensureCapacity(uint32_t capacityRequirement); |
|
| 89 | 90 |
|
| 90 | 91 |
/// Returns current capacity. |
| 91 | 92 |
uint32_t getCapacity() const; |
| 92 | 93 |
|
| 93 | 94 |
public: |
| 94 | 95 |
/// Constructor |
| 95 |
- FIFOSampleBuffer(uint32_t numChannels = 2 ///< Number of channels, 1=mono, 2=stereo. |
|
| 96 |
+ FIFOSampleBuffer(int32_t numChannels = 2 ///< Number of channels, 1=mono, 2=stereo. |
|
| 96 | 97 |
///< Default is stereo. |
| 97 | 98 |
); |
| 98 | 99 |
|
| 99 | 100 |
/// destructor |
| 100 |
- ~FIFOSampleBuffer(); |
|
| 101 |
+ virtual ~FIFOSampleBuffer(); |
|
| 101 | 102 |
|
| 102 | 103 |
/// Returns a pointer to the beginning of the output samples. |
| 103 | 104 |
/// This function is provided for accessing the output samples directly. |
| ... | ... |
@@ -106,7 +107,7 @@ public: |
| 106 | 107 |
/// When using this function to output samples, also remember to 'remove' the |
| 107 | 108 |
/// output samples from the buffer by calling the |
| 108 | 109 |
/// 'receiveSamples(numSamples)' function |
| 109 |
- virtual SAMPLETYPE *ptrBegin() const; |
|
| 110 |
+ virtual SAMPLETYPE *ptrBegin(); |
|
| 110 | 111 |
|
| 111 | 112 |
/// Returns a pointer to the end of the used part of the sample buffer (i.e. |
| 112 | 113 |
/// where the new samples are to be inserted). This function may be used for |
| ... | ... |
@@ -159,15 +160,19 @@ public: |
| 159 | 160 |
virtual uint32_t numSamples() const; |
| 160 | 161 |
|
| 161 | 162 |
/// Sets number of channels, 1 = mono, 2 = stereo. |
| 162 |
- void setChannels(uint32_t numChannels); |
|
| 163 |
+ void setChannels(int32_t numChannels); |
|
| 163 | 164 |
|
| 164 | 165 |
/// Returns nonzero if there aren't any samples available for outputting. |
| 165 | 166 |
virtual bool isEmpty() const; |
| 166 | 167 |
|
| 167 | 168 |
/// Clears all the samples. |
| 168 | 169 |
virtual void clear(); |
| 169 |
-}; |
|
| 170 | 170 |
|
| 171 |
+ /// allow trimming (downwards) amount of samples in pipeline. |
|
| 172 |
+ /// Returns adjusted amount of samples |
|
| 173 |
+ uint32_t adjustAmountOfSamples(uint32_t numSamples); |
|
| 174 |
+}; |
|
| 175 |
+ |
|
| 171 | 176 |
} |
| 172 | 177 |
|
| 173 | 178 |
#endif |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,173 @@ |
| 1 |
+//////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
+/// |
|
| 3 |
+/// A buffer class for temporarily storaging sound samples, operates as a |
|
| 4 |
+/// first-in-first-out pipe. |
|
| 5 |
+/// |
|
| 6 |
+/// Samples are added to the end of the sample buffer with the 'putSamples' |
|
| 7 |
+/// function, and are received from the beginning of the buffer by calling |
|
| 8 |
+/// the 'receiveSamples' function. The class automatically removes the |
|
| 9 |
+/// output samples from the buffer as well as grows the storage size |
|
| 10 |
+/// whenever necessary. |
|
| 11 |
+/// |
|
| 12 |
+/// Author : Copyright (c) Olli Parviainen |
|
| 13 |
+/// Author e-mail : oparviai 'at' iki.fi |
|
| 14 |
+/// SoundTouch WWW: http://www.surina.net/soundtouch |
|
| 15 |
+/// |
|
| 16 |
+//////////////////////////////////////////////////////////////////////////////// |
|
| 17 |
+// |
|
| 18 |
+// Last changed : $Date: 2006/02/05 16:44:06 $ |
|
| 19 |
+// File revision : $Revision: 1.9 $ |
|
| 20 |
+// |
|
| 21 |
+// $Id: FIFOSampleBuffer.h,v 1.9 2006/02/05 16:44:06 Olli Exp $ |
|
| 22 |
+// |
|
| 23 |
+//////////////////////////////////////////////////////////////////////////////// |
|
| 24 |
+// |
|
| 25 |
+// License : |
|
| 26 |
+// |
|
| 27 |
+// SoundTouch audio processing library |
|
| 28 |
+// Copyright (c) Olli Parviainen |
|
| 29 |
+// |
|
| 30 |
+// This library is free software; you can redistribute it and/or |
|
| 31 |
+// modify it under the terms of the GNU Lesser General Public |
|
| 32 |
+// License as published by the Free Software Foundation; either |
|
| 33 |
+// version 2.1 of the License, or (at your option) any later version. |
|
| 34 |
+// |
|
| 35 |
+// This library is distributed in the hope that it will be useful, |
|
| 36 |
+// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 37 |
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 38 |
+// Lesser General Public License for more details. |
|
| 39 |
+// |
|
| 40 |
+// You should have received a copy of the GNU Lesser General Public |
|
| 41 |
+// License along with this library; if not, write to the Free Software |
|
| 42 |
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 43 |
+// |
|
| 44 |
+//////////////////////////////////////////////////////////////////////////////// |
|
| 45 |
+ |
|
| 46 |
+#ifndef FIFOSampleBuffer_H |
|
| 47 |
+#define FIFOSampleBuffer_H |
|
| 48 |
+ |
|
| 49 |
+#include "FIFOSamplePipe.h" |
|
| 50 |
+ |
|
| 51 |
+namespace soundtouch |
|
| 52 |
+{
|
|
| 53 |
+ |
|
| 54 |
+/// Sample buffer working in FIFO (first-in-first-out) principle. The class takes |
|
| 55 |
+/// care of storage size adjustment and data moving during input/output operations. |
|
| 56 |
+/// |
|
| 57 |
+/// Notice that in case of stereo audio, one sample is considered to consist of |
|
| 58 |
+/// both channel data. |
|
| 59 |
+class FIFOSampleBuffer : public FIFOSamplePipe |
|
| 60 |
+{
|
|
| 61 |
+private: |
|
| 62 |
+ /// Sample buffer. |
|
| 63 |
+ SAMPLETYPE *buffer; |
|
| 64 |
+ |
|
| 65 |
+ // Raw unaligned buffer memory. 'buffer' is made aligned by pointing it to first |
|
| 66 |
+ // 16-byte aligned location of this buffer |
|
| 67 |
+ SAMPLETYPE *bufferUnaligned; |
|
| 68 |
+ |
|
| 69 |
+ /// Sample buffer size in bytes |
|
| 70 |
+ uint32_t sizeInBytes; |
|
| 71 |
+ |
|
| 72 |
+ /// How many samples are currently in buffer. |
|
| 73 |
+ uint32_t samplesInBuffer; |
|
| 74 |
+ |
|
| 75 |
+ /// Channels, 1=mono, 2=stereo. |
|
| 76 |
+ uint32_t channels; |
|
| 77 |
+ |
|
| 78 |
+ /// Current position pointer to the buffer. This pointer is increased when samples are |
|
| 79 |
+ /// removed from the pipe so that it's necessary to actually rewind buffer (move data) |
|
| 80 |
+ /// only new data when is put to the pipe. |
|
| 81 |
+ uint32_t bufferPos; |
|
| 82 |
+ |
|
| 83 |
+ /// Rewind the buffer by moving data from position pointed by 'bufferPos' to real |
|
| 84 |
+ /// beginning of the buffer. |
|
| 85 |
+ void rewind(); |
|
| 86 |
+ |
|
| 87 |
+ /// Ensures that the buffer has capacity for at least this many samples. |
|
| 88 |
+ void ensureCapacity(const uint32_t capacityRequirement); |
|
| 89 |
+ |
|
| 90 |
+ /// Returns current capacity. |
|
| 91 |
+ uint32_t getCapacity() const; |
|
| 92 |
+ |
|
| 93 |
+public: |
|
| 94 |
+ /// Constructor |
|
| 95 |
+ FIFOSampleBuffer(uint32_t numChannels = 2 ///< Number of channels, 1=mono, 2=stereo. |
|
| 96 |
+ ///< Default is stereo. |
|
| 97 |
+ ); |
|
| 98 |
+ |
|
| 99 |
+ /// destructor |
|
| 100 |
+ ~FIFOSampleBuffer(); |
|
| 101 |
+ |
|
| 102 |
+ /// Returns a pointer to the beginning of the output samples. |
|
| 103 |
+ /// This function is provided for accessing the output samples directly. |
|
| 104 |
+ /// Please be careful for not to corrupt the book-keeping! |
|
| 105 |
+ /// |
|
| 106 |
+ /// When using this function to output samples, also remember to 'remove' the |
|
| 107 |
+ /// output samples from the buffer by calling the |
|
| 108 |
+ /// 'receiveSamples(numSamples)' function |
|
| 109 |
+ virtual SAMPLETYPE *ptrBegin() const; |
|
| 110 |
+ |
|
| 111 |
+ /// Returns a pointer to the end of the used part of the sample buffer (i.e. |
|
| 112 |
+ /// where the new samples are to be inserted). This function may be used for |
|
| 113 |
+ /// inserting new samples into the sample buffer directly. Please be careful |
|
| 114 |
+ /// not corrupt the book-keeping! |
|
| 115 |
+ /// |
|
| 116 |
+ /// When using this function as means for inserting new samples, also remember |
|
| 117 |
+ /// to increase the sample count afterwards, by calling the |
|
| 118 |
+ /// 'putSamples(numSamples)' function. |
|
| 119 |
+ SAMPLETYPE *ptrEnd( |
|
| 120 |
+ uint32_t slackCapacity ///< How much free capacity (in samples) there _at least_ |
|
| 121 |
+ ///< should be so that the caller can succesfully insert the |
|
| 122 |
+ ///< desired samples to the buffer. If necessary, the function |
|
| 123 |
+ ///< grows the buffer size to comply with this requirement. |
|
| 124 |
+ ); |
|
| 125 |
+ |
|
| 126 |
+ /// Adds 'numSamples' pcs of samples from the 'samples' memory position to |
|
| 127 |
+ /// the sample buffer. |
|
| 128 |
+ virtual void putSamples(const SAMPLETYPE *samples, ///< Pointer to samples. |
|
| 129 |
+ uint32_t numSamples ///< Number of samples to insert. |
|
| 130 |
+ ); |
|
| 131 |
+ |
|
| 132 |
+ /// Adjusts the book-keeping to increase number of samples in the buffer without |
|
| 133 |
+ /// copying any actual samples. |
|
| 134 |
+ /// |
|
| 135 |
+ /// This function is used to update the number of samples in the sample buffer |
|
| 136 |
+ /// when accessing the buffer directly with 'ptrEnd' function. Please be |
|
| 137 |
+ /// careful though! |
|
| 138 |
+ virtual void putSamples(uint32_t numSamples ///< Number of samples been inserted. |
|
| 139 |
+ ); |
|
| 140 |
+ |
|
| 141 |
+ /// Output samples from beginning of the sample buffer. Copies requested samples to |
|
| 142 |
+ /// output buffer and removes them from the sample buffer. If there are less than |
|
| 143 |
+ /// 'numsample' samples in the buffer, returns all that available. |
|
| 144 |
+ /// |
|
| 145 |
+ /// \return Number of samples returned. |
|
| 146 |
+ virtual uint32_t receiveSamples(SAMPLETYPE *output, ///< Buffer where to copy output samples. |
|
| 147 |
+ uint32_t maxSamples ///< How many samples to receive at max. |
|
| 148 |
+ ); |
|
| 149 |
+ |
|
| 150 |
+ /// Adjusts book-keeping so that given number of samples are removed from beginning of the |
|
| 151 |
+ /// sample buffer without copying them anywhere. |
|
| 152 |
+ /// |
|
| 153 |
+ /// Used to reduce the number of samples in the buffer when accessing the sample buffer directly |
|
| 154 |
+ /// with 'ptrBegin' function. |
|
| 155 |
+ virtual uint32_t receiveSamples(uint32_t maxSamples ///< Remove this many samples from the beginning of pipe. |
|
| 156 |
+ ); |
|
| 157 |
+ |
|
| 158 |
+ /// Returns number of samples currently available. |
|
| 159 |
+ virtual uint32_t numSamples() const; |
|
| 160 |
+ |
|
| 161 |
+ /// Sets number of channels, 1 = mono, 2 = stereo. |
|
| 162 |
+ void setChannels(uint32_t numChannels); |
|
| 163 |
+ |
|
| 164 |
+ /// Returns nonzero if there aren't any samples available for outputting. |
|
| 165 |
+ virtual bool isEmpty() const; |
|
| 166 |
+ |
|
| 167 |
+ /// Clears all the samples. |
|
| 168 |
+ virtual void clear(); |
|
| 169 |
+}; |
|
| 170 |
+ |
|
| 171 |
+} |
|
| 172 |
+ |
|
| 173 |
+#endif |