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

Provides audio data from an encoded audio file. More...

#include <AudioPlayerMemorySource.hpp>

Inheritance diagram for switchboard::AudioPlayerMemorySource:
switchboard::AudioPlayerSource

Public Member Functions

 AudioPlayerMemorySource (const std::string &filePath, Codec format)
 AudioPlayerMemorySource constructor for loading encoded audio from file path.
 
 AudioPlayerMemorySource (const std::vector< uint8 > &inputData, Codec format)
 AudioPlayerMemorySource constructor for loading audio from encoded data.
 
 AudioPlayerMemorySource (AudioBuffer< float > &audioBuffer, bool copyData)
 AudioPlayerMemorySource constructor for loading audio from an AudioBuffer instance.
 
const bool isLoopingEnabled () const override
 Indicates whether looping of the audio is enabled.
 
void setLoopingEnabled (bool enabled) override
 Enables or disables the looping of the loaded audio.
 
const uint getSampleRate () const override
 Get the sample rate of the audio.
 
const uint getNumberOfChannels () const override
 Get the number of channels of the audio.
 
const uint getNumberOfFrames () const override
 Get the number of frames of the audio.
 
const bool isFinished () const override
 Check if the provided audio has reached its end.
 
const double getDuration () const override
 
const double getPosition () const override
 
void setPosition (double position) override
 
double getStartPosition () const override
 
void setStartPosition (double startPosition) override
 
double getEndPosition () const override
 
void setEndPosition (double endPosition) override
 
const uint read (float *outputBuffer, const uint numberOfFrames) override
 Gets the next available chunk of audio.
 
- Public Member Functions inherited from switchboard::AudioPlayerSource
virtual ~AudioPlayerSource ()=default
 Default destructor.
 

Detailed Description

Provides audio data from an encoded audio file.

AudioPlayerMemorySource class.

This source loads the entire decoded audio data in memory.

Constructor & Destructor Documentation

◆ AudioPlayerMemorySource() [1/3]

switchboard::AudioPlayerMemorySource::AudioPlayerMemorySource ( const std::string & filePath,
Codec format )

AudioPlayerMemorySource constructor for loading encoded audio from file path.

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

Parameters
filePathThe path the audio file to load.
formatThe audio recording format.
Exceptions
std::runtime_errorThrown if path is not readable or audio data could not be decoded.

◆ AudioPlayerMemorySource() [2/3]

switchboard::AudioPlayerMemorySource::AudioPlayerMemorySource ( const std::vector< uint8 > & inputData,
Codec format )

AudioPlayerMemorySource constructor for loading audio from encoded data.

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

Parameters
inputDataVector containing the encoded audio data.
formatThe audio recording format.
Exceptions
std::runtime_errorThrown if audio data could not be decoded.

◆ AudioPlayerMemorySource() [3/3]

switchboard::AudioPlayerMemorySource::AudioPlayerMemorySource ( AudioBuffer< float > & audioBuffer,
bool copyData )

AudioPlayerMemorySource constructor for loading audio from an AudioBuffer instance.

Parameters
audioBufferThe audio buffer containing the audio data.
copyDataWhen set to true, the audio data from the audio buffer will be copied and stored in the AudioPlayerMemorySource instance.

Member Function Documentation

◆ getDuration()

const double switchboard::AudioPlayerMemorySource::getDuration ( ) const
overridevirtual

The duration of the currently playing media.

Returns
The duration of the media in seconds.

Implements switchboard::AudioPlayerSource.

◆ getEndPosition()

double switchboard::AudioPlayerMemorySource::getEndPosition ( ) const
overridevirtual

Indicates the current end position of the playback.

Returns
Returns the current end position in seconds.

Implements switchboard::AudioPlayerSource.

◆ getNumberOfChannels()

const uint switchboard::AudioPlayerMemorySource::getNumberOfChannels ( ) const
overridevirtual

Get the number of channels of the audio.

Returns
The number of channels of the audio.

Implements switchboard::AudioPlayerSource.

◆ getNumberOfFrames()

const uint switchboard::AudioPlayerMemorySource::getNumberOfFrames ( ) const
overridevirtual

Get the number of frames of the audio.

Returns
The number of frames of the audio.

Implements switchboard::AudioPlayerSource.

◆ getPosition()

const double switchboard::AudioPlayerMemorySource::getPosition ( ) const
overridevirtual

Indicates the current position of the playhead.

Returns
Returns the elapsed time in seconds.

Implements switchboard::AudioPlayerSource.

◆ getSampleRate()

const uint switchboard::AudioPlayerMemorySource::getSampleRate ( ) const
overridevirtual

Get the sample rate of the audio.

Returns
The sample rate of the audio.

Implements switchboard::AudioPlayerSource.

◆ getStartPosition()

double switchboard::AudioPlayerMemorySource::getStartPosition ( ) const
overridevirtual

Indicates the current start position of the playback.

Returns
Returns the current start position in seconds.

Implements switchboard::AudioPlayerSource.

◆ isFinished()

const bool switchboard::AudioPlayerMemorySource::isFinished ( ) const
overridevirtual

Check if the provided audio has reached its end.

Returns
True if the provided audio has reached its end.

Implements switchboard::AudioPlayerSource.

◆ isLoopingEnabled()

const bool switchboard::AudioPlayerMemorySource::isLoopingEnabled ( ) const
overridevirtual

Indicates whether looping of the audio is enabled.

Returns
True when it is enabled, false when it is not.

Implements switchboard::AudioPlayerSource.

◆ read()

const uint switchboard::AudioPlayerMemorySource::read ( float * outputBuffer,
const uint numberOfFrames )
overridevirtual

Gets the next available chunk of audio.

Parameters
outputBufferThe buffer that will contain the output samples.
numberOfFramesThe number of frames to put in the output buffer.
Returns
The number of "useful" audio frames put in outputBuffer.

Implements switchboard::AudioPlayerSource.

◆ setEndPosition()

void switchboard::AudioPlayerMemorySource::setEndPosition ( double endPosition)
overridevirtual

Sets the ending position of the playback.

Parameters
endPositionThe desired position in seconds.

Implements switchboard::AudioPlayerSource.

◆ setLoopingEnabled()

void switchboard::AudioPlayerMemorySource::setLoopingEnabled ( bool enabled)
overridevirtual

Enables or disables the looping of the loaded audio.

Parameters
enabledTrue when it is enabled, false when it is not.

Implements switchboard::AudioPlayerSource.

◆ setPosition()

void switchboard::AudioPlayerMemorySource::setPosition ( double position)
overridevirtual

Sets the playhead to the desired position

Parameters
positionThe desired position in seconds.

Implements switchboard::AudioPlayerSource.

◆ setStartPosition()

void switchboard::AudioPlayerMemorySource::setStartPosition ( double startPosition)
overridevirtual

Sets the starting position of the playback.

Parameters
startPositionThe desired position in seconds.

Implements switchboard::AudioPlayerSource.