Cinder  0.9.1
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
cinder::audio::Context Class Referenceabstract

#include <Context.h>

Inherits enable_shared_from_this< Context >.

Inherited by cinder::audio::cocoa::ContextAudioUnit.

Public Member Functions

virtual ~Context ()
 
virtual OutputDeviceNodeRef createOutputDeviceNode (const DeviceRef &device=Device::getDefaultOutput(), const Node::Format &format=Node::Format())=0
 
virtual InputDeviceNodeRef createInputDeviceNode (const DeviceRef &device=Device::getDefaultInput(), const Node::Format &format=Node::Format())=0
 
template<typename NodeT >
std::shared_ptr< NodeT > makeNode (NodeT *node)
 
template<typename NodeT , typename... Args>
std::shared_ptr< NodeT > makeNode (Args &&...args)
 
virtual void setOutput (const OutputNodeRef &output)
 
virtual const OutputNodeRefgetOutput ()
 
virtual void enable ()
 
virtual void disable ()
 
void setEnabled (bool enable)
 
bool isEnabled () const
 
virtual void connectionsDidChange (const NodeRef &node)
 
size_t getSampleRate ()
 
size_t getFramesPerBlock ()
 
uint64_t getNumProcessedFrames () const
 
double getNumProcessedSeconds ()
 
void initializeNode (const NodeRef &node)
 
void uninitializeNode (const NodeRef &node)
 
void initializeAllNodes ()
 
void uninitializeAllNodes ()
 
virtual void disconnectAllNodes ()
 
void addAutoPulledNode (const NodeRef &node)
 
void removeAutoPulledNode (const NodeRef &node)
 
void schedule (double when, const NodeRef &node, bool enable, const std::function< void()> &func)
 
std::mutex & getMutex () const
 
bool isAudioThread () const
 
void preProcess ()
 
void postProcess ()
 
std::string printGraphToString ()
 

Static Public Member Functions

static Contextmaster ()
 
static DeviceManagerdeviceManager ()
 
static void setMaster (Context *masterContext, DeviceManager *deviceManager)
 

Protected Member Functions

 Context ()
 

Detailed Description

Manages the creation, connections, and lifecycle of audio::Node's.

The Context class manages platform specific audio processing and thread synchronization between the 'audio' (real-time) and 'user' (typically UI/main, but not limited to) threads. There is one 'master', which is the only hardware-facing Context.

All Node's are created using the Context, which is necessary for thread synchronization.

Constructor & Destructor Documentation

cinder::audio::Context::~Context ( )
virtual
cinder::audio::Context::Context ( )
protected

Member Function Documentation

Context * cinder::audio::Context::master ( )
static

Returns the master Context that manages hardware I/O and real-time processing, which is platform specific. If none is available, returns null.

DeviceManager * cinder::audio::Context::deviceManager ( )
static

Returns the platform-specific DeviceManager singleton instance, which is platform specific. If none is available, returns null.

void cinder::audio::Context::setMaster ( Context masterContext,
DeviceManager deviceManager 
)
static

Allows the user to set the master Context and DeviceManager, overriding the defaults.

virtual OutputDeviceNodeRef cinder::audio::Context::createOutputDeviceNode ( const DeviceRef device = Device::getDefaultOutput(),
const Node::Format format = Node::Format() 
)
pure virtual

Creates and returns a platform-specific OutputDeviceNode, which delivers audio to the hardware output device specified by device.

Implemented in cinder::audio::cocoa::ContextAudioUnit.

virtual InputDeviceNodeRef cinder::audio::Context::createInputDeviceNode ( const DeviceRef device = Device::getDefaultInput(),
const Node::Format format = Node::Format() 
)
pure virtual

Creates and returns a platform-specific InputDeviceNode, which captures audio from the hardware input device specified by device.

Implemented in cinder::audio::cocoa::ContextAudioUnit.

template<typename NodeT >
std::shared_ptr< NodeT > cinder::audio::Context::makeNode ( NodeT *  node)

Interface for creating new Node's of type NodeT, which is owned by this Context. All Node's must be created using the Context.

