SPKitProcessor


User's Guide

SPKitProcessor is the base class of all SPKit classes. It implements the basic protocol for connecting sound processing objects and passing samples between them. SPKitProcessor is an abstract class and not intended for direct use.

SPKitProcessor contains member functions common to all SPKit classes. The setInput(SPKitProcessor* ip) function is used for initialization and connecting a signal input to the object. A derived class may have its own initialization function, which must be used instead of the standard setInput() function. For example, SPKitDelay has a setInputAndDelayTime(SPKitProcessor* ip, SPKitFloat dt) function for connecting to the signal input and setting the delay time.

Other important functions inherited from SPKitProcesssor are getSamplingRate() and getChannelCount() for retrieving the sampling rate and number of channels of the object's output signal.


Programmer's Reference

Defined in <spkit/processo.h>.

All SPKit classes inherit from SPKitProcessor. It provides several useful member functions and variables which can be accessed from subclasses. Most importantly, SPKitProcessor defines a setInput() function for connecting and initializing signal processing objects and a getSample() function for retrieving and processing signal samples.

Public Members

The following members are declared virtual and may be overridden by subclasses:
SPKitError setInput(SPKitProcessor* newInput)
connect a signal input to the object and initialize it. Returns a negative value on error, 0 otherwise.

setInput() initializes a sound processing module by reading values for inputSamplingRate, inputChannelCount and originalDataFormat. setInput also initializes input to newInput.

Derived classes may re-define setInput() to do any initialization that requires data of the members in the paragraph above. A derived class should always call the base class setInput() before accessing any inherited members (e.g. those mentioned above). from its own setInput() or equivalent initialization function (e.g. see SPKitDelay::setInputAndDelayTime()).

Note: SPKit objects are not fully initialized before setInput() is called. While it is error-prone and not good C++ practice to leave an object in an un-initialized state after construction, there is a good reason for allowing this in SPKit: a derived class may call its base class' setInput() anywhere in its own definition of setInput(). This was found very useful and would not have been possible with standard C++ constructors.

void setOutput(SPKitProcessor* op)
set output to op. setInput() calls input->setOutput(this).
SPKitProcessor* getInput() const
returns input.
SPKitProcessor* getOutput() const
returns output.
int getSample(SPKitSample& outputSample)
retrieve a processed audio sample

getSample() stores the processed sample in outputSample. The function returns 0 on end of signal, 1 otherwise.

SPKitFloat getSamplingRate() const
retrieve sampling rate of an object

returns inputSamplingRate. A sampling rate converter class should override it.

SPKitInt getChannelCount() const
get number of audio channels

The following member functions are declared non-virtual:

SPKitInt getOriginalDataFormat() const
returns original data format (originalDataFormat) of the input sample stream.

Protected Members

SPKitProcessor* input
object's signal input
SPKitProcessor* output
object's signal output
SPKitFloat inputSamplingRate
sampling rate of object's input
SPKitInt inputChannelCount
number of channels of object's input
SPKitInt originalDataFormat
data format of input sound file or stream

Return to SPKit home

Kai Lassfolk / University of Helsinki / kpl@elisir.helsinki.fi