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

Resampling class for audio streams. More...

#include <StreamResampler.hpp>

Public Member Functions

 StreamResampler (int numberOfChannels)
 Constructor for StreamResampler.
 
 ~StreamResampler ()
 Destructor for StreamResampler.
 
int getNumberOfChannels () const
 Gets the number of channels.
 
double getRatio () const
 Gets the ratio of output to input sample rates, which is used internally for resampling.
 
int getInputSampleRate () const
 Gets the input sample rate.
 
int getOutputSampleRate () const
 Gets the output sample rate.
 
void setRatio (int inputSampleRate, int outputSampleRate)
 Sets the input and output sample rates.
 
void process (const float *inputBuffer, int inputBufferSize, float *outputBuffer, int outputBufferSize, bool endOfInput, long &inputFramesUsed, long &outputFramesGenerated)
 Processes the input audio buffer and generates the output audio buffer.
 
void reset ()
 Resets the internal state of the resampler.
 

Detailed Description

Resampling class for audio streams.

This class is a lightweight wrapper around the libsamplerate library. It provides a simple interface for resampling audio streams in real-time.

Constructor & Destructor Documentation

◆ StreamResampler()

switchboard::StreamResampler::StreamResampler ( int numberOfChannels)

Constructor for StreamResampler.

Parameters
numberOfChannelsThe number of audio channels to be resampled.

The numberOfChannels value cannot be changed after the object is created.

Member Function Documentation

◆ getInputSampleRate()

int switchboard::StreamResampler::getInputSampleRate ( ) const

Gets the input sample rate.

Returns
The input sample rate.

◆ getNumberOfChannels()

int switchboard::StreamResampler::getNumberOfChannels ( ) const

Gets the number of channels.

Returns
The number of channels.

◆ getOutputSampleRate()

int switchboard::StreamResampler::getOutputSampleRate ( ) const

Gets the output sample rate.

Returns
The output sample rate.

◆ getRatio()

double switchboard::StreamResampler::getRatio ( ) const

Gets the ratio of output to input sample rates, which is used internally for resampling.

Returns
The resampling ratio.

◆ process()

void switchboard::StreamResampler::process ( const float * inputBuffer,
int inputBufferSize,
float * outputBuffer,
int outputBufferSize,
bool endOfInput,
long & inputFramesUsed,
long & outputFramesGenerated )

Processes the input audio buffer and generates the output audio buffer.

Parameters
inputBufferThe input audio buffer.
inputBufferSizeThe size of the input buffer in frames.
outputBufferThe output audio buffer.
outputBufferSizeThe size of the output buffer in frames.
endOfInputIndicates if the end of the input stream has been reached.
inputFramesUsedThe number of input frames used for processing from the input buffer.
outputFramesGeneratedThe number of output frames generated in the output buffer.

Note, that not all input frames are guaranteed to be used. Always check the value of inputFramesUsed.

◆ reset()

void switchboard::StreamResampler::reset ( )

Resets the internal state of the resampler.

This method clears any internal buffers and resets the resampling state.

◆ setRatio()

void switchboard::StreamResampler::setRatio ( int inputSampleRate,
int outputSampleRate )

Sets the input and output sample rates.

Parameters
inputSampleRateThe input sample rate.
outputSampleRateThe output sample rate.

This method sets the input and output sample rates for resampling.