tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
Classes | 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.

Definition at line 21 of file tracktion_ReadAheadTimeStretcher.h.

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.

Definition at line 98 of file tracktion_ReadAheadTimeStretcher.cpp.

◆ ~ReadAheadTimeStretcher()

engine::ReadAheadTimeStretcher::~ReadAheadTimeStretcher ( )

Destructor.

Definition at line 103 of file tracktion_ReadAheadTimeStretcher.cpp.

Member Function Documentation

◆ 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

Definition at line 224 of file tracktion_ReadAheadTimeStretcher.cpp.

◆ 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.

Definition at line 165 of file tracktion_ReadAheadTimeStretcher.cpp.

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

Definition at line 171 of file tracktion_ReadAheadTimeStretcher.cpp.

◆ getFreeSpace()

int engine::ReadAheadTimeStretcher::getFreeSpace ( ) const

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

Definition at line 188 of file tracktion_ReadAheadTimeStretcher.cpp.

◆ 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.

Definition at line 159 of file tracktion_ReadAheadTimeStretcher.cpp.

◆ 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.

Definition at line 203 of file tracktion_ReadAheadTimeStretcher.cpp.

◆ initialise()

void engine::ReadAheadTimeStretcher::initialise ( double  sourceSampleRate,
int  samplesPerBlock,
int  numChannels,
TimeStretcher::Mode  mode,
TimeStretcher::ElastiqueProOptions  proOpts,
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

Definition at line 108 of file tracktion_ReadAheadTimeStretcher.cpp.

◆ isInitialised()

bool engine::ReadAheadTimeStretcher::isInitialised ( ) const

Returns true if this has been fully initialised.

Definition at line 129 of file tracktion_ReadAheadTimeStretcher.cpp.

◆ 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

Definition at line 208 of file tracktion_ReadAheadTimeStretcher.cpp.

◆ 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

Definition at line 193 of file tracktion_ReadAheadTimeStretcher.cpp.

◆ requiresMoreFrames()

bool engine::ReadAheadTimeStretcher::requiresMoreFrames ( ) const

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

Definition at line 183 of file tracktion_ReadAheadTimeStretcher.cpp.

◆ reset()

void engine::ReadAheadTimeStretcher::reset ( )

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

Definition at line 134 of file tracktion_ReadAheadTimeStretcher.cpp.

◆ 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.

Definition at line 148 of file tracktion_ReadAheadTimeStretcher.cpp.


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