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 redefine 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 uninitialized 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 in many SPKit classes and would not have been possible with standard C++ constructors.

void setOutput(SPKitProcessor* op)
Set output to op. setInput() calls input->setOutput(this).

Signal multiplexing objects, and other objects that may have multiple outputs, may need to override setOutput() to store all their outputs to an array instead of the default member variable output.

SPKitProcessor* getInput() const
Returns input.

SPKitProcessor* getOutput() const
Returns output.

int getSample(SPKitSample& outputSample, SPKitProcessor* caller)
retrieve a processed audio sample

getSample() stores the processed sample in outputSample. The function returns 0 on end of signal, 1 otherwise. SPKitProcessor::getSample() has no signal processing functionality. It just retrieves a sample from input and stores it in outputSample. However, the function is useful and is inherited by composite processors, such as SPKitComb and SPKitComb

caller is a pointer to the object that requests a sample. caller can be used, for example, by signal routing objects (e.g. a multiplexer) to direct samples to the right outputs.

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 (i.e. sample encoding) of input sound file or stream


Return to top level.

Author: Kai Lassfolk