MythTV  0.26-pre
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends
Public Member Functions | Private Member Functions | Private Attributes
soundtouch::FIFOSampleBuffer Class Reference

Sample buffer working in FIFO (first-in-first-out) principle. More...

#include <FIFOSampleBuffer.h>

Inheritance diagram for soundtouch::FIFOSampleBuffer:
FIFOSamplePipe

List of all members.

Public Member Functions

 FIFOSampleBuffer (uint numChannels=2)
 Constructor.
 ~FIFOSampleBuffer ()
 destructor
virtual SAMPLETYPEptrBegin () const
 Returns a pointer to the beginning of the output samples.
SAMPLETYPEptrEnd (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

SAMPLETYPEbuffer
 Sample buffer.
SAMPLETYPEbufferUnaligned
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.

Detailed Description

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.


Constructor & Destructor Documentation

Constructor.

Parameters:
numChannelsNumber of channels, 1=mono, 2=stereo. Default is stereo.

Definition at line 57 of file FIFOSampleBuffer.cpp.

destructor

Definition at line 69 of file FIFOSampleBuffer.cpp.


Member Function Documentation

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().

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.

Parameters:
slackCapacityHow 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::RateTransposer::processSamples(), soundtouch::TDStretch::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.

Parameters:
samplesPointer to samples.
numSamplesNumber of samples to insert.

Implements FIFOSamplePipe.

Definition at line 101 of file FIFOSampleBuffer.cpp.

Referenced by soundtouch::RateTransposer::downsample(), soundtouch::TDStretch::processNominalTempo(), soundtouch::RateTransposer::processSamples(), soundtouch::TDStretch::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!

Parameters:
numSamplesNumber 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.

Returns:
Number of samples returned.
Parameters:
outputBuffer where to copy output samples.
maxSamplesHow 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().

uint FIFOSampleBuffer::receiveSamples ( uint  maxSamples) [virtual]

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.

Parameters:
maxSamplesRemove this many samples from the beginning of pipe.

Implements FIFOSamplePipe.

Definition at line 222 of file FIFOSampleBuffer.cpp.

uint FIFOSampleBuffer::numSamples ( ) const [virtual]

Sets number of channels, 1 = mono, 2 = stereo.

Definition at line 76 of file FIFOSampleBuffer.cpp.

Referenced by soundtouch::RateTransposer::setChannels(), and soundtouch::TDStretch::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().

Clears all the samples.

Implements FIFOSamplePipe.

Definition at line 248 of file FIFOSampleBuffer.cpp.

Referenced by soundtouch::RateTransposer::clear(), soundtouch::TDStretch::clear(), and soundtouch::TDStretch::clearInput().


Member Data Documentation

Sample buffer.

Definition at line 63 of file FIFOSampleBuffer.h.

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().

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().

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().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends