TracktionEngine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
engine::ReadAheadTimeStretcher Class Reference

Wraps a TimeStretcher but keeps a larger internal input and output buffer and uses a background thread to try and process frames, reducing CPU cost on real-time threads. More...

#include <tracktion_ReadAheadTimeStretcher.h>

Public Member Functions

 ReadAheadTimeStretcher (int numBlocksToReadAhead)
 Creates a ReadAheadTimeStretcher that will attempt to process the desired number of blocks on a background thread.
 
 ~ReadAheadTimeStretcher ()
 Destructor.
 
void initialise (double sourceSampleRate, int samplesPerBlock, int numChannels, TimeStretcher::Mode, TimeStretcher::ElastiqueProOptions, bool realtime)
 Initialises the TimeStretcher ready to perform timestretching.
 
bool isInitialised () const
 Returns true if this has been fully initialised.
 
void reset ()
 Resets the TimeStretcher ready for a new set of audio data, maintains mode, speed and pitch ratios.
 
bool setSpeedAndPitch (float speedRatio, float semitones)
 Sets the timestretch speed ratio and semitones pitch shift.
 
int getMaxFramesNeeded () const
 Returns the maximum number of frames that will ever be returned by getFramesNeeded.
 
int getFramesNeeded () const
 Returns the expected number of frames required to generate some output.
 
int getFramesRecomended () const
 Returns the number of frames that should be pushed to ensure the background thread has ample to work with.
 
bool requiresMoreFrames () const
 Returns true if more frames are required to be pushed in order for a pop operation to succeed.
 
int getFreeSpace () const
 Returns the number of samples that can be pushed to the input, ready to be processed.
 
int pushData (const float *const *inChannels, int numSamples)
 Pushes a number of samples to the instance ready to be time-stretched.
 
int getNumReady () const
 Returns the number of samples ready in the output buffer which can be retrieved without processing the time-stretch.
 
int popData (float *const *outChannels, int numSamples)
 Retrieves some samples from the output buffer.
 
int flush (float *const *outChannels)
 Flushes the end of the stream when input data is exhausted but there is still output data available.
 

Detailed Description

Wraps a TimeStretcher but keeps a larger internal input and output buffer and uses a background thread to try and process frames, reducing CPU cost on real-time threads.

Constructor & Destructor Documentation

◆ ReadAheadTimeStretcher()

engine::ReadAheadTimeStretcher::ReadAheadTimeStretcher ( int  numBlocksToReadAhead)

Creates a ReadAheadTimeStretcher that will attempt to process the desired number of blocks on a background thread.

The number of blocks is a multiple of that passed to the initalise call.

◆ ~ReadAheadTimeStretcher()

engine::ReadAheadTimeStretcher::~ReadAheadTimeStretcher ( )

Destructor.

Member Function Documentation

◆ initialise()

void engine::ReadAheadTimeStretcher::initialise ( double  sourceSampleRate,
int  samplesPerBlock,
int  numChannels,
TimeStretcher::Mode  ,
TimeStretcher::ElastiqueProOptions  ,
bool  realtime 
)

Initialises the TimeStretcher ready to perform timestretching.

This must be called at least once before calling the processData methods.

Parameters
sourceSampleRateThe sample rate this will be processed at
samplesPerBlockThe expected number of samples per process block
numChannelsThe number of channels to process
ModeThe Mode to enable
ElastiqueProOptionsThe Elastique options to use, ignored in non-ElastiquePro modes
realtimeIndicates this is for real-time or offline use

◆ isInitialised()

bool engine::ReadAheadTimeStretcher::isInitialised ( ) const

Returns true if this has been fully initialised.

◆ reset()

void engine::ReadAheadTimeStretcher::reset ( )

Resets the TimeStretcher ready for a new set of audio data, maintains mode, speed and pitch ratios.

◆ setSpeedAndPitch()

bool engine::ReadAheadTimeStretcher::setSpeedAndPitch ( float  speedRatio,
float  semitones 
)

Sets the timestretch speed ratio and semitones pitch shift.

Parameters
speedRatioThe ratio for timestretched speed. 1 = no stretching, 2 = half as fast, 0.5 = twice as fast etc.
semitonesThe number of semitones to adjust the pitch by 0 = not shift, 12 = up one oct, -12 = down one oct etc.

◆ getMaxFramesNeeded()

int engine::ReadAheadTimeStretcher::getMaxFramesNeeded ( ) const

Returns the maximum number of frames that will ever be returned by getFramesNeeded.

This can be used to size FIFOs for real-time use accordingly.

◆ getFramesNeeded()

int engine::ReadAheadTimeStretcher::getFramesNeeded ( ) const

Returns the expected number of frames required to generate some output.

This should be queried each block and the returned number of frames be passed to pushData.

◆ getFramesRecomended()

int engine::ReadAheadTimeStretcher::getFramesRecomended ( ) const

Returns the number of frames that should be pushed to ensure the background thread has ample to work with.

This also prioritises a fast startup where possible after a reset()

◆ requiresMoreFrames()

bool engine::ReadAheadTimeStretcher::requiresMoreFrames ( ) const

Returns true if more frames are required to be pushed in order for a pop operation to succeed.

◆ getFreeSpace()

int engine::ReadAheadTimeStretcher::getFreeSpace ( ) const

Returns the number of samples that can be pushed to the input, ready to be processed.

◆ pushData()

int engine::ReadAheadTimeStretcher::pushData ( const float *const *  inChannels,
int  numSamples 
)

Pushes a number of samples to the instance ready to be time-stretched.

N.B. This doesn't actually do any processing so should be quick.

Returns
The number of samples read

◆ getNumReady()

int engine::ReadAheadTimeStretcher::getNumReady ( ) const

Returns the number of samples ready in the output buffer which can be retrieved without processing the time-stretch.

◆ popData()

int engine::ReadAheadTimeStretcher::popData ( float *const *  outChannels,
int  numSamples 
)

Retrieves some samples from the output buffer.

N.B. If there aren't enough samples already processed this will do the processing so its cost can vary.

Returns
The number of samples read

◆ flush()

int engine::ReadAheadTimeStretcher::flush ( float *const *  outChannels)

Flushes the end of the stream when input data is exhausted but there is still output data available.

Once you have called this, you can no longer call processData.

Parameters
outChannelsThe destination for non-interleaved output samples. This should be as big as samplesPerBlock passed to the constructor but it may not fill the whole buffer. In cases where less than samplesPerBlock is returned, you should query getFramesNeeded and call this method again, incrementing destination buffers as required.
Returns
The number of frames read and hence written to outChannels

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