Essentia  2.1-beta6-dev
Algorithm Class Referenceabstract

#include <streamingalgorithm.h>

Inheritance diagram for Algorithm:
Configurable AccumulatorAlgorithm AlgorithmComposite Copy< TokenType > DevNull< TokenType > DiskWriter< T > FileOutput< TokenType, StorageType > PoolStorageBase RingBufferInput RingBufferOutput RingBufferVectorOutput StreamingAlgorithmWrapper VectorInput< TokenType, acquireSize > VectorOutput< TokenType, StorageType >

Public Types

typedef OrderedMap< SinkBaseInputMap
 
typedef OrderedMap< SourceBaseOutputMap
 

Public Member Functions

 Algorithm ()
 
virtual ~Algorithm ()
 
SinkBaseinput (const std::string &name)
 
SourceBaseoutput (const std::string &name)
 
SinkBaseinput (int idx)
 
SourceBaseoutput (int idx)
 
const InputMapinputs () const
 
const OutputMapoutputs () const
 
std::vector< std::string > inputNames () const
 
std::vector< std::string > outputNames () const
 
virtual void shouldStop (bool stop)
 
virtual bool shouldStop () const
 
void disconnectAll ()
 
AlgorithmStatus acquireData ()
 
void releaseData ()
 
virtual AlgorithmStatus process ()=0
 
virtual void reset ()
 
- Public Member Functions inherited from Configurable
virtual ~Configurable ()
 
const std::string & name () const
 
void setName (const std::string &name)
 
virtual void declareParameters ()=0
 
virtual void setParameters (const ParameterMap &params)
 
virtual void configure (const ParameterMap &params)
 
virtual void configure ()
 
const ParameterMapdefaultParameters () const
 
const Parameterparameter (const std::string &key) const
 

Public Attributes

DescriptionMap inputDescription
 
DescriptionMap outputDescription
 
- Public Attributes inherited from Configurable
DescriptionMap parameterDescription
 
DescriptionMap parameterRange
 

Static Public Attributes

static const std::string processingMode
 

Protected Member Functions

void declareInput (SinkBase &sink, const std::string &name, const std::string &desc)
 
void declareInput (SinkBase &sink, int n, const std::string &name, const std::string &desc)
 
void declareInput (SinkBase &sink, int acquireSize, int releaseSize, const std::string &name, const std::string &desc)
 
void declareOutput (SourceBase &source, const std::string &name, const std::string &desc)
 
void declareOutput (SourceBase &source, int n, const std::string &name, const std::string &desc)
 
void declareOutput (SourceBase &source, int acquireSize, int releaseSize, const std::string &name, const std::string &desc)
 
- Protected Member Functions inherited from Configurable
void declareParameter (const std::string &name, const std::string &desc, const std::string &range, const Parameter &defaultValue)
 

Protected Attributes

bool _shouldStop
 
OutputMap _outputs
 
InputMap _inputs
 
int nProcess
 
- Protected Attributes inherited from Configurable
std::string _name
 
ParameterMap _params
 
ParameterMap _defaultParams
 

Friends

class essentia::scheduler::Network
 

Detailed Description

A streaming::Algorithm is an algorithm that can be used in streaming mode. It is very similar to a 'classic' algorithm, but instead of having inputs and outputs that you need to set manually each time you want to call the process() method, they have input stream connectors (called Sinks, because data flows into them as water in a sink) and output stream connectors (called Sources, because data flows out of them).

Connections between two algorithms (actually, between a source and a sink) represent a flow of Tokens, which can be of any type, as long as the Source and Sink are themselves of the same type. A token is the smallest unit you can have in your stream. For example, for an audio stream, the token type will be Real, because a single audio sample is represented as a Real. A frame cutter which outputs frames will have the Token type set to vector<Real>, because you can't take smaller than that, otherwise the frame would be incomplete. A framecutter is then a strange beast, because it has a Sink<Real> (input is a stream of audio samples), but has also a Source<vector<Real> >, because it outputs whole frames one by one. This might seem strange, but is not a problem at all.

NB: of course, the input of the framecutter will consume tokens much more quickly than the rate at which it produces output tokens (frames). That is not a problem at all.

Member Typedef Documentation

◆ InputMap

◆ OutputMap

Constructor & Destructor Documentation

◆ Algorithm()

Algorithm ( )
inline

