Sample buffer working in FIFO (first-in-first-out) principle. More...
#include <FIFOSampleBuffer.h>
Public Member Functions | |
| FIFOSampleBuffer (uint numChannels=2) | |
| Constructor. | |
| ~FIFOSampleBuffer () | |
| destructor | |
| virtual SAMPLETYPE * | ptrBegin () const |
| Returns a pointer to the beginning of the output samples. | |
| SAMPLETYPE * | ptrEnd (uint slackCapacity) |
| Returns a pointer to the end of the used part of the sample buffer (i.e. | |
| virtual void | putSamples (const SAMPLETYPE *samples, uint numSamples) |
| Adds 'numSamples' pcs of samples from the 'samples' memory position to the sample buffer. | |
| virtual void | putSamples (uint numSamples) |
| Adjusts the book-keeping to increase number of samples in the buffer without copying any actual samples. | |
| virtual uint | receiveSamples (SAMPLETYPE *output, uint maxSamples) |
| Output samples from beginning of the sample buffer. | |
| virtual uint | receiveSamples (uint maxSamples) |
| Adjusts book-keeping so that given number of samples are removed from beginning of the sample buffer without copying them anywhere. | |
| virtual uint | numSamples () const |
| Returns number of samples currently available. | |
| void | setChannels (uint numChannels) |
| Sets number of channels, 1 = mono, 2 = stereo. | |
| virtual int | isEmpty () const |
| Returns nonzero if there aren't any samples available for outputting. | |
| virtual void | clear () |
| Clears all the samples. | |
Private Member Functions | |
| void | rewind () |
| Rewind the buffer by moving data from position pointed by 'bufferPos' to real beginning of the buffer. | |
| void | ensureCapacity (const uint capacityRequirement) |
| Ensures that the buffer has capacity for at least this many samples. | |
| uint | getCapacity () const |
| Returns current capacity. | |
Private Attributes | |
| SAMPLETYPE * | buffer |
| Sample buffer. | |
| SAMPLETYPE * | bufferUnaligned |
| uint | sizeInBytes |
| Sample buffer size in bytes. | |
| uint | samplesInBuffer |
| How many samples are currently in buffer. | |
| uint | channels |
| Channels, 1=mono, 2=stereo. | |
| uint | bufferPos |
| Current position pointer to the buffer. | |
Sample buffer working in FIFO (first-in-first-out) principle.
The class takes care of storage size adjustment and data moving during input/output operations.
Notice that in case of stereo audio, one sample is considered to consist of both channel data.
Definition at line 59 of file FIFOSampleBuffer.h.
| FIFOSampleBuffer::FIFOSampleBuffer | ( | uint | numChannels = 2 |
) |
Constructor.
| numChannels | Number of channels, 1=mono, 2=stereo. Default is stereo. |
Definition at line 57 of file FIFOSampleBuffer.cpp.
| FIFOSampleBuffer::~FIFOSampleBuffer | ( | ) |
destructor
Definition at line 69 of file FIFOSampleBuffer.cpp.
| void FIFOSampleBuffer::rewind | ( | ) | [private] |
Rewind the buffer by moving data from position pointed by 'bufferPos' to real beginning of the buffer.
Definition at line 89 of file FIFOSampleBuffer.cpp.
Referenced by ensureCapacity().
| void FIFOSampleBuffer::ensureCapacity | ( | const uint | capacityRequirement | ) | [private] |
Ensures that the buffer has capacity for at least this many samples.
Definition at line 160 of file FIFOSampleBuffer.cpp.
Referenced by ptrEnd(), and putSamples().
| uint FIFOSampleBuffer::getCapacity | ( | ) | const [private] |
Returns current capacity.
Definition at line 190 of file FIFOSampleBuffer.cpp.
Referenced by ensureCapacity().
| SAMPLETYPE * FIFOSampleBuffer::ptrBegin | ( | ) | const [virtual] |
Returns a pointer to the beginning of the output samples.
This function is provided for accessing the output samples directly. Please be careful for not to corrupt the book-keeping!
When using this function to output samples, also remember to 'remove' the output samples from the buffer by calling the 'receiveSamples(numSamples)' function
Implements FIFOSamplePipe.
Definition at line 150 of file FIFOSampleBuffer.cpp.
Referenced by soundtouch::RateTransposer::downsample(), ensureCapacity(), soundtouch::TDStretch::processNominalTempo(), soundtouch::TDStretch::processSamples(), receiveSamples(), rewind(), and soundtouch::RateTransposer::upsample().
| SAMPLETYPE * FIFOSampleBuffer::ptrEnd | ( | uint | slackCapacity | ) |
Returns a pointer to the end of the used part of the sample buffer (i.e.
where the new samples are to be inserted). This function may be used for inserting new samples into the sample buffer directly. Please be careful not corrupt the book-keeping!
When using this function as means for inserting new samples, also remember to increase the sample count afterwards, by calling the 'putSamples(numSamples)' function.
| slackCapacity | How much free capacity (in samples) there _at least_ should be so that the caller can succesfully insert the desired samples to the buffer. If necessary, the function grows the buffer size to comply with this requirement. |
Definition at line 136 of file FIFOSampleBuffer.cpp.
Referenced by soundtouch::RateTransposer::downsample(), soundtouch::TDStretch::processNominalTempo(), soundtouch::TDStretch::processSamples(), soundtouch::RateTransposer::processSamples(), putSamples(), and soundtouch::RateTransposer::upsample().
| void FIFOSampleBuffer::putSamples | ( | const SAMPLETYPE * | samples, | |
| uint | numSamples | |||
| ) | [virtual] |
Adds 'numSamples' pcs of samples from the 'samples' memory position to the sample buffer.
| samples | Pointer to samples. | |
| numSamples | Number of samples to insert. |
Implements FIFOSamplePipe.
Definition at line 101 of file FIFOSampleBuffer.cpp.
Referenced by soundtouch::RateTransposer::downsample(), soundtouch::TDStretch::processNominalTempo(), soundtouch::TDStretch::processSamples(), soundtouch::RateTransposer::processSamples(), soundtouch::TDStretch::putSamples(), and soundtouch::RateTransposer::upsample().
| void FIFOSampleBuffer::putSamples | ( | uint | numSamples | ) | [virtual] |
Adjusts the book-keeping to increase number of samples in the buffer without copying any actual samples.
This function is used to update the number of samples in the sample buffer when accessing the buffer directly with 'ptrEnd' function. Please be careful though!
| numSamples | Number of samples been inserted. |
Definition at line 114 of file FIFOSampleBuffer.cpp.
| uint FIFOSampleBuffer::receiveSamples | ( | SAMPLETYPE * | output, | |
| uint | maxSamples | |||
| ) | [virtual] |
Output samples from beginning of the sample buffer.
Copies requested samples to output buffer and removes them from the sample buffer. If there are less than 'numsample' samples in the buffer, returns all that available.
| output | Buffer where to copy output samples. | |
| maxSamples | How many samples to receive at max. |
Implements FIFOSamplePipe.
Definition at line 208 of file FIFOSampleBuffer.cpp.
Referenced by soundtouch::RateTransposer::downsample(), soundtouch::TDStretch::processNominalTempo(), soundtouch::TDStretch::processSamples(), and soundtouch::RateTransposer::upsample().
Adjusts book-keeping so that given number of samples are removed from beginning of the sample buffer without copying them anywhere.
Used to reduce the number of samples in the buffer when accessing the sample buffer directly with 'ptrBegin' function.
| maxSamples | Remove this many samples from the beginning of pipe. |
Implements FIFOSamplePipe.
Definition at line 222 of file FIFOSampleBuffer.cpp.
| uint FIFOSampleBuffer::numSamples | ( | ) | const [virtual] |
Returns number of samples currently available.
Implements FIFOSamplePipe.
Definition at line 197 of file FIFOSampleBuffer.cpp.
Referenced by soundtouch::RateTransposer::downsample(), soundtouch::TDStretch::processNominalTempo(), soundtouch::TDStretch::processSamples(), and soundtouch::RateTransposer::upsample().
| void FIFOSampleBuffer::setChannels | ( | uint | numChannels | ) |
Sets number of channels, 1 = mono, 2 = stereo.
Definition at line 76 of file FIFOSampleBuffer.cpp.
Referenced by soundtouch::TDStretch::setChannels(), and soundtouch::RateTransposer::setChannels().
| int FIFOSampleBuffer::isEmpty | ( | ) | const [virtual] |
Returns nonzero if there aren't any samples available for outputting.
Implements FIFOSamplePipe.
Definition at line 241 of file FIFOSampleBuffer.cpp.
Referenced by soundtouch::RateTransposer::downsample(), soundtouch::RateTransposer::flushStoreBuffer(), and soundtouch::RateTransposer::isEmpty().
| void FIFOSampleBuffer::clear | ( | void | ) | [virtual] |
Clears all the samples.
Implements FIFOSamplePipe.
Definition at line 248 of file FIFOSampleBuffer.cpp.
Referenced by soundtouch::TDStretch::clear(), soundtouch::RateTransposer::clear(), and soundtouch::TDStretch::clearInput().
SAMPLETYPE* soundtouch::FIFOSampleBuffer::buffer [private] |
Sample buffer.
Definition at line 63 of file FIFOSampleBuffer.h.
Referenced by ensureCapacity(), FIFOSampleBuffer(), ptrBegin(), ptrEnd(), and rewind().
Definition at line 67 of file FIFOSampleBuffer.h.
Referenced by ensureCapacity(), FIFOSampleBuffer(), and ~FIFOSampleBuffer().
Sample buffer size in bytes.
Definition at line 70 of file FIFOSampleBuffer.h.
Referenced by ensureCapacity(), FIFOSampleBuffer(), and getCapacity().
How many samples are currently in buffer.
Definition at line 73 of file FIFOSampleBuffer.h.
Referenced by clear(), ensureCapacity(), FIFOSampleBuffer(), isEmpty(), numSamples(), ptrEnd(), putSamples(), receiveSamples(), rewind(), and setChannels().
uint soundtouch::FIFOSampleBuffer::channels [private] |
Channels, 1=mono, 2=stereo.
Definition at line 76 of file FIFOSampleBuffer.h.
Referenced by ensureCapacity(), FIFOSampleBuffer(), getCapacity(), ptrBegin(), ptrEnd(), putSamples(), receiveSamples(), rewind(), and setChannels().
uint soundtouch::FIFOSampleBuffer::bufferPos [private] |
Current position pointer to the buffer.
This pointer is increased when samples are removed from the pipe so that it's necessary to actually rewind buffer (move data) only new data when is put to the pipe.
Definition at line 81 of file FIFOSampleBuffer.h.
Referenced by clear(), ensureCapacity(), FIFOSampleBuffer(), ptrBegin(), receiveSamples(), and rewind().
1.6.3