ofxPDSP
pdsp::Unit Class Referenceabstract

Abstract class for implementing Units. More...

#include <BasicNodes.h>

Inheritance diagram for pdsp::Unit:
pdsp::Preparable pdsp::Patchable pdsp::ADSR pdsp::AHR pdsp::AllPassDelay pdsp::Amp pdsp::APF1 pdsp::APF4 pdsp::BiquadBase pdsp::Bitcruncher pdsp::ClockedPhasor pdsp::Decimator pdsp::Delay pdsp::DownSampler pdsp::EnvelopeFollower pdsp::ExternalInput pdsp::FDLConvolver pdsp::Formula pdsp::GainComputer pdsp::GrainWindow pdsp::LFOPhasor pdsp::LHDelay pdsp::MaxValue2 pdsp::MultiLadder4 pdsp::OneBarTimeMs pdsp::OnePole pdsp::Oscillator pdsp::OscillatorVariShape pdsp::PatchNode pdsp::PhasorShifter pdsp::PMPhasor pdsp::RMSDetector pdsp::SampleAndHold pdsp::Sampler pdsp::SamplesDelay pdsp::Scope pdsp::SoftClip pdsp::SRDelay pdsp::SVF2 pdsp::Switch pdsp::ToGateTrigger pdsp::TriggerControl pdsp::TriggeredRandom pdsp::TriggerGeiger pdsp::UpSampler pdsp::ValueControl pdsp::WhiteNoise pdsp::Wrapper

Public Member Functions

 Unit (const Unit &other)
 
Unitoperator= (const Unit &other)
 
 Unit (Unit &&other)
 
Unitoperator= (Unit &&other)
 
virtual void setOversampleLevel (int newOversampleLevel)
 sets the unit oversample level More...
 
int getOversampleLevel () const
 returns the Unit oversample level
 
- Public Member Functions inherited from pdsp::Patchable
void resetInputToDefault ()
 resets the selected input to the default.
 
void resetOutputToDefault ()
 resets the selected output to the default.
 
Patchablein (const char *tag)
 sets the selected input to the one tagged with "tag", if tag is a valid string, and returns this Patchable ready to be patched. More...
 
Patchableout (const char *tag)
 sets the selected output to the one tagged with "tag", if tag is a valid string, and returns this Patchable ready to be patched. More...
 
void disconnectIn ()
 disconnects all the outputs connected to the selected input, then resets the selected input to the default.
 
void disconnectOut ()
 disconnects all the inputs connected to the selected output, then resets the selected output to the default.
 
void disconnectAll ()
 disconnects all the inputs and outputs to their connected outputs and inputs. Also resets the selected input and output to the default.
 
InputNodegetSelectedInput ()
 returns the selected input, you can patch a Patchable or OutputNode to it with the >> operator.
 
OutputNodegetSelectedOutput ()
 returns the selected output, you can patch it to another Patchable or InputNode with the >> operator.
 
std::vector< std::string > getInputsList ()
 returns a vector of the valid input tags
 
std::vector< std::string > getOutputsList ()
 returns a vector of the valid input tags
 

Protected Member Functions

virtual void process (int bufferSize) noexcept=0
 the unit DSP method to override More...
 
virtual void prepareUnit (int expectedBufferSize, double sampleRate)=0
 this method will be called to prepare the unit to play. More...
 
virtual void releaseResources () override=0
 this method will be called to release the unit resoruces. More...
 
void prepareToPlay (int expectedBufferSize, double sampleRate) override
 you have to use this method only in the constructor, inside if(dynamicConstruction){ } More...
 
const float * processInput (InputNode &node, int &stateNow)
 process the given input, gives you a pointer to the processed buffer as result and its state More...
 
float processAndGetSingleValue (InputNode &input, int pos)
 process the given input, gives you a pointer to the processed buffer as result and its state More...
 
float * getOutputBufferToFill (OutputNode &node)
 gets a pointer to the output buffer for rendering audio to it, and sets the OutputNode state to AudioRate More...
 
void setControlRateOutput (OutputNode &node, float scalarValue)
 sets the OutputNode buffer to "Changed" and its first value to scalarValue More...
 
void setOutputToZero (OutputNode &node)
 sets the OutputNode buffer to "Changed" and its first value to 0.0f More...
 
void updateOutputNodes ()
 call this method in the Unit constructor after adding all the Outputs, this is mandatory for the inner working of the patching framework.
 
- Protected Member Functions inherited from pdsp::Patchable
void addOutput (const char *tag, OutputNode &output)
 method to add outputs when constructing a Unit More...
 
void addInput (const char *tag, InputNode &input)
 method to add inputs when constructing a Unit More...
 
void addModuleOutput (const char *tag, Patchable &unit)
 method to add outputs when constructing a module More...
 
void addModuleInput (const char *tag, Patchable &unit)
 method to add outputs when constructing a module More...
 

Friends

class InputNode
 

Additional Inherited Members

- Static Public Member Functions inherited from pdsp::Preparable
static double getGlobalSampleRate ()
 

Detailed Description

Abstract class for implementing Units.

