Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cinder::audio::FilePlayerNode Class Reference

File-based SamplePlayerNode, where samples are constantly streamed from file. Suitable for large audio files. More...

#include <SamplePlayerNode.h>

Inheritance diagram for cinder::audio::FilePlayerNode:
[legend]

Public Types

enum  ChannelMode { ChannelMode::SPECIFIED, ChannelMode::MATCHES_INPUT, ChannelMode::MATCHES_OUTPUT }
 

Public Member Functions

 FilePlayerNode (const Format &format=Format())
 Constructs a FilePlayerNode with optional format. More...
 
 FilePlayerNode (const SourceFileRef &sourceFile, bool isReadAsync=true, const Format &format=Node::Format())
 Constructs a FilePlayerNode that plays sourceFile and optionally specifying isReadAsync (default = true). Can also provide an optional format. More...
 
virtual ~FilePlayerNode ()
 
virtual void stop () override
 Stops playing the sample, returns the read position to the beginning and disables processing. More...
 
virtual void seek (size_t readPositionFrames) override
 Seek the read position to readPositionFrames. More...
 
bool isReadAsync () const
 Returns whether reading occurs asynchronously (default is false). If true, file reading is done from an internal thread, if false it is done directly on the audio thread. More...
 
void setSourceFile (const SourceFileRef &sourceFile)
 
const SourceFileRefgetSourceFile () const
 
uint64_t getLastUnderrun ()
 Returns the frame of the last buffer underrun or 0 if none since the last time this method was called. More...
 
uint64_t getLastOverrun ()
 Returns the frame of the last buffer overrun or 0 if none since the last time this method was called. More...
 
virtual void start ()
 Starts playing the sample from the beginning. More...
 
void seekToTime (double positionSeconds)
 Seek to read position readPositionSeconds,. More...
 
size_t getReadPosition () const
 Returns the current read position in frames. More...
 
double getReadPositionTime () const
 Returns the current read position in seconds. More...
 
double getNumSeconds () const
 Returns the total number of seconds this SamplePlayerNode will play from beginning to end. More...
 
size_t getNumFrames () const
 Returns the total number of frames this SamplePlayerNode will play from beginning to end. More...
 
bool isEof () const
 Returns whether the SamplePlayerNode has reached EOF (end of file). If true, isEnabled() will also return false. More...
 
void setLoopEnabled (bool b=true)
 Sets whether playing continues from beginning after the end is reached (default = false) More...
 
bool isLoopEnabled () const
 Gets whether playing continues from beginning after the end is reached (default = false) More...
 
void setLoopBegin (size_t positionFrames)
 Sets the begin loop marker in frames (default = 0, max = getNumFrames()). More...
 
void setLoopBeginTime (double positionSeconds)
 Sets the begin loop marker in seconds (default = 0, max = getNumSeconds()). More...
 
void setLoopEnd (size_t positionFrames)
 Sets the end loop marker in frames (default = getNumFrames(), max = getNumFrames()). More...
 
void setLoopEndTime (double positionSeconds)
 Sets the end loop marker in seconds (default = getNumSeconds(), max = getNumSeconds()). More...
 
size_t getLoopBegin () const
 Returns the begin loop marker in frames. More...
 
double getLoopBeginTime () const
 Returns the begin loop marker in seconds. More...
 
size_t getLoopEnd () const
 Returns the end loop marker in frames. More...
 
double getLoopEndTime () const
 Returns the end loop marker in seconds. More...
 
void enable ()
 Enables this Node for processing. Same as setEnabled( true ). More...
 
void disable ()
 Disables this Node for processing. Same as setEnabled( false ). More...
 
void setEnabled (bool b=true)
 Sets whether this Node is enabled for processing or not. More...
 
bool isEnabled () const
 Returns whether this Node is enabled for processing or not. More...
 
virtual void connect (const NodeRef &output)
 Connects this Node to output. More...
 
virtual void disconnect (const NodeRef &output)
 Disconnects this Node from output. More...
 
virtual void disconnectAll ()
 Disconnects this Node from all inputs and outputs. More...
 
virtual void disconnectAllOutputs ()
 Disconnects this Node from all outputs. More...
 
virtual void disconnectAllInputs ()
 Disconnects all of this Node's inputs. More...
 
size_t getNumConnectedInputs () const
 Returns the number of inputs connected to this Node. More...
 
size_t getNumConnectedOutputs () const
 Returns the number of outputs this Node is connected to. More...
 
bool isConnectedToInput (const NodeRef &input) const
 Returns true if input is connected to this Node as an input, false otherwise. More...
 
bool isConnectedToOutput (const NodeRef &output) const
 Returns true if output is connected to this Node as an output, false otherwise. More...
 
ContextRef getContext () const
 Returns the Context associated with this Node. More...
 
size_t getNumChannels () const
 Returns the number of channels this Node will process. More...
 
ChannelMode getChannelMode () const
 Returns the channel mode. More...
 
size_t getMaxNumInputChannels () const
 Returns the maximum number of channels any input has. More...
 
size_t getSampleRate () const
 Returns the samplerate of this Node, which is governed by the Context's OutputNode. More...
 
size_t getFramesPerBlock () const
 Returns the number of frames processed in one block by this Node, which is governed by the Context's OutputNode. More...
 
bool isAutoEnabled () const
 Returns whether this Node is automatically enabled / disabled when connected. More...
 
void setAutoEnabled (bool b=true)
 Sets whether this Node is automatically enabled / disabled when connected. More...
 
bool isInitialized () const
 Returns whether this Node is in an initialized state and is capable of processing audio. More...
 
bool getProcessesInPlace () const
 Returns whether this Node will process audio with an in-place Buffer. More...
 
bool canConnectToInput (const NodeRef &input)
 Returns whether it is possible to connect to input, example reasons of failure would be this == Node, or Node is already an input. More...
 
bool checkCycle (const NodeRef &sourceNode, const NodeRef &destNode) const
 Returns true if there is an unmanageable cycle betweeen sourceNode and destNode. If any Node's in the traversal returns true for supportsCycles(), this method will return false. More...
 
const std::set< NodeRef > & getInputs () const
 Returns an immutable reference to the inputs container. More...
 
std::vector< NodeRefgetOutputs () const
 Returns a copy of the NodeRef's referenced by the this Node as outputs. The copy is necessary because outputs are stored internally with weak_ptr's. More...
 
virtual std::string getName ()
 Returns a string representing the name of this Node type. Default returns a demangled, compiler-specific class name. More...
 
void setName (const std::string &name)
 Sets this Node's name to a user-specified string. More...
 
BuffergetInternalBuffer ()
 Usually used internally by a Node subclass, returns a pointer to the internal buffer storage. More...
 
const BuffergetInternalBuffer () const
 Usually used internally by a Node subclass, returns a pointer to the internal buffer storage. More...
 
void pullInputs (Buffer *inPlaceBuffer)
 Usually called internally by the Node, in special cases sub-classes may need to call this on other Node's. More...
 

Protected Member Functions

void initialize () override
 Called before audio buffers need to be used. There is always a valid Context at this point. More...
 
void uninitialize () override
 Called once the contents of initialize are no longer relevant, i.e. connections have changed. More...
 
void enableProcessing () override
 Callled when this Node should enable processing. Initiated from Node::enable(). More...
 
void disableProcessing () override
 Callled when this Node should disable processing. Initiated from Node::disable(). More...
 
void process (Buffer *buffer) override
 Override to perform audio processing on buffer. More...
 
void readAsyncImpl ()
 
void readImpl ()
 
void seekImpl (size_t readPos)
 
void destroyReadThreadImpl ()
 
virtual void sumInputs ()
 
virtual bool supportsInputNumChannels (size_t numChannels) const
 Default implementation returns true if numChannels matches our format. More...
 
virtual bool supportsCycles () const
 Default implementation returns false, return true if it makes sense for the Node to be processed in a cycle (eg. Delay). More...
 
virtual bool supportsProcessInPlace () const
 Default implementation returns true, subclasses should return false if they must process out-of-place (summing). More...
 
virtual void disconnectInput (const NodeRef &input)
 
virtual void disconnectOutput (const NodeRef &output)
 
virtual void configureConnections ()
 
void setupProcessWithSumming ()
 
void notifyConnectionsDidChange ()
 
bool inputChannelsAreUnequal () const
 
void setNumChannels (size_t numChannels)
 Only Node subclasses can specify num channels directly - users specify via Format at construction time. More...
 
void setChannelMode (ChannelMode mode)
 Only Node subclasses can specify channel mode directly - users specify via Format at construction time. More...
 
void initializeImpl ()
 
void uninitializeImpl ()
 
BufferDynamicgetSummingBuffer ()
 
const BufferDynamicgetSummingBuffer () const
 

Protected Attributes

std::vector< dsp::RingBuffermRingBuffers
 
BufferDynamic mIoBuffer
 
SourceFileRef mSourceFile
 
size_t mBufferFramesThreshold
 
size_t mRingBufferPaddingFactor
 
std::atomic< uint64_t > mLastUnderrun
 
std::atomic< uint64_t > mLastOverrun
 
std::unique_ptr< std::thread > mReadThread
 
std::mutex mAsyncReadMutex
 
std::condition_variable mIssueAsyncReadCond
 
bool mIsReadAsync
 
bool mAsyncReadShouldQuit
 
size_t mNumFrames
 
std::atomic< size_t > mReadPos
 
std::atomic< size_t > mLoopBegin
 
std::atomic< size_t > mLoopEnd
 
std::atomic< bool > mLoop
 
std::atomic< bool > mIsEof
 

Detailed Description

File-based SamplePlayerNode, where samples are constantly streamed from file. Suitable for large audio files.

Member Enumeration Documentation

enum cinder::audio::Node::ChannelMode
stronginherited

Used to specifiy how the corresponding channels are to be resolved between two connected Node's, based on either a Node's input (the default), it's output, or specified by user.

Enumerator
SPECIFIED 

Number of channels has been specified by user or is non-settable.

MATCHES_INPUT 

This Node matches it's channels with it's input.

MATCHES_OUTPUT 

This Node matches it's channels with it's output.

Constructor & Destructor Documentation

cinder::audio::FilePlayerNode::FilePlayerNode ( const Format format = Format())

Constructs a FilePlayerNode with optional format.

cinder::audio::FilePlayerNode::FilePlayerNode ( const SourceFileRef sourceFile,
bool  isReadAsync = true,
const Format format = Node::Format() 
)

Constructs a FilePlayerNode that plays sourceFile and optionally specifying isReadAsync (default = true). Can also provide an optional format.

Note
sourceFile's samplerate is forced to match this Node's Context.
cinder::audio::FilePlayerNode::~FilePlayerNode ( )
virtual

Member Function Documentation

void cinder::audio::FilePlayerNode::stop ( )
overridevirtual

Stops playing the sample, returns the read position to the beginning and disables processing.

Reimplemented from cinder::audio::SamplePlayerNode.

void cinder::audio::FilePlayerNode::seek ( size_t  positionFrames)
overridevirtual

Seek the read position to readPositionFrames.

Implements cinder::audio::SamplePlayerNode.

bool cinder::audio::FilePlayerNode::isReadAsync ( ) const

Returns whether reading occurs asynchronously (default is false). If true, file reading is done from an internal thread, if false it is done directly on the audio thread.

void cinder::audio::FilePlayerNode::setSourceFile ( const SourceFileRef sourceFile)
Note
sourceFile's samplerate is forced to match this Node's Context.
const SourceFileRef& cinder::audio::FilePlayerNode::getSourceFile ( ) const
uint64_t cinder::audio::FilePlayerNode::getLastUnderrun ( )

Returns the frame of the last buffer underrun or 0 if none since the last time this method was called.

uint64_t cinder::audio::FilePlayerNode::getLastOverrun ( )

Returns the frame of the last buffer overrun or 0 if none since the last time this method was called.

void cinder::audio::FilePlayerNode::initialize ( )
overrideprotectedvirtual

Called before audio buffers need to be used. There is always a valid Context at this point.

Reimplemented from cinder::audio::Node.

