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:
switchboard::SingleBusAudioSourceNode switchboard::AudioSourceNode switchboard::AudioNode

Public Member Functions

WASM AudioPlayerNode ()
 Creates a AudioPlayerNode instance.
 
 AudioPlayerNode (std::map< std::string, std::any > config)
 Creates a AudioPlayerNode instance with parameters config.
 
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.
 
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.
 
WASM void play ()
 Starts the audio playback.
 
WASM void pause ()
 Pauses the audio playback.
 
WASM void stop ()
 Stops the audio playback.
 
WASM bool isPlaying () const
 Indicates whether the system is currently playing.
 
WASM bool isLoopingEnabled () const
 Indicates whether looping of the audio file is enabled.
 
WASM uint getNumberOfChannels () const
 Gets the number of channels that the audio node will output. Default: 2 (stereo)
 
WASM void setNumberOfChannels (const uint numberOfChannels)
 Sets the number of channels that the audio node will output.
 
WASM uint getSourceSampleRate () const
 Gets the sample rate of the current audio source. SAMPLE_RATE_UNDEFINED is returned if there is none.
 
WASM uint getSourceNumberOfChannels () const
 Gets the number of channels of the current audio source. NUM_CHANNELS_UNDEFINED is returned if there is none.
 
WASM void setLoopingEnabled (bool loopingEnabled)
 Indicates whether looping of the audio file is enabled.
 
WASM double getPosition () const
 Indicates the current position of the playback head.
 
WASM double getDuration () const
 The duration of the currently playing media.
 
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
 Sets bus format.
 
bool produce (AudioBus &bus) override
 Produces audio data in the given bus.
 
- Public Member Functions inherited from switchboard::SingleBusAudioSourceNode
bool setNumberOfBuses (const uint numberOfBuses) override
 Sets number of buses.
 
bool setBusFormats (AudioBusFormatList &busFormats) override
 Sets bus formats.
 
bool produce (AudioBusList &buses) override
 Produces audio data in the given buses.
 
- Public Member Functions inherited from switchboard::AudioSourceNode
- Public Member Functions inherited from switchboard::AudioNode
 AudioNode ()
 AudioNode constructor.
 
virtual ~AudioNode ()=default
 AudioNode virtual destructor.
 
const std::string & getType () const
 Gets the type of the audio node.
 
virtual const std::string getDisplayName () const
 Gets the display name of the audio node.
 
virtual std::vector< std::unique_ptr< Parameter > > & getParameters ()
 Gets the parameters of the audio node.
 
virtual ParametergetParameter (const std::string &id)
 Gets the parameter with the given name.
 

Additional Inherited Members

- Public Attributes inherited from switchboard::AudioNode
std::string name
 The name of the audio node.
 
- Protected Member Functions inherited from switchboard::AudioNode
void initParameters (std::map< std::string, std::any > config)
 Initializes the node parameters from the given configuration values.
 
- Protected Attributes inherited from switchboard::AudioNode
std::string type
 
std::vector< std::unique_ptr< Parameter > > parameters
 

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.

◆ produce()

bool switchboard::AudioPlayerNode::produce ( AudioBus & bus)
overridevirtual

Produces audio data in the given bus.

Should be overridden by subclasses.

Parameters
busThe bus that should be filled with audio data.
Returns
True if audio was produced successfully, false otherwise.

Implements switchboard::SingleBusAudioSourceNode.

◆ setBusFormat()

bool switchboard::AudioPlayerNode::setBusFormat ( AudioBusFormat & busFormat)
overridevirtual

Sets bus format.

Should be overridden by subclasses.

Parameters
busFormatThe bus format to set.
Returns
True if the bus format was set successfully, false otherwise.

Implements switchboard::SingleBusAudioSourceNode.

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