TracktionEngine
|
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. | |
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.
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.
engine::ReadAheadTimeStretcher::~ReadAheadTimeStretcher | ( | ) |
Destructor.
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.
sourceSampleRate | The sample rate this will be processed at |
samplesPerBlock | The expected number of samples per process block |
numChannels | The number of channels to process |
Mode | The Mode to enable |
ElastiqueProOptions | The Elastique options to use, ignored in non-ElastiquePro modes |
realtime | Indicates this is for real-time or offline use |
bool engine::ReadAheadTimeStretcher::isInitialised | ( | ) | const |
Returns true if this has been fully initialised.
void engine::ReadAheadTimeStretcher::reset | ( | ) |
Resets the TimeStretcher ready for a new set of audio data, maintains mode, speed and pitch ratios.
bool engine::ReadAheadTimeStretcher::setSpeedAndPitch | ( | float | speedRatio, |
float | semitones | ||
) |
Sets the timestretch speed ratio and semitones pitch shift.
speedRatio | The ratio for timestretched speed. 1 = no stretching, 2 = half as fast, 0.5 = twice as fast etc. |
semitones | The number of semitones to adjust the pitch by 0 = not shift, 12 = up one oct, -12 = down one oct etc. |
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.
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.
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()
bool engine::ReadAheadTimeStretcher::requiresMoreFrames | ( | ) | const |
Returns true if more frames are required to be pushed in order for a pop operation to succeed.
int engine::ReadAheadTimeStretcher::getFreeSpace | ( | ) | const |
Returns the number of samples that can be pushed to the input, ready to be processed.
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.
int engine::ReadAheadTimeStretcher::getNumReady | ( | ) | const |
Returns the number of samples ready in the output buffer which can be retrieved without processing the time-stretch.
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.
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.
outChannels | The 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. |