void cinder::audio::FilePlayerNode::uninitialize ( )
overrideprotectedvirtual

Called once the contents of initialize are no longer relevant, i.e. connections have changed.

Note
Not guaranteed to be called at Node destruction.

Reimplemented from cinder::audio::Node.

void cinder::audio::FilePlayerNode::enableProcessing ( )
overrideprotectedvirtual

Callled when this Node should enable processing. Initiated from Node::enable().

Reimplemented from cinder::audio::Node.

void cinder::audio::FilePlayerNode::disableProcessing ( )
overrideprotectedvirtual

Callled when this Node should disable processing. Initiated from Node::disable().

Reimplemented from cinder::audio::Node.

void cinder::audio::FilePlayerNode::process ( Buffer buffer)
overrideprotectedvirtual

Override to perform audio processing on buffer.

Reimplemented from cinder::audio::Node.

void cinder::audio::FilePlayerNode::readAsyncImpl ( )
protected
void cinder::audio::FilePlayerNode::readImpl ( )
protected
void cinder::audio::FilePlayerNode::seekImpl ( size_t  readPos)
protected
void cinder::audio::FilePlayerNode::destroyReadThreadImpl ( )
protected
void cinder::audio::SamplePlayerNode::start ( )
virtualinherited

Starts playing the sample from the beginning.

void cinder::audio::SamplePlayerNode::seekToTime ( double  positionSeconds)
inherited

Seek to read position readPositionSeconds,.

size_t cinder::audio::SamplePlayerNode::getReadPosition ( ) const
inherited

Returns the current read position in frames.

double cinder::audio::SamplePlayerNode::getReadPositionTime ( ) const
inherited

Returns the current read position in seconds.

double cinder::audio::SamplePlayerNode::getNumSeconds ( ) const
inherited

Returns the total number of seconds this SamplePlayerNode will play from beginning to end.

size_t cinder::audio::SamplePlayerNode::getNumFrames ( ) const
inherited

Returns the total number of frames this SamplePlayerNode will play from beginning to end.

bool cinder::audio::SamplePlayerNode::isEof ( ) const
inherited

Returns whether the SamplePlayerNode has reached EOF (end of file). If true, isEnabled() will also return false.

void cinder::audio::SamplePlayerNode::setLoopEnabled ( bool  b = true)
inherited

Sets whether playing continues from beginning after the end is reached (default = false)

bool cinder::audio::SamplePlayerNode::isLoopEnabled ( ) const
inherited

Gets whether playing continues from beginning after the end is reached (default = false)

void cinder::audio::SamplePlayerNode::setLoopBegin ( size_t  positionFrames)
inherited

Sets the begin loop marker in frames (default = 0, max = getNumFrames()).

void cinder::audio::SamplePlayerNode::setLoopBeginTime ( double  positionSeconds)
inherited

Sets the begin loop marker in seconds (default = 0, max = getNumSeconds()).

void cinder::audio::SamplePlayerNode::setLoopEnd ( size_t  positionFrames)
inherited

Sets the end loop marker in frames (default = getNumFrames(), max = getNumFrames()).

void cinder::audio::SamplePlayerNode::setLoopEndTime ( double  positionSeconds)
inherited

Sets the end loop marker in seconds (default = getNumSeconds(), max = getNumSeconds()).

size_t cinder::audio::SamplePlayerNode::getLoopBegin ( ) const
inherited

Returns the begin loop marker in frames.

double cinder::audio::SamplePlayerNode::getLoopBeginTime ( ) const
inherited

Returns the begin loop marker in seconds.

size_t cinder::audio::SamplePlayerNode::getLoopEnd ( ) const
inherited

Returns the end loop marker in frames.

double cinder::audio::SamplePlayerNode::getLoopEndTime ( ) const
inherited

Returns the end loop marker in seconds.

void cinder::audio::Node::enable ( )
inherited

Enables this Node for processing. Same as setEnabled( true ).

void cinder::audio::Node::disable ( )
inherited

Disables this Node for processing. Same as setEnabled( false ).

void cinder::audio::Node::setEnabled ( bool  b = true)
inherited