template<typename NodeT , typename... Args>
std::shared_ptr< NodeT > cinder::audio::Context::makeNode ( Args &&...  args)

Interface for creating a new Node of type NodeT, which is owned by this Context. All Node's must be created using the Context.

void cinder::audio::Context::setOutput ( const OutputNodeRef output)
virtual

Sets the new output of this Context to output. You should do this before making any connections because when Node's are initialized they use the format of the OutputNode to configure their buffers.

const OutputNodeRef & cinder::audio::Context::getOutput ( )
virtual

Returns the OutputNode for the Context (currently always an OutputDeviceNode that sends audio to your speakers). This can be thought of as the 'heartbeat', it is the one who initiates the pulling and processing of all other Node's in the audio graph. note If the output has not already been set, it is the default OutputDeviceNode.

void cinder::audio::Context::enable ( )
virtual

Enables audio processing. Effectively the same as calling getOutput()->enable()

void cinder::audio::Context::disable ( )
virtual

Enables audio processing. Effectively the same as calling getOutput()->disable()

void cinder::audio::Context::setEnabled ( bool  enable)

start / stop audio processing via boolean

bool cinder::audio::Context::isEnabled ( ) const

Returns whether or not this Context is current enabled and processing audio.

virtual void cinder::audio::Context::connectionsDidChange ( const NodeRef node)
virtual

Called by node when it's connections have changed, default implementation is empty.

size_t cinder::audio::Context::getSampleRate ( )

Returns the samplerate of this Context, which is governed by the current OutputNode.

size_t cinder::audio::Context::getFramesPerBlock ( )

Returns the number of frames processed in one block by this Node, which is governed by the current OutputNode.

uint64_t cinder::audio::Context::getNumProcessedFrames ( ) const

Returns the total number of frames that have been processed in the dsp loop.

double cinder::audio::Context::getNumProcessedSeconds ( )

Returns the total number of seconds that have been processed in the dsp loop.

void cinder::audio::Context::initializeNode ( const NodeRef node)

Initializes node, ensuring that Node::initialze() gets called and that its internal buffers are ready for processing. Useful for initializing a heavy Node at an opportune time so as to not cause audio drop-outs or UI snags.

void cinder::audio::Context::uninitializeNode ( const NodeRef node)

Un-initializes node, ensuring that Node::uninitialze() gets called.

void cinder::audio::Context::initializeAllNodes ( )

Initialize all Node's related by this Context.

void cinder::audio::Context::uninitializeAllNodes ( )

Uninitialize all Node's related by this Context.

void cinder::audio::Context::disconnectAllNodes ( )
virtual

Disconnect all Node's related by this Context.

void cinder::audio::Context::addAutoPulledNode ( const NodeRef node)

Add node to the list of auto-pulled nodes, who will have their Node::pullInputs() method called after a OutputDeviceNode implementation finishes pulling its inputs.

Note
Callers on the non-audio thread must synchronize with getMutex().
void cinder::audio::Context::removeAutoPulledNode ( const NodeRef node)

Remove node from the list of auto-pulled nodes.

Note
Callers on the non-audio thread must synchronize with getMutex().
void cinder::audio::Context::schedule ( double  when,
const NodeRef node,
bool  enable,
const std::function< void()> &  func 
)

Schedule node to be enabled or disabled with with func on the audio thread, to be called at when seconds measured against getNumProcessedSeconds(). node is owned until the scheduled event completes.

std::mutex& cinder::audio::Context::getMutex ( ) const

Returns the mutex used to synchronize the audio thread. This is also used internally by the Node class when making connections.

bool cinder::audio::Context::isAudioThread ( ) const

Returns true if the current thread is the thread used for audio processing, false otherwise.

void cinder::audio::Context::preProcess ( )

OutputNode implementations should call this before each rendering block.

void cinder::audio::Context::postProcess ( )

OutputNode implementations should call this after each rendering block.

string cinder::audio::Context::printGraphToString ( )

Returns a string representation of the Node graph for debugging purposes.


The documentation for this class was generated from the following files: