NAP
Public Types | Public Member Functions | Public Attributes | List of all members
NodeManager Class Referencefinal

#include <audio/core/audionodemanager.h>

Public Types

using OutputMapping = std::vector< std::vector< SampleBuffer * > >
 

Public Member Functions

 NodeManager (DeletionQueue &deletionQueue)
 
 ~NodeManager ()
 
void process (float **inputBuffer, float **outputBuffer, unsigned long framesPerBuffer)
 
void process (std::vector< SampleBuffer * > &inputBuffer, std::vector< SampleBuffer * > &outputBuffer, unsigned long framesPerBuffer)
 
void enqueueTask (nap::TaskQueue::Task task)
 
int getInputChannelCount () const
 
int getOutputChannelCount () const
 
float getSampleRate () const
 
float getSamplesPerMillisecond () const
 
int getInternalBufferSize () const
 
const DiscreteTimeValuegetSampleTime () const
 
void setInputChannelCount (int inputChannelCount)
 
void setOutputChannelCount (int outputChannelCount)
 
void setSampleRate (float sampleRate)
 
void setInternalBufferSize (int size)
 
void registerRootProcess (Process &rootProcess)
 
void unregisterRootProcess (Process &rootProcess)
 
template<typename T , typename... Args>
SafeOwner< T > makeSafe (Args &&... args)
 
template<typename T >
SafeOwner< T > makeSafe (T *ptr)
 
DeletionQueuegetDeletionQueue ()
 

Public Attributes

Signal< DiscreteTimeValuemUpdateSignal
 
Signal< NodeManager & > mChannelCountChangedSignal
 

Description

The audio node manager represents a node system for audio processing. The nodes in the system can have multiple inputs and outputs that can be connected between different nodes. A connection represents a mono audio signal. Does not own the nodes but maintains a list of existing nodes that is updated from the node's constructor end destructors.

Collaboration diagram for NodeManager:
[legend]

Member Typedef Documentation

◆ OutputMapping

using OutputMapping = std::vector<std::vector<SampleBuffer*> >

Constructor & Destructor Documentation

◆ NodeManager()

NodeManager ( DeletionQueue deletionQueue)

◆ ~NodeManager()

Member Function Documentation

◆ enqueueTask()

void enqueueTask ( nap::TaskQueue::Task  task)

Enqueue a lambda to be executed before the processing of the next internal buffer starts. This way modifications to the processing chain can be made in a threadsafe manner from outside of the audio thread, with a timing accuracy that corresponds to the internal buffer size.

Parameters
taskLamba without arguments that will be called on the next audio callback

◆ getDeletionQueue()

DeletionQueue& getDeletionQueue ( )

Returns the DeletionQueue that this node manager uses to construct and destruct nodes or other processes on the audio thread safely.

◆ getInputChannelCount()

int getInputChannelCount ( ) const
Returns
: the number of input channels that will be fed into the node system

◆ getInternalBufferSize()

int getInternalBufferSize ( ) const
Returns
the buffer size the node system is running on. Beware: this can be smaller than the buffersize the audio device is running on. The latter is specified by the framesPerBuffer parameter in the process() function. This number indicates the size of each buffer that the nodes' process() functions have to present.

◆ getOutputChannelCount()

int getOutputChannelCount ( ) const
Returns
: the number of output channels that will be processed by the node system

◆ getSampleRate()

float getSampleRate ( ) const
Returns
: the sample rate that the node system runs on

◆ getSamplesPerMillisecond()

float getSamplesPerMillisecond ( ) const
Returns
: the number of audio samples needed per millisecond (TimeValue unit)

◆ getSampleTime()

const DiscreteTimeValue& getSampleTime ( ) const
Returns
the absolute time in samples

◆ makeSafe() [1/2]

SafeOwner<T> makeSafe ( Args &&...  args)

Constructs an object managed by a SafeOwner that will dispose the object in the NodeManager's DeletionQueue when it is no longer used. This will make sure the object is always destructed by the audio thread, so after going out of scope it can be safely referred until the next audio callback cycle.

Template Parameters
TThe type of the object retained by the newly constructed SafeOwner.
Parameters
argsThe arguments passed to the constructor of the object that will be retained by the newly created SafeOwner
Returns
A SafeOwner retaining the new object.

◆ makeSafe() [2/2]

SafeOwner<T> makeSafe ( T *  ptr)

Make an object to be retained by a SafeOwner that will dispose the object in the NodeManager's DeletionQueue when it is no longer used. This will make sure the object is always destructed by the audio thread, so after going out of scope it can be safely referred until the next audio callback cycle.

Template Parameters
TThe type of the object to be retained by the newly constructed SafeOwner
Parameters
ptrPointer to the object to be retained
Returns
A SafeOwner retaining the passed object.

◆ process() [1/2]

void process ( float **  inputBuffer,
float **  outputBuffer,
unsigned long  framesPerBuffer 
)

This function is typically called by an audio callback to perform all the audio processing. It feeds the inputbuffer to the audio input nodes and polls the audio output nodes for output.

Parameters
inputBufferan array of float arrays, representing one sample buffer for every channel
outputBufferan array of float arrays, representing one sample buffer for every channel
framesPerBufferthe number of samples that has to be processed per channel

◆ process() [2/2]

void process ( std::vector< SampleBuffer * > &  inputBuffer,
std::vector< SampleBuffer * > &  outputBuffer,
unsigned long  framesPerBuffer 
)

This function is typically called by an audio callback to perform all the audio processing. It feeds the inputbuffer to the audio input nodes and polls the audio output nodes for output.

Parameters
inputBuffera vector of sample buffers, representing one sample buffer for every channel
outputBuffera vector of sample buffers, representing one sample buffer for every channel
framesPerBufferthe number of samples that has to be processed per channel

◆ registerRootProcess()

void registerRootProcess ( Process rootProcess)

Used by nodes to register themselves to be processed directly by the node manager

Parameters
rootProcessThe root process is a process or node that is executed on every audio callback without being connected to an input of another node. In most cases the root process is an OutputNode.

◆ setInputChannelCount()

void setInputChannelCount ( int  inputChannelCount)

Sets the number of input channels that will be fed into the node system

Parameters
inputChannelCountthe number of input channels

◆ setInternalBufferSize()

void setInternalBufferSize ( int  size)

Changes the internal buffer size that the node system uses. The internal buffer size determines the timing accuracy of state changes within the node system. The internal buffer size needs to fit a discrete amount of times into the audio callback's buffer size. Beware: this can be smaller than the buffersize the audio device is running on.

Parameters
sizethe new buffer size

◆ setOutputChannelCount()

void setOutputChannelCount ( int  outputChannelCount)

Sets the number of output channels that will be processed by the node system

Parameters
outputChannelCountthe number of output channels that the node system provides audio to

◆ setSampleRate()

void setSampleRate ( float  sampleRate)

Changes the sample rate the node system is running on. This method is normally called by the AudioService.

Parameters
sampleRatethe sample rate in Hz

◆ unregisterRootProcess()

void unregisterRootProcess ( Process rootProcess)

Used by nodes to unregister themselves to be processed directly by the node manager.

Parameters
rootProcessThe root process is a process or node that is executed on every audio callback without being connected to an input of another node. In most cases the root process is an OutputNode.

Member Data Documentation

◆ mChannelCountChangedSignal

Signal<NodeManager&> mChannelCountChangedSignal

Signal triggered whenever the input or output channel count of the node manager changes

◆ mUpdateSignal

Signal<DiscreteTimeValue> mUpdateSignal

This signal is emitted from the process() function after processing every internal buffer of audio.