ofxPDSP
pdsp::RMSDetector Class Reference

An RMS signal detector. More...

#include <RMSDetector.h>

Inheritance diagram for pdsp::RMSDetector:
pdsp::Unit pdsp::Preparable pdsp::Patchable

Public Member Functions

Patchableset (float window_ms)
 sets the window millisecond value and returns this unit ready to be patched. An array of values will be deallocated and the allocated again so this is ABSOLUTELY not thread-safe to run in the audio-thread. More...
 
Patchablein_signal ()
 Sets "signal" as selected input and returns this Unit ready to be patched. This is the default input. This is the detector input.
 
Patchableout_signal ()
 Sets "signal" as selected output and returns this Unit ready to be patched. This is the default output. This is the detector output.
 
float meter_output () const
 return the first value of the last processed output buffer.
 
int getWindowSamples () const
 return the ms window in samples, useful for set a delay for lookahead correction with a SamplesDelay.
 
- Public Member Functions inherited from pdsp::Unit
 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

void prepareUnit (int expectedBufferSize, double sampleRate) override
 this method will be called to prepare the unit to play. More...
 
void releaseResources () override
 this method will be called to release the unit resoruces. More...
 
void process (int bufferSize) noexcept override
 the unit DSP method to override More...
 
- Protected Member Functions inherited from pdsp::Unit
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...
 

Additional Inherited Members

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

Detailed Description

An RMS signal detector.

This Unit makes for each samples the Root Mean Squared of the values inside a given time window. It is useful as first step for dynamic processing. If set(float window_ms) is not used the window is to 50ms.

Member Function Documentation

◆ prepareUnit()

void pdsp::RMSDetector::prepareUnit ( int  expectedBufferSize,
double  sampleRate 
)
overrideprotectedvirtual

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()

Implements pdsp::Unit.

◆ process()

void pdsp::RMSDetector::process ( int  bufferSize)
overrideprotectedvirtualnoexcept

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".

Implements pdsp::Unit.

◆ releaseResources()

void pdsp::RMSDetector::releaseResources ( )
overrideprotectedvirtual

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.

Implements pdsp::Unit.

◆ set()

pdsp::Patchable & pdsp::RMSDetector::set ( float  window_ms)

sets the window millisecond value and returns this unit ready to be patched. An array of values will be deallocated and the allocated again so this is ABSOLUTELY not thread-safe to run in the audio-thread.

Parameters
[in]window_msvalue in milliseconds of the RMS-window time.

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