Switchboard SDK
Loading...
Searching...
No Matches
switchboard::Resampler Class Reference

Resamples audio data from one sample rate to another. More...

#include <Resampler.hpp>

Public Member Functions

 Resampler (const uint maxNumberOfChannels=constants::STEREO, const uint maxNumberOfFrames=constants::MAX_NUMBER_OF_FRAMES)
 Creates a Resampler instance.
 
 ~Resampler ()
 Resampler destructor.
 
uint process (const AudioBuffer< int16 > &input, AudioBuffer< int16 > &output, const uint inputSampleRate, const uint outputSampleRate)
 Resamples an input buffer of sampling rate N, to an output buffer of sampling rate M.
 
uint process (const AudioBuffer< float > &input, AudioBuffer< float > &output, const uint inputSampleRate, const uint outputSampleRate)
 Resamples an input buffer of sampling rate N, to an output buffer of sampling rate M.
 
uint process (const int16 *input, float *output, uint inputSampleRate, uint outputSampleRate, uint numberOfInputFrames, uint maxNumberOfOutputFrames, uint numChannels, bool endOfInput=false)
 Resamples an input buffer of sampling rate N, to an output buffer of sampling rate M.
 
uint process (const float *input, float *output, uint inputSampleRate, uint outputSampleRate, uint numberOfInputFrames, uint maxNumberOfOutputFrames, uint numChannels, bool endOfInput=false)
 Resamples an input buffer of sampling rate N, to an output buffer of sampling rate M.
 
void process (const float *input, float *output, uint inputSampleRate, uint outputSampleRate, uint numberOfInputFrames, uint maxNumberOfOutputFrames, uint numChannels, bool endOfInput, uint &numberOfInputFramesUsed, uint &numberOfOutputFramesGenerated)
 Resamples an input buffer of sampling rate N, to an output buffer of sampling rate M.
 
void reset ()
 Resets the resampler after endOfInput is set to true in the process method. Needs to be called before a new stream of data is input to the process method.
 
int getNumberOfBufferedFrames () const
 Retrieves the number of buffered frames currently in the Resampler.
 

Detailed Description

Resamples audio data from one sample rate to another.

Resampler class.

Constructor & Destructor Documentation

◆ Resampler()

switchboard::Resampler::Resampler ( const uint maxNumberOfChannels = constants::STEREO,
const uint maxNumberOfFrames = constants::MAX_NUMBER_OF_FRAMES )

Creates a Resampler instance.

Parameters
maxNumberOfChannelsMaximum number of channels that is supported by the resampler, determines buffer sizes.
maxNumberOfFramesMaximum number of frames that is supported by the resampler, determines buffer sizes.

Member Function Documentation

◆ getNumberOfBufferedFrames()

int switchboard::Resampler::getNumberOfBufferedFrames ( ) const

Retrieves the number of buffered frames currently in the Resampler.

The count returned by this method is indicative of the internal state of the Resampler's buffering system and can be used for diagnostics or managing the flow of data through the Resampler.

Returns
The number of buffered frames in the Resampler.

◆ process() [1/5]

uint switchboard::Resampler::process ( const AudioBuffer< float > & input,
AudioBuffer< float > & output,
const uint inputSampleRate,
const uint outputSampleRate )

Resamples an input buffer of sampling rate N, to an output buffer of sampling rate M.

Parameters
inputThe float input buffer that needs to be resampled. Either interleaved stereo or mono.
outputThe resampled output buffer. Interleaved stereo. Should not be the same as output.
inputSampleRateThe sample rate of the input buffer.
outputSampleRateThe target sample rate of the output buffer.
Returns
The number of frames in the resampled output buffer.

◆ process() [2/5]

uint switchboard::Resampler::process ( const AudioBuffer< int16 > & input,
AudioBuffer< int16 > & output,
const uint inputSampleRate,
const uint outputSampleRate )

Resamples an input buffer of sampling rate N, to an output buffer of sampling rate M.

Parameters
inputThe short input buffer that needs to be resampled. Either interleaved stereo or mono.
outputThe resampled output buffer. Interleaved stereo. Should not be the same as output.
inputSampleRateThe sample rate of the input buffer.
outputSampleRateThe target sample rate of the output buffer.
Returns
The number of frames in the resampled output buffer.

◆ process() [3/5]

void switchboard::Resampler::process ( const float * input,
float * output,
uint inputSampleRate,
uint outputSampleRate,
uint numberOfInputFrames,
uint maxNumberOfOutputFrames,
uint numChannels,
bool endOfInput,
uint & numberOfInputFramesUsed,
uint & numberOfOutputFramesGenerated )

Resamples an input buffer of sampling rate N, to an output buffer of sampling rate M.

Parameters
inputThe float input buffer that needs to be resampled. Either interleaved stereo or mono.
outputThe resampled output buffer. Interleaved stereo. Should not be the same as output.
inputSampleRateThe sample rate of the input buffer.
outputSampleRateThe target sample rate of the output buffer.
numberOfInputFramesNumber of frames in the input.
maxNumberOfOutputFramesMax number of frames in the output. Derived from the sample rate ratio.
numChannelsIndicates the number of channels.
endOfInputOptional - Signals the end of input in a stream of input buffers. Resampler needs to be reset after it is set to true.
numberOfInputFramesUsedThe number of frames used from the input buffer to generate the output.
numberOfOutputFramesGeneratedThe number of frames written to the output buffer.

◆ process() [4/5]

uint switchboard::Resampler::process ( const float * input,
float * output,
uint inputSampleRate,
uint outputSampleRate,
uint numberOfInputFrames,
uint maxNumberOfOutputFrames,
uint numChannels,
bool endOfInput = false )

Resamples an input buffer of sampling rate N, to an output buffer of sampling rate M.

Parameters
inputThe float input buffer that needs to be resampled. Either interleaved stereo or mono.
outputThe resampled output buffer. Interleaved stereo. Should not be the same as output.
inputSampleRateThe sample rate of the input buffer.
outputSampleRateThe target sample rate of the output buffer.
numberOfInputFramesNumber of frames in the input.
maxNumberOfOutputFramesMax number of frames in the output. Derived from the sample rate ratio.
numChannelsIndicates the number of channels.
endOfInputOptional - Signals the end of input in a stream of input buffers. Resampler needs to be reset after it is set to true.
Returns
The number of frames in the resampled output buffer.

◆ process() [5/5]

uint switchboard::Resampler::process ( const int16 * input,
float * output,
uint inputSampleRate,
uint outputSampleRate,
uint numberOfInputFrames,
uint maxNumberOfOutputFrames,
uint numChannels,
bool endOfInput = false )

Resamples an input buffer of sampling rate N, to an output buffer of sampling rate M.

Parameters
inputThe short input buffer that needs to be resampled. Either interleaved stereo or mono.
outputThe resampled output buffer. Interleaved stereo. Should not be the same as output.
inputSampleRateThe sample rate of the input buffer.
outputSampleRateThe target sample rate of the output buffer.
numberOfInputFramesNumber of frames in the input.
maxNumberOfOutputFramesMax number of frames in the output. Derived from the sample rate ratio.
numChannelsIndicates the number of channels.
endOfInputOptional - Signals the end of input in a stream of input buffers. Resampler needs to be reset after it is set to true.
Returns
The number of frames in the resampled output buffer.