TracktionEngine
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
tracktion::engine::TimeStretcher Class Reference

Handles time/pitch stretching using various supported libraries. More...

Classes

struct  ElastiqueProOptions
 A set of options that can be used in conjunction with the elastiquePro Mode to fine tune the algorithm. More...
 

Public Types

enum  Mode {
  disabled = 0 , elastiqueTransient = 1 , elastiqueTonal = 2 , soundtouchNormal = 3 ,
  soundtouchBetter = 4 , melodyne = 5 , elastiquePro = 6 , elastiqueEfficient = 7 ,
  elastiqueMobile = 8 , elastiqueMonophonic = 9 , rubberbandMelodic = 10 , rubberbandPercussive = 11 ,
  defaultMode = disabled
}
 Holds the various algorithms to which can be used (if enabled). More...
 

Public Member Functions

 TimeStretcher ()
 Creates an TimeStretcher using the default mode. More...
 
 ~TimeStretcher ()
 Destructor. More...
 
void initialise (double sourceSampleRate, int samplesPerBlock, int numChannels, Mode, ElastiqueProOptions, bool realtime)
 Initialises the TimeStretcher ready to perform timestretching. More...
 
bool isInitialised () const
 Returns true if this has been fully initialised. More...
 
void reset ()
 Resets the TimeStretcher ready for a new set of audio data, maintains mode, speed and pitch ratios. More...
 
bool setSpeedAndPitch (float speedRatio, float semitones)
 Sets the timestretch speed ratio and semitones pitch shift. More...
 
int getMaxFramesNeeded () const
 Returns the maximum number of frames that will ever be returned by getFramesNeeded. More...
 
int getFramesNeeded () const
 Returns the expected number of frames required to generate some output. More...
 
int processData (const float *const *inChannels, int numSamples, float *const *outChannels)
 Processes some input frames and fills some output frames with the applied speed ratio and pitch shift. More...
 
int processData (AudioFifo &inFifo, int numSamples, AudioFifo &outFifo)
 Processes some input frames and fills some output frames from a pair of AudioFifos, useful for real-time use. More...
 
int flush (float *const *outChannels)
 Flushes the end of the stream when input data is exhausted but there is still output data available. More...
 

Static Public Member Functions

static Mode checkModeIsAvailable (Mode)
 Checks if the given mode is available for use. More...
 
static juce::StringArray getPossibleModes (Engine &, bool excludeMelodyne)
 Returns the names of the availabel Modes. More...
 
static Mode getModeFromName (Engine &, const juce::String &name)
 Returns the Mode for a given name. More...
 
static juce::String getNameOfMode (Mode)
 Returns the name of a given Mode for display purposes. More...
 
static bool isMelodyne (Mode)
 Returns true if the given Mode is a Melodyne mode. More...
 
static bool canProcessFor (Mode)
 Checks that the given Mode is a valid mode and not disabled. More...
 

Detailed Description

Handles time/pitch stretching using various supported libraries.

Currently supported libraries are SoundTouch, RubberBand and Elastique. These libraries may require additional module config options to enable and fall under their own licence terms so make sure to check those before distributing any code.

Member Enumeration Documentation

◆ Mode

Holds the various algorithms to which can be used (if enabled).

Enumerator
disabled 

No algorithm enabled.

elastiqueTransient 

Defunct, don't use.

elastiqueTonal 

Defunct, don't use.

soundtouchNormal 

SoundTouch normal quality, lower CPU use.

soundtouchBetter 

SoundTouch better quality, higher CPU use.

melodyne 

Melodyne, only used for clip timestretching.

elastiquePro 

Elastique Pro good all round (.

See also
ElastiqueProOptions).
elastiqueEfficient 

Elastique lower quality and lower CPU usage.

elastiqueMobile 

Elastique lower quality and lower CPU usage, optimised for mobile.

elastiqueMonophonic 

Elastique which can sound better for monophonic sounds.

rubberbandMelodic 

RubberBand tailored to melodic sounds prioritising pitch accuracy.

rubberbandPercussive 

RubberBand tailored to percussive sounds prioritising transient accuracy.

defaultMode 

Default mode.

Constructor & Destructor Documentation

◆ TimeStretcher()

tracktion::engine::TimeStretcher::TimeStretcher ( )

Creates an TimeStretcher using the default mode.

◆ ~TimeStretcher()

tracktion::engine::TimeStretcher::~TimeStretcher ( )

Destructor.

Member Function Documentation

◆ checkModeIsAvailable()

static Mode tracktion::engine::TimeStretcher::checkModeIsAvailable ( Mode  )
static

Checks if the given mode is available for use.

◆ getPossibleModes()

static juce::StringArray tracktion::engine::TimeStretcher::getPossibleModes ( Engine ,
bool  excludeMelodyne 
)
static

Returns the names of the availabel Modes.

◆ getModeFromName()

static Mode tracktion::engine::TimeStretcher::getModeFromName ( Engine ,
const juce::String &  name 
)
static

Returns the Mode for a given name.

See also
getPossibleModes.

◆ getNameOfMode()

static juce::String tracktion::engine::TimeStretcher::getNameOfMode ( Mode  )
static

Returns the name of a given Mode for display purposes.

◆ isMelodyne()

static bool tracktion::engine::TimeStretcher::isMelodyne ( Mode  )
static

Returns true if the given Mode is a Melodyne mode.

◆ canProcessFor()

static bool tracktion::engine::TimeStretcher::canProcessFor ( Mode  )
static

Checks that the given Mode is a valid mode and not disabled.

◆ initialise()

void tracktion::engine::TimeStretcher::initialise ( double  sourceSampleRate,
int  samplesPerBlock,
int  numChannels,
Mode  ,
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 tracktion::engine::TimeStretcher::isInitialised ( ) const

Returns true if this has been fully initialised.

◆ reset()

void tracktion::engine::TimeStretcher::reset ( )

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

◆ setSpeedAndPitch()

bool tracktion::engine::TimeStretcher::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 tracktion::engine::TimeStretcher::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 tracktion::engine::TimeStretcher::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 passes to processData.

◆ processData() [1/2]

int tracktion::engine::TimeStretcher::processData ( const float *const *  inChannels,
int  numSamples,
float *const *  outChannels 
)

Processes some input frames and fills some output frames with the applied speed ratio and pitch shift.

Parameters
inChannelsThe input sample data in non-interleaved format
numSamplesThe number of input frames to read from inChannels
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

◆ processData() [2/2]

int tracktion::engine::TimeStretcher::processData ( AudioFifo inFifo,
int  numSamples,
AudioFifo outFifo 
)

Processes some input frames and fills some output frames from a pair of AudioFifos, useful for real-time use.

Parameters
inFifoThe input sample data to read from
numSamplesThe number of input frames to read from inFifo. In inFifo must have this number of frames ready
outFifoThe destination for output samples. This should have at lest samplesPerBlock free.
Returns
The number of frames read and hence written to outFifo

◆ flush()

int tracktion::engine::TimeStretcher::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: