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

Manages a graph of AudioNode instances. More...

#include <AudioGraph.hpp>

Inheritance diagram for switchboard::AudioGraph:

Public Member Functions

 SB_WASM_EXPORT (AudioGraph)
SB_WASM AudioGraph (uint maxNumberOfChannels=constants::STEREO, uint maxNumberOfFrames=constants::MAX_NUMBER_OF_FRAMES, uint sampleRate=constants::SAMPLE_RATE_UNDEFINED, uint bufferSize=512)
 Creates an AudioGraph.
 AudioGraph (const std::map< std::string, std::any > &config)
SB_WASM ~AudioGraph ()
 AudioGraph destructor.
SB_WASM const AudioGraphInputNodegetInputNode () const
 Returns the input node of the audio graph.
SB_WASM const AudioGraphOutputNodegetOutputNode () const
 Returns the output node of the audio graph.
SB_WASM Result< void > addNode (AudioNode &audioNode, bool moveOwnership=false)
 Adds a node to the audio graph.
SB_WASM Result< void > removeNode (AudioNode &audioNode)
 Removes a node from the audio graph.
const std::vector< AudioNode * > & getNodes () const
 Gets a list of all audio nodes in the audio graph.
AudioNode * getNodeByName (const std::string &name) const
 Finds an audio node by name.
SB_WASM AudioNode * getNodeByName (const char *name) const
 Finds an audio node by name.
Result< void > connect (const AudioNode &srcNode, std::optional< uint > srcBusIndexOptional, const AudioNode &dstNode, std::optional< uint > dstBusIndexOptional)
 Connects two audio nodes together.
SB_WASM bool connect (const AudioSourceNode &srcNode, const AudioProcessorNode &dstNode)
 Connects a source node to a processor node.
SB_WASM bool connect (const AudioSourceNode &srcNode, const AudioSinkNode &dstNode)
 Connects a source node to a sink node.
SB_WASM bool connect (const AudioProcessorNode &srcNode, const AudioProcessorNode &dstNode)
 Connects a processor node to another processor node.
SB_WASM bool connect (const AudioProcessorNode &srcNode, const AudioSinkNode &dstNode)
 Connects a processor node to a sink node.
Result< void > disconnect (const AudioNode &srcNode, uint srcBusIndex, const AudioNode &dstNode, uint dstBusIndex)
 Disconnects two audio nodes that are connected.
bool isInputNodeConnected ()
 Checks if the input node is connected to any other nodes.
bool isOutputNodeConnected ()
 Checks if the output node is connected to any other nodes.
void setProcessingConfig (uint sampleRate, uint bufferSize)
 Sets the internal processing configuration of the audio graph.
SB_WASM Result< void > start ()
 Starts the audio graph.
SB_WASM Result< void > stop ()
 Stops the audio graph.
SB_WASM bool isRunning ()
 Checks if the audio graph has been started.
SB_WASM bool process (AudioBusList &inAudioBuses, AudioBusList &outAudioBuses) NONBLOCKING
 The real-time audio process function of the audio graph.
SB_WASM bool processBuffer (AudioBuffer< float > *inAudioBuffer, AudioBuffer< float > *outAudioBuffer)
 The real-time audio process function of the audio graph that processes audio buffers.
Result< void > setValue (const std::string &key, const std::any &value) override
Result< std::any > getValue (const std::string &key) override
Result< std::any > callAction (const std::string &actionName, const std::map< std::string, std::any > &params) override

Public Attributes

uint maxNumberOfChannels
 Maximum number of channels that is supported by the audio graph.
uint maxNumberOfFrames
 Maximum number of frames that is supported by the audio graph.

Detailed Description

Manages a graph of AudioNode instances.

AudioGraph class.

This class can be used to easily put together complicated audio pipelines by adding and then connecting AudioNode instances together.

Constructor & Destructor Documentation

◆ AudioGraph()

switchboard::AudioGraph::AudioGraph ( uint maxNumberOfChannels = constants::STEREO,
uint maxNumberOfFrames = constants::MAX_NUMBER_OF_FRAMES,
uint sampleRate = constants::SAMPLE_RATE_UNDEFINED,
uint bufferSize = 512 )

Creates an AudioGraph.

Parameters
maxNumberOfChannelsMaximum number of channels that is supported by the audio graph.
maxNumberOfFramesMaximum number of frames that is supported by the audio graph.
sampleRateThe sample rate to run the graph with. (optional)
bufferSizeThe buffer size to use with the graph. (optional)

Member Function Documentation

◆ addNode()

Result< void > switchboard::AudioGraph::addNode ( AudioNode & audioNode,
bool moveOwnership = false )

Adds a node to the audio graph.

Parameters
audioNodeThe node to be added.
moveOwnershipIf set to true, the AudioGraph will destruct the audio node.
Returns
A result indicating success or failure of the addition.

◆ connect() [1/5]

Result< void > switchboard::AudioGraph::connect ( const AudioNode & srcNode,
std::optional< uint > srcBusIndexOptional,
const AudioNode & dstNode,
std::optional< uint > dstBusIndexOptional )

Connects two audio nodes together.

Parameters
srcNodeThe source node.
srcBusIndexOptionalThe optional source bus index. If not provided, the first bus will be used.
dstNodeThe destination node.
dstBusIndexOptionalThe optional destination bus index. If not provided, the first bus will be used.
Returns
A result indicating success or failure of the connection.

◆ connect() [2/5]

bool switchboard::AudioGraph::connect ( const AudioProcessorNode & srcNode,
const AudioProcessorNode & dstNode )

Connects a processor node to another processor node.

Parameters
srcNodeThe source processor node.
dstNodeThe destination processor node.
Returns
True if the nodes were successfully connected, false otherwise.

◆ connect() [3/5]

bool switchboard::AudioGraph::connect ( const AudioProcessorNode & srcNode,
const AudioSinkNode & dstNode )

Connects a processor node to a sink node.

Parameters
srcNodeThe processor node.
dstNodeThe sink node.
Returns
True if the nodes were successfully connected, false otherwise.

◆ connect() [4/5]

bool switchboard::AudioGraph::connect ( const AudioSourceNode & srcNode,
const AudioProcessorNode & dstNode )

Connects a source node to a processor node.

Parameters
srcNodeThe source node.
dstNodeThe processor node.
Returns
True if the nodes were successfully connected, false otherwise.

◆ connect() [5/5]

bool switchboard::AudioGraph::connect ( const AudioSourceNode & srcNode,
const AudioSinkNode & dstNode )

Connects a source node to a sink node.

Parameters
srcNodeThe source node.
dstNodeThe sink node.
Returns
True if the nodes were successfully connected, false otherwise.

◆ disconnect()

Result< void > switchboard::AudioGraph::disconnect ( const AudioNode & srcNode,
uint srcBusIndex,
const AudioNode & dstNode,
uint dstBusIndex )

Disconnects two audio nodes that are connected.

Parameters
srcNodeThe source node.
srcBusIndexThe source bus index.
dstNodeThe destination node.
dstBusIndexThe destination bus index.
Returns
A result indicating success or failure of the disconnection.

◆ getInputNode()

const AudioGraphInputNode & switchboard::AudioGraph::getInputNode ( ) const

Returns the input node of the audio graph.

Returns
The input node.

◆ getNodeByName() [1/2]

AudioNode * switchboard::AudioGraph::getNodeByName ( const char * name) const

Finds an audio node by name.

Parameters
nameThe name of the audio node.
Returns
The found audio node, or nullptr if the audio node could not be found.

◆ getNodeByName() [2/2]

AudioNode * switchboard::AudioGraph::getNodeByName ( const std::string & name) const

Finds an audio node by name.

Parameters
nameThe name of the audio node.
Returns
The found audio node, or nullptr if the audio node could not be found.

◆ getNodes()

const std::vector< AudioNode * > & switchboard::AudioGraph::getNodes ( ) const

Gets a list of all audio nodes in the audio graph.

Returns
A vector with all the audio nodes in the audio graph.

◆ getOutputNode()

const AudioGraphOutputNode & switchboard::AudioGraph::getOutputNode ( ) const

Returns the output node of the audio graph.

Returns
The output node.

◆ isInputNodeConnected()

bool switchboard::AudioGraph::isInputNodeConnected ( )

Checks if the input node is connected to any other nodes.

Returns
True if the input node is connected, false otherwise.

◆ isOutputNodeConnected()

bool switchboard::AudioGraph::isOutputNodeConnected ( )

Checks if the output node is connected to any other nodes.

Returns
True if the output node is connected, false otherwise.

◆ isRunning()

bool switchboard::AudioGraph::isRunning ( )

Checks if the audio graph has been started.

Returns
True if the audio graph was already started successfully, false otherwise.

◆ process()

bool switchboard::AudioGraph::process ( AudioBusList & inAudioBuses,
AudioBusList & outAudioBuses )

The real-time audio process function of the audio graph.

Processes the audio in the provided input audio buses and puts the output audio in the provided output audio buses.

Parameters
inAudioBusesThe input audio buses.
outAudioBusesThe output audio buses.
Returns
True if the process call was successful, false otherwise.

◆ processBuffer()

bool switchboard::AudioGraph::processBuffer ( AudioBuffer< float > * inAudioBuffer,
AudioBuffer< float > * outAudioBuffer )

The real-time audio process function of the audio graph that processes audio buffers.

Processes the audio in the provided input audio buffer and puts the output audio in the provided output audio buffer. This is a convenience method that can be used when the audio graph has no more than one input and output buses. To process multiple buses, use the process method.

Parameters
inAudioBufferThe input audio buffer, or null if there graph has no input.
outAudioBufferThe output audio buffer, or null if the graph has no output.
Returns
True if the process call was successful, false otherwise.

◆ removeNode()

Result< void > switchboard::AudioGraph::removeNode ( AudioNode & audioNode)

Removes a node from the audio graph.

Parameters
audioNodeThe node to be removed.
Returns
A result indicating success or failure of the removal.

◆ setProcessingConfig()

void switchboard::AudioGraph::setProcessingConfig ( uint sampleRate,
uint bufferSize )

Sets the internal processing configuration of the audio graph.

Parameters
sampleRateThe fixed processing sample rate.
bufferSizeThe fixed processing buffer size.

Call this method before starting the audio graph. To process the graph with dynamic sample rate and buffer size, set the sample rate value to SAMPLE_RATE_UNDEFINED.

◆ start()

SB_WASM Result< void > switchboard::AudioGraph::start ( )

Starts the audio graph.

Returns
A result indicating success or failure of the start operation.

◆ stop()

Result< void > switchboard::AudioGraph::stop ( )

Stops the audio graph.

Returns
A result indicating success or failure of the stop operation.