Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
switchboard::WavDecoder Class Reference

Decodes WAVdata to 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
 Get the sample rate of the audio.
 
const uint getNumberOfChannels () const
 Get the number of channels of the audio.
 
const uint getNumberOfFrames () const
 Get 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)
 Decode input WAV byte data to PCM data.
 

Detailed Description

Decodes WAVdata to 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

Decode input WAV byte data to 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.

◆ getNumberOfChannels()

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

Get the number of channels of the audio.

Returns
The number of channels of the audio.

◆ getNumberOfFrames()

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

Get the number of frames of the audio.

Returns
The number of frames of the audio.

◆ getSampleRate()

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

Get 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.

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