SuperpoweredSDK  v2.0.2
Superpowered Audio SDK
Superpowered::TimeStretching Class Reference

Time stretching and pitch shifting. More...

#include "SuperpoweredTimeStretching.h"

Collaboration diagram for Superpowered::TimeStretching:

Public Member Functions

 TimeStretching (unsigned int samplerate, float minimumRate=0.01f, unsigned char sound=1)
 Constructor. More...
 
 ~TimeStretching ()
 
void addInput (float *input, int numberOfFrames)
 Processes audio. More...
 
void advancedProcess (AudiopointerlistElement *input)
 Processes audio. More...
 
unsigned int getNumberOfInputFramesNeeded ()
 
bool getOutput (float *output, int numberOfFrames)
 Gets the audio output into a buffer. More...
 
unsigned int getOutputLengthFrames ()
 
void removeFramesFromInputBuffersEnd (unsigned int numberOfFrames)
 Removes audio from the end of the input buffer. More...
 
void reset ()
 Reset all internals, sets the instance as good as new. More...
 
void setStereoPairs (unsigned int numStereoPairs)
 This class can handle one stereo audio channel pair by default (left+right). More...
 

Public Attributes

Superpowered::AudiopointerListoutputList
 The AudiopointerList storing the audio output. To be used with the advancedProcess() method. Read only. More...
 
int pitchShiftCents
 Pitch shift cents, limited from -2400 (two octaves down) to 2400 (two octaves up). More...
 
float rate
 Time stretching rate (tempo). 1 means no time stretching. Maximum: 4. Values above 2 or below 0.5 are not recommended on mobile devices with low latency audio due high CPU load and risk of audio dropouts. More...
 
unsigned int samplerate
 Sample rate in Hz. More...
 

Private Member Functions

 TimeStretching (const TimeStretching &)
 
TimeStretchingoperator= (const TimeStretching &)
 

Private Attributes

stretchInternals * internals
 

Detailed Description

Time stretching and pitch shifting.

One instance allocates around 220 kb memory.

Constructor & Destructor Documentation

◆ TimeStretching() [1/2]

Superpowered::TimeStretching::TimeStretching ( unsigned int  samplerate,
float  minimumRate = 0.01f,
unsigned char  sound = 1 
)

Constructor.

Parameters
samplerateThe initial sample rate in Hz.
minimumRateThe minimum value of rate. For example: if the rate will never go below 0.5, minimumRate = 0.5 will save significant computing power and memory. Minimum value of this: 0.01.
soundValid values are: 0 (best to save CPU with slightly lower audio quality), 1 (best for DJ apps, modern and "complete" music), 2 (best for instrumental loops and single instruments).

◆ ~TimeStretching()

Superpowered::TimeStretching::~TimeStretching ( )

◆ TimeStretching() [2/2]

Superpowered::TimeStretching::TimeStretching ( const TimeStretching )
private

Member Function Documentation

◆ addInput()

void Superpowered::TimeStretching::addInput ( float *  input,
int  numberOfFrames 
)

Processes audio.

It's never blocking for real-time usage. You can change all properties on any thread, concurrently with process(). Use it in the same thread with the other real-time methods of this class.

Parameters
inputPointer to floating point numbers. 32-bit interleaved stereo input.
numberOfFramesNumber of frames to process.

◆ advancedProcess()

void Superpowered::TimeStretching::advancedProcess ( AudiopointerlistElement input)

Processes audio.

For advanced uses to:

  1. Save memory bandwidth (uses no memory copy) for maximum performance.
  2. Support up to 8 audio channels.
  3. Provide sub-sample precise positioning. It's never blocking for real-time usage. You can change all properties on any thread, concurrently with process(). Use it in the same thread with the other real-time methods of this class. Do not use this method with addInput() or getOutput().
    Parameters
    inputThe input buffer. It will take ownership on the input.

◆ getNumberOfInputFramesNeeded()

unsigned int Superpowered::TimeStretching::getNumberOfInputFramesNeeded ( )
Returns
Returns with how many frames of input should be provided to the time stretcher to produce some output. It's never blocking for real-time usage. Use it in the same thread with the other real-time methods of this class. The result can be 0 if rate is 1 and pitch shift is 0, because in that case the time stretcher is fully "transparent" and any number of input frames will produce some output.

◆ getOutput()

bool Superpowered::TimeStretching::getOutput ( float *  output,
int  numberOfFrames 
)

Gets the audio output into a buffer.

It's never blocking for real-time usage. You can change all properties on any thread, concurrently with process(). Use it in the same thread with the other real-time methods of this class.

Returns
True if it has enough output frames stored and output is successfully written, false otherwise.
Parameters
outputPointer to floating point numbers. 32-bit interleaved stereo output.
numberOfFramesNumber of frames to return with.

◆ getOutputLengthFrames()

unsigned int Superpowered::TimeStretching::getOutputLengthFrames ( )
Returns
Returns with how many frames of output is available. It's never blocking for real-time usage. Use it in the same thread with the other real-time methods of this class.

◆ operator=()

TimeStretching& Superpowered::TimeStretching::operator= ( const TimeStretching )
private

◆ removeFramesFromInputBuffersEnd()

void Superpowered::TimeStretching::removeFramesFromInputBuffersEnd ( unsigned int  numberOfFrames)

Removes audio from the end of the input buffer.

Can be useful for some looping use-cases for example. It's never blocking for real-time usage. Use it in the same thread with the other real-time methods of this class.

Parameters
numberOfFramesThe number of frames to remove.

◆ reset()

void Superpowered::TimeStretching::reset ( )

Reset all internals, sets the instance as good as new.

Don't call this concurrently with process() and in a real-time thread.

◆ setStereoPairs()

void Superpowered::TimeStretching::setStereoPairs ( unsigned int  numStereoPairs)

This class can handle one stereo audio channel pair by default (left+right).

Maybe you need more if you load some music with 4 channels, then less if you load a regular stereo track. Don't call this concurrently with process() and in a real-time thread.

Parameters
numStereoPairsThe number of stereo audio channel pairs. Valid values: one (stereo) to four (8 channels).

Member Data Documentation

◆ internals

stretchInternals* Superpowered::TimeStretching::internals
private

◆ outputList

Superpowered::AudiopointerList* Superpowered::TimeStretching::outputList

The AudiopointerList storing the audio output. To be used with the advancedProcess() method. Read only.

◆ pitchShiftCents

int Superpowered::TimeStretching::pitchShiftCents

Pitch shift cents, limited from -2400 (two octaves down) to 2400 (two octaves up).

Examples: 0 (no pitch shift), -100 (one note down), 300 (3 notes up). When the value if a multiply of 100 and is >= -1200 and <= 1200, changing the pitch shift needs only a few CPU clock cycles. Any change in pitchShiftCents involves significant momentary CPU load otherwise.

◆ rate

float Superpowered::TimeStretching::rate

Time stretching rate (tempo). 1 means no time stretching. Maximum: 4. Values above 2 or below 0.5 are not recommended on mobile devices with low latency audio due high CPU load and risk of audio dropouts.

◆ samplerate

unsigned int Superpowered::TimeStretching::samplerate

Sample rate in Hz.


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