MythTV  0.28pre
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
soundtouch::FIFOSampleBuffer Class Reference

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

#include <FIFOSampleBuffer.h>

Inheritance diagram for soundtouch::FIFOSampleBuffer:
Inheritance graph
[legend]
Collaboration diagram for soundtouch::FIFOSampleBuffer:
Collaboration graph
[legend]

Public Member Functions

 FIFOSampleBuffer (uint numChannels=2)
 Constructor. More...
 
 ~FIFOSampleBuffer ()
 destructor More...
 
virtual SAMPLETYPEptrBegin () const
 Returns a pointer to the beginning of the output samples. More...
 
SAMPLETYPEptrEnd (uint slackCapacity)
 Returns a pointer to the end of the used part of the sample buffer (i.e. More...
 
virtual void putSamples (const SAMPLETYPE *samples, uint numSamples)
 Adds 'numSamples' pcs of samples from the 'samples' memory position to the sample buffer. More...
 
virtual void putSamples (uint numSamples)
 Adjusts the book-keeping to increase number of samples in the buffer without copying any actual samples. More...
 
virtual uint receiveSamples (SAMPLETYPE *output, uint maxSamples)
 Output samples from beginning of the sample buffer. More...
 
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. More...
 
virtual uint numSamples () const
 Returns number of samples currently available. More...
 
void setChannels (uint numChannels)
 Sets number of channels, 1 = mono, 2 = stereo. More...
 
virtual int isEmpty () const
 Returns nonzero if there aren't any samples available for outputting. More...
 
virtual void clear ()
 Clears all the samples. More...
 
- Public Member Functions inherited from FIFOSamplePipe
void moveSamples (FIFOSamplePipe &other)
 
virtual ~FIFOSamplePipe ()
 Destructor to shut gcc 4 up. More...
 

Private Member Functions

void rewind ()
 Rewind the buffer by moving data from position pointed by 'bufferPos' to real beginning of the buffer. More...
 
void ensureCapacity (const uint capacityRequirement)
 Ensures that the buffer has capacity for at least this many samples. More...
 
uint getCapacity () const
 Returns current capacity. More...
 

Private Attributes

SAMPLETYPEbuffer
 Sample buffer. More...
 
SAMPLETYPEbufferUnaligned
 
uint sizeInBytes
 Sample buffer size in bytes. More...
 
uint samplesInBuffer
 How many samples are currently in buffer. More...
 
uint channels
 Channels, 1=mono, 2=stereo. More...
 
uint bufferPos
 Current position pointer to the buffer. More...
 

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

FIFOSampleBuffer::FIFOSampleBuffer ( uint  numChannels = 2)

Constructor.

Parameters
numChannelsNumber 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.

Member Function Documentation

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.

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
void FIFOSampleBuffer::setChannels ( uint  numChannels)

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

void FIFOSampleBuffer::clear ( void  )
virtual

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

SAMPLETYPE* soundtouch::FIFOSampleBuffer::buffer
private

Sample buffer.

Definition at line 63 of file FIFOSampleBuffer.h.

SAMPLETYPE* soundtouch::FIFOSampleBuffer::bufferUnaligned
private

Definition at line 67 of file FIFOSampleBuffer.h.

Referenced by ensureCapacity(), FIFOSampleBuffer(), and ~FIFOSampleBuffer().

uint soundtouch::FIFOSampleBuffer::sizeInBytes
private

Sample buffer size in bytes.

Definition at line 70 of file FIFOSampleBuffer.h.

Referenced by ensureCapacity(), FIFOSampleBuffer(), and getCapacity().

uint soundtouch::FIFOSampleBuffer::samplesInBuffer
private

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


The documentation for this class was generated from the following files: