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

Decodes WAV data to Linear PCM audio data. More...

#include <WavDecoder.hpp>

Public Member Functions

 WavDecoder (const std::string &path)
 WavDecoder constructor for decoding WAV from file path.
 
 ~WavDecoder ()
 
const uint getSampleRate () const
 Gets the sample rate of the audio.
 
const uint getNumberOfChannels () const
 Gets the number of channels of the audio.
 
const uint getNumberOfFrames () const
 Gets the number of frames of the audio.
 
const bool read (float *outputBuffer, const uint frameIndex, const uint numberOfFrames)
 Gets the next available chunk of audio.
 

Static Public Member Functions

static bool decode (const std::vector< uint8 > &inputData, std::vector< float > &outputData, uint &sampleRate, uint &numberOfChannels)
 Decodes input WAV byte data to Linear PCM data.
 

Detailed Description

Decodes WAV data to Linear PCM audio data.

WavDecoder class.

Constructor & Destructor Documentation

◆ WavDecoder()

switchboard::WavDecoder::WavDecoder ( const std::string & path)

WavDecoder constructor for decoding WAV from file path.

This constructor throws std::runtime_error if loading the audio file fails.

Parameters
pathThe path the audio file to load.

◆ ~WavDecoder()

switchboard::WavDecoder::~WavDecoder ( )
default

WavDecoder destructor.

Member Function Documentation

◆ decode()

bool switchboard::WavDecoder::decode ( const std::vector< uint8 > & inputData,
std::vector< float > & outputData,
uint & sampleRate,
uint & numberOfChannels )
static

Decodes input WAV byte data to Linear PCM data.

Parameters
inputDataThe vector that contains the WAV byte data.
outputDataThe vector that will contain the decoded PCM data.
sampleRateIn-out parameter that will contain the decoded WAV data sample rate.
numberOfChannelsIn-out parameter that will contain the decoded WAV data number of channels.
Returns
True if decoding was successful, false otherwise.

◆ getNumberOfChannels()

const uint switchboard::WavDecoder::getNumberOfChannels ( ) const

Gets the number of channels of the audio.

Returns
The number of channels of the audio.

◆ getNumberOfFrames()

const uint switchboard::WavDecoder::getNumberOfFrames ( ) const

Gets the number of frames of the audio.

Returns
The number of frames of the audio.

◆ getSampleRate()

const uint switchboard::WavDecoder::getSampleRate ( ) const

Gets the sample rate of the audio.

Returns
The sample rate of the audio.

◆ read()

const bool switchboard::WavDecoder::read ( float * outputBuffer,
const uint frameIndex,
const uint numberOfFrames )

Gets the next available chunk of audio.

Returns false in case the frame index overflows.

Pads the end with zeros if there is not enough frames to read.

Parameters
outputBufferThe buffer that will contain the output samples.
frameIndexReading starts at this frame index.
numberOfFramesThe number of frames to put in the output buffer.
Returns
True if reading from decoded audio was successful, false otherwise.