◆ ~Algorithm()

virtual ~Algorithm ( )
inlinevirtual

Member Function Documentation

◆ acquireData()

AlgorithmStatus acquireData ( )

This is a non-blocking function.

Referenced by DiskWriter< T >::process(), and VectorInput< TokenType, acquireSize >::process().

◆ declareInput() [1/3]

void declareInput ( SinkBase sink,
const std::string &  name,
const std::string &  desc 
)
protected

◆ declareInput() [2/3]

void declareInput ( SinkBase sink,
int  acquireSize,
int  releaseSize,
const std::string &  name,
const std::string &  desc 
)
protected

Declare a Sink for this algorithm. The sink uses the given acquire/release size.

◆ declareInput() [3/3]

void declareInput ( SinkBase sink,
int  n,
const std::string &  name,
const std::string &  desc 
)
protected

Declare a Sink for this algorithm. The sink uses n for the acquire/release size.

◆ declareOutput() [1/3]

void declareOutput ( SourceBase source,
const std::string &  name,
const std::string &  desc 
)
protected

Declare a Source for this algorithm. The source uses its default acquire/release size.

Referenced by Copy< TokenType >::Copy(), AlgorithmComposite::declareOutput(), and VectorInput< TokenType, acquireSize >::VectorInput().

◆ declareOutput() [2/3]

void declareOutput ( SourceBase source,
int  acquireSize,
int  releaseSize,
const std::string &  name,
const std::string &  desc 
)
protected

Declare a Source for this algorithm. The source uses the given acquire/release size.

◆ declareOutput() [3/3]

void declareOutput ( SourceBase source,
int  n,
const std::string &  name,
const std::string &  desc 
)
protected

Declare a Source for this algorithm. The source uses n for the acquire/release size.

◆ disconnectAll()

void disconnectAll ( )

Disconnect all sources and sinks of this algorithm from anything they would be connected to.

◆ input() [1/2]

◆ input() [2/2]

SinkBase& input ( int  idx)

◆ inputNames()

std::vector<std::string> inputNames ( ) const
inline

Returns the names of all the inputs that have been defined for this algorithm.

◆ inputs()

const InputMap& inputs ( ) const
inline

◆ output() [1/2]

SourceBase& output ( const std::string &  name)

◆ output() [2/2]

SourceBase& output ( int  idx)

◆ outputNames()

std::vector<std::string> outputNames ( ) const
inline

Returns the names of all the outputs that have been defined for this algorithm.

◆ outputs()

const OutputMap& outputs ( ) const
inline

◆ process()

◆ releaseData()

◆ reset()

virtual void reset ( )
virtual

This function will be called when doing batch computations between each file that is processed. That is, if your algorithm is some sort of state machine, it allows you to reset it to its original state to process another file without having to delete and reinstantiate it. This function should not be called directly. Use resetNetwork instead to reset a network of connected Algorithms.

Reimplemented in StreamingAlgorithmWrapper, AlgorithmComposite, VectorOutput< TokenType, StorageType >, VectorInput< TokenType, acquireSize >, RingBufferVectorOutput, RingBufferOutput, RingBufferInput, and AccumulatorAlgorithm.

Referenced by VectorInput< TokenType, acquireSize >::reset(), and StreamingAlgorithmWrapper::reset().

◆ shouldStop() [1/2]

virtual bool shouldStop ( ) const
inlinevirtual

Returns whether the algorithm should stop, ie: it has received an end-of-stream signal.

Reimplemented in VectorInput< TokenType, acquireSize >.

◆ shouldStop() [2/2]

virtual void shouldStop ( bool  stop)
virtual

Sets whether an algorithm should stop as soon as it has finished processing all of its inputs. This is most often called when the algorithm has received an STOP_WHEN_DONE signal (at the end of the stream).

Reimplemented in RingBufferInput.

Friends And Related Function Documentation

◆ essentia::scheduler::Network

friend class essentia::scheduler::Network
friend

Member Data Documentation

◆ _inputs

InputMap _inputs
protected

◆ _outputs

OutputMap _outputs
protected

◆ _shouldStop

bool _shouldStop
protected

◆ inputDescription

DescriptionMap inputDescription

◆ nProcess

int nProcess
protected

number of times the process() method has been called

◆ outputDescription

DescriptionMap outputDescription

◆ processingMode

const std::string processingMode
static

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