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

AudioNode that plays the loaded audio file. More...

#include <AudioPlayerNode.hpp>

Inheritance diagram for switchboard::AudioPlayerNode:

Public Member Functions

SB_WASM AudioPlayerNode ()
 Creates a AudioPlayerNode instance.
 
 AudioPlayerNode (const std::map< std::string, std::any > &config)
 Creates a AudioPlayerNode instance with parameters config.
 
SB_WASM ~AudioPlayerNode ()
 AudioPlayerNode destructor.
 
bool load (const std::string &path, Codec format)
 Loads an entire audio file from the given path to the memory. Stops playback.
 
bool load (const std::vector< uint8 > &inputData, Codec format)
 Loads encoded audio data. Stops playback.
 
SB_WASM bool load (AudioBuffer< float > &audioBuffer, bool copyData)
 Loads audio data from an AudioBuffer instance.
 
bool stream (const std::string &path, Codec format)
 Starts streaming an audio file from the given path. Stops playback.
 
void setSource (AudioPlayerSource &source)
 Sets the audio source to be played.
 
SB_WASM void play ()
 Starts the audio playback.
 
SB_WASM void pause ()
 Pauses the audio playback.
 
SB_WASM void stop ()
 Stops the audio playback.
 
SB_WASM bool isPlaying () const
 Indicates whether the system is currently playing.
 
SB_WASM bool isLoopingEnabled () const
 Indicates whether looping of the audio file is enabled.
 
SB_WASM uint getNumberOfChannels () const
 Gets the number of channels that the audio node will output. Default: 2 (stereo)
 
SB_WASM void setNumberOfChannels (const uint numberOfChannels)
 Sets the number of channels that the audio node will output.
 
SB_WASM uint getSourceSampleRate () const
 Gets the sample rate of the current audio source. SAMPLE_RATE_UNDEFINED is returned if there is none.
 
SB_WASM uint getSourceNumberOfChannels () const
 Gets the number of channels of the current audio source. NUM_CHANNELS_UNDEFINED is returned if there is none.
 
SB_WASM void setLoopingEnabled (bool loopingEnabled)
 Indicates whether looping of the audio file is enabled.
 
SB_WASM double getPosition () const
 Indicates the current position of the playback head.
 
SB_WASM double getDuration () const
 The duration of the currently playing media.
 
SB_WASM void setPosition (double position)
 Sets the playback head to the desired position.
 
double getStartPosition () const
 Indicates the current start position of the playback.
 
void setStartPosition (double startPosition)
 Sets the starting position of the playback. Only takes effect after audio is loaded.
 
double getEndPosition () const
 Indicates the current end position of the playback.
 
void setEndPosition (double endPosition)
 Sets the ending position of the playback. Only takes effect after audio is loaded.
 
std::string getAudioFilePath () const
 Gets the audio file path string parsed via constructor that takes parameter config.
 
bool setBusFormat (AudioBusFormat &busFormat) override
 
bool produce (AudioBus &bus) override
 
Result< std::any > callAction (const std::string &actionName, const std::map< std::string, std::any > &params) override
 

Detailed Description

AudioNode that plays the loaded audio file.

AudioPlayerNode class.

Member Function Documentation

◆ getAudioFilePath()

std::string switchboard::AudioPlayerNode::getAudioFilePath ( ) const

Gets the audio file path string parsed via constructor that takes parameter config.

Returns
The file path of the audio file.

◆ getDuration()

double switchboard::AudioPlayerNode::getDuration ( ) const

The duration of the currently playing media.

Returns
The duration of the media in seconds.

◆ getEndPosition()

double switchboard::AudioPlayerNode::getEndPosition ( ) const

Indicates the current end position of the playback.

Returns
Returns the current end position in seconds.

◆ getNumberOfChannels()

uint switchboard::AudioPlayerNode::getNumberOfChannels ( ) const

Gets the number of channels that the audio node will output. Default: 2 (stereo)

Returns
The output number of channels.

◆ getPosition()

double switchboard::AudioPlayerNode::getPosition ( ) const

Indicates the current position of the playback head.

Returns
Returns the elapsed time in seconds.

◆ getSourceNumberOfChannels()

uint switchboard::AudioPlayerNode::getSourceNumberOfChannels ( ) const

Gets the number of channels of the current audio source. NUM_CHANNELS_UNDEFINED is returned if there is none.

Returns
The current audio source's number of channels.

◆ getSourceSampleRate()

uint switchboard::AudioPlayerNode::getSourceSampleRate ( ) const

Gets the sample rate of the current audio source. SAMPLE_RATE_UNDEFINED is returned if there is none.

Returns
The current audio source's sample rate.

◆ getStartPosition()

double switchboard::AudioPlayerNode::getStartPosition ( ) const

Indicates the current start position of the playback.

Returns
Returns the current start position in seconds.

◆ isLoopingEnabled()

bool switchboard::AudioPlayerNode::isLoopingEnabled ( ) const

Indicates whether looping of the audio file is enabled.

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

◆ isPlaying()

bool switchboard::AudioPlayerNode::isPlaying ( ) const

Indicates whether the system is currently playing.

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

◆ load() [1/3]

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

Loads audio data 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 AudioPlayerNode instance.
Returns
True when loading the audio data was successful, false otherwise.

◆ load() [2/3]

bool switchboard::AudioPlayerNode::load ( const std::string & path,
Codec format )

Loads an entire audio file from the given path to the memory. Stops playback.

Parameters
pathThe path to the audio file to load.
formatThe audio recording format.
Returns
True when loading of the audio file was successful, false otherwise.

◆ load() [3/3]

bool switchboard::AudioPlayerNode::load ( const std::vector< uint8 > & inputData,
Codec format )

Loads encoded audio data. Stops playback.

Parameters
inputDataVector containing the encoded audio data.
formatThe audio encoding format.
Returns
True when loading the audio data was successful, false otherwise.

◆ setEndPosition()

void switchboard::AudioPlayerNode::setEndPosition ( double endPosition)

Sets the ending position of the playback. Only takes effect after audio is loaded.

Parameters
endPositionThe desired position in seconds.

◆ setLoopingEnabled()

void switchboard::AudioPlayerNode::setLoopingEnabled ( bool loopingEnabled)

Indicates whether looping of the audio file is enabled.

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

◆ setNumberOfChannels()

void switchboard::AudioPlayerNode::setNumberOfChannels ( const uint numberOfChannels)

Sets the number of channels that the audio node will output.

Parameters
numberOfChannelsThe new number of channels setting.

◆ setPosition()

void switchboard::AudioPlayerNode::setPosition ( double position)

Sets the playback head to the desired position.

Parameters
positionThe desired position in seconds.

◆ setSource()

void switchboard::AudioPlayerNode::setSource ( AudioPlayerSource & source)

Sets the audio source to be played.

Parameters
sourceThe audio source to be played.

◆ setStartPosition()

void switchboard::AudioPlayerNode::setStartPosition ( double startPosition)

Sets the starting position of the playback. Only takes effect after audio is loaded.

Parameters
startPositionThe desired position in seconds.

◆ stream()

bool switchboard::AudioPlayerNode::stream ( const std::string & path,
Codec format )

Starts streaming an audio file from the given path. Stops playback.

Using this method, instead of load, is more memory efficient as it does not load the entire audio file to memory. However, seeking the audio might take longer.

Parameters
pathThe path to the audio file to stream.
formatThe audio recording format.
Returns
True when streaming of the audio file could be started, false otherwise.