Sets whether this Node is enabled for processing or not.

bool cinder::audio::Node::isEnabled ( ) const
inherited

Returns whether this Node is enabled for processing or not.

void cinder::audio::Node::connect ( const NodeRef output)
virtualinherited

Connects this Node to output.

Reimplemented in cinder::audio::NodeAutoPullable.

void cinder::audio::Node::disconnect ( const NodeRef output)
virtualinherited

Disconnects this Node from output.

void cinder::audio::Node::disconnectAll ( )
virtualinherited

Disconnects this Node from all inputs and outputs.

void cinder::audio::Node::disconnectAllOutputs ( )
virtualinherited

Disconnects this Node from all outputs.

Reimplemented in cinder::audio::NodeAutoPullable.

void cinder::audio::Node::disconnectAllInputs ( )
virtualinherited

Disconnects all of this Node's inputs.

Reimplemented in cinder::audio::ChannelRouterNode.

size_t cinder::audio::Node::getNumConnectedInputs ( ) const
inherited

Returns the number of inputs connected to this Node.

size_t cinder::audio::Node::getNumConnectedOutputs ( ) const
inherited

Returns the number of outputs this Node is connected to.

bool cinder::audio::Node::isConnectedToInput ( const NodeRef input) const
inherited

Returns true if input is connected to this Node as an input, false otherwise.

bool cinder::audio::Node::isConnectedToOutput ( const NodeRef output) const
inherited

Returns true if output is connected to this Node as an output, false otherwise.

ContextRef cinder::audio::Node::getContext ( ) const
inherited

Returns the Context associated with this Node.

Note
Cannot be called from within a Node's constructor. Use initialize instead.
size_t cinder::audio::Node::getNumChannels ( ) const
inherited

Returns the number of channels this Node will process.

ChannelMode cinder::audio::Node::getChannelMode ( ) const
inherited

Returns the channel mode.

See also
ChannelMode.
size_t cinder::audio::Node::getMaxNumInputChannels ( ) const
inherited

Returns the maximum number of channels any input has.

size_t cinder::audio::Node::getSampleRate ( ) const
inherited

Returns the samplerate of this Node, which is governed by the Context's OutputNode.

size_t cinder::audio::Node::getFramesPerBlock ( ) const
inherited

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

bool cinder::audio::Node::isAutoEnabled ( ) const
inherited

Returns whether this Node is automatically enabled / disabled when connected.

void cinder::audio::Node::setAutoEnabled ( bool  b = true)
inherited

Sets whether this Node is automatically enabled / disabled when connected.

bool cinder::audio::Node::isInitialized ( ) const
inherited

Returns whether this Node is in an initialized state and is capable of processing audio.

bool cinder::audio::Node::getProcessesInPlace ( ) const
inherited

Returns whether this Node will process audio with an in-place Buffer.

bool cinder::audio::Node::canConnectToInput ( const NodeRef input)
inherited

Returns whether it is possible to connect to input, example reasons of failure would be this == Node, or Node is already an input.

bool cinder::audio::Node::checkCycle ( const NodeRef sourceNode,
const NodeRef destNode 
) const
inherited

Returns true if there is an unmanageable cycle betweeen sourceNode and destNode. If any Node's in the traversal returns true for supportsCycles(), this method will return false.

const std::set<NodeRef>& cinder::audio::Node::getInputs ( ) const
inherited

Returns an immutable reference to the inputs container.

vector< NodeRef > cinder::audio::Node::getOutputs ( ) const
inherited

Returns a copy of the NodeRef's referenced by the this Node as outputs. The copy is necessary because outputs are stored internally with weak_ptr's.

std::string cinder::audio::Node::getName ( )
virtualinherited

Returns a string representing the name of this Node type. Default returns a demangled, compiler-specific class name.

void cinder::audio::Node::setName ( const std::string name)
inherited

Sets this Node's name to a user-specified string.

Buffer* cinder::audio::Node::getInternalBuffer ( )
inherited

Usually used internally by a Node subclass, returns a pointer to the internal buffer storage.

const Buffer* cinder::audio::Node::getInternalBuffer ( ) const
inherited

Usually used internally by a Node subclass, returns a pointer to the internal buffer storage.

void cinder::audio::Node::pullInputs ( Buffer inPlaceBuffer)
inherited

Usually called internally by the Node, in special cases sub-classes may need to call this on other Node's.

void cinder::audio::Node::sumInputs ( )
protectedvirtualinherited
virtual bool cinder::audio::Node::supportsInputNumChannels ( size_t  numChannels) const
protectedvirtualinherited

Default implementation returns true if numChannels matches our format.

Reimplemented in cinder::audio::ChannelRouterNode.

virtual bool cinder::audio::Node::supportsCycles ( ) const
protectedvirtualinherited

Default implementation returns false, return true if it makes sense for the Node to be processed in a cycle (eg. Delay).

Reimplemented in cinder::audio::DelayNode.

virtual bool cinder::audio::Node::supportsProcessInPlace ( ) const
protectedvirtualinherited

Default implementation returns true, subclasses should return false if they must process out-of-place (summing).

Reimplemented in cinder::audio::ChannelRouterNode, and cinder::audio::cocoa::OutputDeviceNodeAudioUnit.

void cinder::audio::Node::disconnectInput ( const NodeRef input)
protectedvirtualinherited
void cinder::audio::Node::disconnectOutput ( const NodeRef output)
protectedvirtualinherited
void cinder::audio::Node::configureConnections ( )
protectedvirtualinherited
void cinder::audio::Node::setupProcessWithSumming ( )
protectedinherited
void cinder::audio::Node::notifyConnectionsDidChange ( )
protectedinherited
bool cinder::audio::Node::inputChannelsAreUnequal ( ) const
protectedinherited
void cinder::audio::Node::setNumChannels ( size_t  numChannels)
protectedinherited

Only Node subclasses can specify num channels directly - users specify via Format at construction time.

void cinder::audio::Node::setChannelMode ( ChannelMode  mode)
protectedinherited

Only Node subclasses can specify channel mode directly - users specify via Format at construction time.

void cinder::audio::Node::initializeImpl ( )
protectedinherited
void cinder::audio::Node::uninitializeImpl ( )
protectedinherited
BufferDynamic* cinder::audio::Node::getSummingBuffer ( )
protectedinherited
const BufferDynamic* cinder::audio::Node::getSummingBuffer ( ) const
protectedinherited

Member Data Documentation

std::vector<dsp::RingBuffer> cinder::audio::FilePlayerNode::mRingBuffers
protected
BufferDynamic cinder::audio::FilePlayerNode::mIoBuffer
protected
SourceFileRef cinder::audio::FilePlayerNode::mSourceFile
protected
size_t cinder::audio::FilePlayerNode::mBufferFramesThreshold
protected
size_t cinder::audio::FilePlayerNode::mRingBufferPaddingFactor
protected
std::atomic<uint64_t> cinder::audio::FilePlayerNode::mLastUnderrun
protected
std::atomic<uint64_t> cinder::audio::FilePlayerNode::mLastOverrun
protected
std::unique_ptr<std::thread> cinder::audio::FilePlayerNode::mReadThread
protected
std::mutex cinder::audio::FilePlayerNode::mAsyncReadMutex
protected
std::condition_variable cinder::audio::FilePlayerNode::mIssueAsyncReadCond
protected
bool cinder::audio::FilePlayerNode::mIsReadAsync
protected
bool cinder::audio::FilePlayerNode::mAsyncReadShouldQuit
protected
size_t cinder::audio::SamplePlayerNode::mNumFrames
protectedinherited
std::atomic<size_t> cinder::audio::SamplePlayerNode::mReadPos
protectedinherited
std::atomic<size_t> cinder::audio::SamplePlayerNode::mLoopBegin
protectedinherited
std::atomic<size_t> cinder::audio::SamplePlayerNode::mLoopEnd
protectedinherited
std::atomic<bool> cinder::audio::SamplePlayerNode::mLoop
protectedinherited
std::atomic<bool> cinder::audio::SamplePlayerNode::mIsEof
protectedinherited

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