Unit is the base class for implementing all the DSPs. It has inputs and outputs for patching and process them in the process() code.

Member Function Documentation

◆ getOutputBufferToFill()

float * pdsp::Unit::getOutputBufferToFill ( OutputNode node)
protected

gets a pointer to the output buffer for rendering audio to it, and sets the OutputNode state to AudioRate

Parameters
[in]nodeOutputNode to render

This method will give you a buffer to fill with the result of the DSP

◆ prepareToPlay()

void pdsp::Unit::prepareToPlay ( int  expectedBufferSize,
double  sampleRate 
)
overrideprotected

you have to use this method only in the constructor, inside if(dynamicConstruction){ }

Parameters
[in]expectedBufferSizethe size of the expected buffersize
[in]sampleRatethe sample rate

This method will be called before playing to prepare the Unit to play, it will call also prepareUnit(...) with the correct sample rates and buffer sizes, the method is protected so you can use it in your constructor method, it will resolve some problems that could arise only when allocating and deallocating Units when the program is already running (more on this later in some wiki...)

◆ prepareUnit()

virtual void pdsp::Unit::prepareUnit ( int  expectedBufferSize,
double  sampleRate 
)
protectedpure virtual

this method will be called to prepare the unit to play.

Parameters
[in]expectedBufferSizethe size of the expected buffersize, already multiplied if the Unit is oversampling
[in]sampleRatethe sample rate, already multiplied if the Unit is oversampling

This method will be called before playing to prepare the Unit to play, remember that in some cases (when programming vst/au) it could be called more than once without even calling releaseResources()

Implemented in pdsp::Wrapper, and pdsp::RMSDetector.

◆ process()

virtual void pdsp::Unit::process ( int  bufferSize)
protectedpure virtualnoexcept

the unit DSP method to override

Parameters
[in]bufferSizethe size of the buffersize, already multiplied if the Unit is oversampling

This is the method to implement for calling the inputs processing methods, process the signal and render then in the output buffers. Remember that some clients not use a buffer size of constant size, and you can't be even shure that is a multiple of 2. Remember to set all the methods inside process() to noexcept, and absolutely avoid allocating and deallocating memory. Avoid branches if possible, and if needed "switch" is preferred to "if".

Implemented in pdsp::RMSDetector.

◆ processAndGetSingleValue()

float pdsp::Unit::processAndGetSingleValue ( InputNode input,
int  pos 
)
protected

process the given input, gives you a pointer to the processed buffer as result and its state

Parameters
[in]nodeInputNode to process
[in]posposition of the value inside the buffer to get. WARNING: boundary not checked!!!

This method will process the given input and give you the value at pos as result. If the input state after processing is Unchanged or Changed it will give the value at index 0 as result.

◆ processInput()

const float * pdsp::Unit::processInput ( InputNode node,
int &  stateNow 
)
protected

process the given input, gives you a pointer to the processed buffer as result and its state

Parameters
[in]nodeInputNode to process
[in]stateNowthis int will be set to the input state after processing (Unchanged==0, Changed==1, AudioRate==2)

This method will process the given input and give you a pointer as result. If the state is Unchanged or Changed only the first value of the given array is meaningful, otherwise the full array rapresent the buffer to process.

◆ releaseResources()

virtual void pdsp::Unit::releaseResources ( )
overrideprotectedpure virtual

this method will be called to release the unit resoruces.

This method will be called when pdsp::releaseAll() is called, so in some cases it could be called more than once in succession without a corresponding prepareToPlay() call, and it is also called on destruction, so make it robust enough.

Implemented in pdsp::Wrapper, and pdsp::RMSDetector.

◆ setControlRateOutput()

void pdsp::Unit::setControlRateOutput ( OutputNode node,
float  scalarValue 
)
protected

sets the OutputNode buffer to "Changed" and its first value to scalarValue

Parameters
[in]nodeOutputNode to render
[in]scalarValueOutputNode value

If you know that the output of your DSP will be constant for all the buffer size use this method. This method flags also the OutputNode as "Changed", it means that it isn't running at audio rate and this will save some cpu for other Unit that have this output patched to them.

◆ setOutputToZero()

void pdsp::Unit::setOutputToZero ( OutputNode node)
protected

sets the OutputNode buffer to "Changed" and its first value to 0.0f

Parameters
[in]nodeOutputNode to render

If you know that the output of your DSP will be constant for all the buffer size use this method. This method flags also the OutputNode as "Changed", it means that it isn't running at audio rate and this will save some cpu for other Unit that have this output patched to them. As you are also setting the value to 0.0f, this will save even more cpu... for example when Amp know that has to multiply for 0.0f it doesn't even process the in_signal() inputs and directly set the result to 0.0f.

◆ setOversampleLevel()

void pdsp::Unit::setOversampleLevel ( int  newOversampleLevel)
virtual

sets the unit oversample level

Parameters
[in]newOversampleLevelthe oversample level, 2 for 2x, 4 for 4x, etc etc

This method let you set the Unit oversample level, the Unit will run at a multiple of the sample rate. Remember to upsample the inputs with an UpSampler and downsample the outputs with a DownSampler


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