Vital
Loading...
Searching...
No Matches
vital::Reverb Class Reference

A Processor implementing a dense feedback network reverb. More...

#include <reverb.h>

Inheritance diagram for vital::Reverb:
vital::Processor

Public Types

enum  {
  kAudio , kDecayTime , kPreLowCutoff , kPreHighCutoff ,
  kLowCutoff , kLowGain , kHighCutoff , kHighGain ,
  kChorusAmount , kChorusFrequency , kStereoWidth , kSize ,
  kDelay , kWet , kNumInputs
}
 

Public Member Functions

 Reverb ()
 Constructs a Reverb processor with default configuration.
 
virtual ~Reverb ()
 Default destructor.
 
void process (int num_samples) override
 Processes audio by pulling from the kAudio input buffer.
 
void processWithInput (const poly_float *audio_in, int num_samples) override
 Processes a block of audio using a provided input buffer.
 
force_inline float getSampleRateRatio (int sample_rate)
 Returns the ratio of the current sample rate to kBaseSampleRate.
 
force_inline int getBufferScale (int sample_rate)
 Computes a buffer scaling factor based on current sample rate.
 
void setSampleRate (int sample_rate) override
 Overrides base class to update reverb internal buffers at a new sample rate.
 
void setOversampleAmount (int oversample_amount) override
 Overrides base class to handle changes in oversampling factor.
 
void setupBuffersForSampleRate (int sample_rate)
 Adjusts internal buffer sizes and states for the given sample rate.
 
void hardReset () override
 Resets the reverb, clearing buffer contents and resetting filters.
 
force_inline poly_float readFeedback (const mono_float *const *lookups, poly_float offset)
 Reads from the feedback delay line with polynomial interpolation.
 
force_inline poly_float readAllpass (const mono_float *lookup, poly_int offset)
 Reads from the all-pass filters using integer offsets.
 
force_inline void wrapFeedbackBuffer (mono_float *buffer)
 Wraps the feedback buffer to preserve continuity for polynomial interpolation.
 
virtual Processorclone () const override
 Creates a clone of this Processor. (Not implemented for Reverb).
 
- Public Member Functions inherited from vital::Processor
 Processor (int num_inputs, int num_outputs, bool control_rate=false, int max_oversample=1)
 Constructs a Processor with a given number of inputs/outputs and oversampling.
 
virtual ~Processor ()
 Virtual destructor.
 
virtual bool hasState () const
 Indicates whether this Processor requires per-voice state.
 
virtual void init ()
 Called after constructor, used for any additional initialization. Subclasses can override. Sets the initialized flag.
 
virtual void reset (poly_mask reset_mask)
 Called to reset the Processor's per-voice state (e.g., on note-on).
 
bool initialized ()
 Returns whether this Processor has been initialized.
 
force_inline bool enabled () const
 Checks if this Processor is enabled.
 
virtual void enable (bool enable)
 Enables or disables this Processor.
 
force_inline int getSampleRate () const
 Retrieves the current (effective) sample rate.
 
force_inline int getOversampleAmount () const
 Retrieves the current oversampling factor.
 
force_inline bool isControlRate () const
 Checks if this Processor is running at control rate (buffer_size == 1).
 
virtual void setControlRate (bool control_rate)
 Sets whether this Processor runs at control rate.
 
force_inline poly_mask getResetMask (int input_index) const
 Retrieves a mask indicating which voices triggered a note-on event. Compares the input's trigger_value to kVoiceOn.
 
force_inline void clearOutputBufferForReset (poly_mask reset_mask, int input_index, int output_index) const
 Clears output samples for voices that are about to be reset, based on the trigger offset.
 
bool inputMatchesBufferSize (int input=0)
 Checks whether the buffer size of a particular input matches the size needed by this Processor.
 
bool checkInputAndOutputSize (int num_samples)
 Checks if all inputs and outputs have buffers big enough for num_samples.
 
virtual bool isPolyphonic () const
 Checks if this Processor is polyphonic by querying its ProcessorRouter.
 
void plug (const Output *source)
 Connects an external Output to this Processor's first input.
 
void plug (const Output *source, unsigned int input_index)
 Connects an external Output to a specified input index.
 
void plug (const Processor *source)
 Connects the first output of a Processor to this Processor's first input.
 
void plug (const Processor *source, unsigned int input_index)
 Connects the first output of a Processor to a specified input index.
 
void plugNext (const Output *source)
 Connects an external Output to the first available (unplugged) input.
 
void plugNext (const Processor *source)
 Connects the first output of a Processor to the first available (unplugged) input.
 
void useInput (Input *input)
 Uses an existing Input object as this Processor's first input.
 
void useInput (Input *input, int index)
 Uses an existing Input object at a specified input index.
 
void useOutput (Output *output)
 Uses an existing Output object as this Processor's first output.
 
void useOutput (Output *output, int index)
 Uses an existing Output object at a specified output index.
 
int connectedInputs ()
 Counts how many inputs are connected to a real source (not null_source_).
 
virtual void unplugIndex (unsigned int input_index)
 Removes the connection at a specified input index, if any.
 
virtual void unplug (const Output *source)
 Removes a connection to a given Output from all inputs.
 
virtual void unplug (const Processor *source)
 Removes connections to all outputs from a given Processor.
 
virtual void numInputsChanged ()
 Called when the number of inputs changes (e.g., new connections). Subclasses may override for dynamic behavior.
 
force_inline void router (ProcessorRouter *router)
 Sets the ProcessorRouter that owns or manages this Processor.
 
force_inline ProcessorRouterrouter () const
 Returns the ProcessorRouter that currently owns this Processor.
 
ProcessorRoutergetTopLevelRouter () const
 Gets the topmost (root) ProcessorRouter by traversing parent routers.
 
virtual void registerInput (Input *input, int index)
 Registers a new input, appending it to the input list.
 
virtual OutputregisterOutput (Output *output, int index)
 Registers a new Output in the output list at a specified index.
 
virtual void registerInput (Input *input)
 Registers a new Input by appending it to the end of the input list.
 
virtual OutputregisterOutput (Output *output)
 Registers a new Output by appending it to the end of the output list.
 
force_inline int numInputs () const
 Returns the total number of Input pointers (owned or otherwise).
 
force_inline int numOutputs () const
 Returns the total number of Output pointers (owned or otherwise).
 
force_inline int numOwnedInputs () const
 Returns how many Input objects this Processor owns.
 
force_inline int numOwnedOutputs () const
 Returns how many Output objects this Processor owns.
 
force_inline Inputinput (unsigned int index=0) const
 Retrieves the Input pointer at a given index.
 
force_inline bool isInputSourcePolyphonic (int index=0)
 Checks if the input source at a given index is polyphonic.
 
force_inline InputownedInput (unsigned int index=0) const
 Retrieves an owned Input pointer at a given index.
 
force_inline Outputoutput (unsigned int index=0) const
 Retrieves the Output pointer at a given index.
 
force_inline OutputownedOutput (unsigned int index=0) const
 Retrieves an owned Output pointer at a given index.
 
void setPluggingStart (int start)
 Sets the position at which plugNext starts searching for an open input.
 

Static Public Attributes

static constexpr mono_float kT60Amplitude = 0.001f
 Amplitude at which we consider the reverb tail to effectively end (T60).
 
static constexpr mono_float kAllpassFeedback = 0.6f
 Feedback coefficient for all-pass filter sections.
 
static constexpr float kMinDelay = 3.0f
 Minimum delay (in samples) used for certain time-domain operations.
 
static constexpr int kBaseSampleRate = 44100
 Reference sample rate for the base reverb time calculations.
 
static constexpr int kDefaultSampleRate = 88200
 Default sample rate used for internal buffer initialization.
 
static constexpr int kNetworkSize = 16
 Number of feedback delay lines in the network.
 
static constexpr int kBaseFeedbackBits = 14
 Base bits used for feedback buffer size calculations.
 
static constexpr int kExtraLookupSample = 4
 Extra samples in the buffer to allow for interpolation overflow.
 
static constexpr int kBaseAllpassBits = 10
 Base bits used for the all-pass filters’ buffer size.
 
static constexpr int kNetworkContainers = kNetworkSize / poly_float::kSize
 Number of poly_float-sized containers covering the entire network.
 
static constexpr int kMinSizePower = -3
 Minimum size exponent for reverb buffer scale.
 
static constexpr int kMaxSizePower = 1
 Maximum size exponent for reverb buffer scale.
 
static constexpr float kSizePowerRange = kMaxSizePower - kMinSizePower
 The exponent range (max minus min).
 
static const poly_int kAllpassDelays [kNetworkContainers]
 Fixed all-pass filter delays for each container.
 
static const poly_float kFeedbackDelays [kNetworkContainers]
 Fixed feedback delays (in samples) for each container.
 

Additional Inherited Members

- Protected Member Functions inherited from vital::Processor
OutputaddOutput (int oversample=1)
 Creates and registers a new Output. Handles control rate vs. audio rate.
 
InputaddInput ()
 Creates and registers a new Input, initially connected to null_source_.
 
- Protected Attributes inherited from vital::Processor
std::shared_ptr< ProcessorStatestate_
 Shared state (sample rate, oversample, etc.)
 
int plugging_start_
 The index at which plugNext starts searching for an unplugged input.
 
std::vector< std::shared_ptr< Input > > owned_inputs_
 Inputs owned by this Processor.
 
std::vector< std::shared_ptr< Output > > owned_outputs_
 Outputs owned by this Processor.
 
std::shared_ptr< std::vector< Input * > > inputs_
 All inputs, owned or external.
 
std::shared_ptr< std::vector< Output * > > outputs_
 All outputs, owned or external.
 
ProcessorRouterrouter_
 The ProcessorRouter that manages this Processor.
 
- Static Protected Attributes inherited from vital::Processor
static const Output null_source_
 A null (dummy) source used for unconnected inputs.
 

Detailed Description

A Processor implementing a dense feedback network reverb.

The Reverb uses multiple all-pass filters and feedback delay lines to create a spacious, reverberant sound. It can be controlled via decay time, cutoff filters, chorus modulation, stereo width, and more.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
kAudio 

Audio input buffer.

kDecayTime 

Reverb decay time in seconds.

kPreLowCutoff 

Pre-filter low cutoff (MIDI note)

kPreHighCutoff 

Pre-filter high cutoff (MIDI note)

kLowCutoff 

Internal feedback low cutoff (MIDI note)

kLowGain 

Low-frequency attenuation (dB)

kHighCutoff 

Internal feedback high cutoff (MIDI note)

kHighGain 

High-frequency attenuation (dB)

kChorusAmount 

Amount of chorusing applied to feedback lines.

kChorusFrequency 

Frequency of the chorus LFO (Hz)

kStereoWidth 

Stereo width parameter (not used in all reverb modes)

kSize 

Overall size (scales buffer size exponent)

kDelay 

Additional pre-delay in samples.

kWet 

Dry/wet mix.

kNumInputs 

Total number of inputs.

Constructor & Destructor Documentation

◆ Reverb()

vital::Reverb::Reverb ( )

Constructs a Reverb processor with default configuration.

Constructs a Reverb object with default sample rate and buffer sizes.

Allocates internal buffers and sets a default sample rate for initialization.

Allocates internal feedback memories and sets default filter coefficients.

◆ ~Reverb()

virtual vital::Reverb::~Reverb ( )
inlinevirtual

Default destructor.

Member Function Documentation

◆ clone()

virtual Processor * vital::Reverb::clone ( ) const
inlineoverridevirtual

Creates a clone of this Processor. (Not implemented for Reverb).

Returns
Returns nullptr.

Implements vital::Processor.

◆ getBufferScale()

force_inline int vital::Reverb::getBufferScale ( int sample_rate)
inline

Computes a buffer scaling factor based on current sample rate.

Doubling from kBaseSampleRate to keep the buffer sizes a power of two.

Parameters
sample_rateThe current sample rate.
Returns
The integer scaling factor.

◆ getSampleRateRatio()

force_inline float vital::Reverb::getSampleRateRatio ( int sample_rate)
inline

Returns the ratio of the current sample rate to kBaseSampleRate.

Parameters
sample_rateThe current sample rate.
Returns
The ratio between current sample rate and the base sample rate.

◆ hardReset()

void vital::Reverb::hardReset ( )
overridevirtual

Resets the reverb, clearing buffer contents and resetting filters.

Resets the reverb to its default/initial state.

Clears feedback buffers, all-pass buffers, and filter states. Resets chorus amount based on the current parameter.

Reimplemented from vital::Processor.

◆ process()

void vital::Reverb::process ( int num_samples)
overridevirtual

Processes audio by pulling from the kAudio input buffer.

Processes the Reverb by reading from the kAudio input buffer.

Parameters
num_samplesNumber of samples to process.

Implements vital::Processor.

◆ processWithInput()

void vital::Reverb::processWithInput ( const poly_float * audio_in,
int num_samples )
overridevirtual

Processes a block of audio using a provided input buffer.

Processes the Reverb effect using an external input buffer.

Parameters
audio_inPointer to the input buffer.
num_samplesNumber of samples to process.

Applies the entire reverb network chain: wrapping buffers, reading from all-pass lines, writing into feedback delay lines, computing shelving filters, and blending the result with the dry signal.

Parameters
audio_inPointer to the input buffer.
num_samplesNumber of samples to process.

Reimplemented from vital::Processor.

◆ readAllpass()

force_inline poly_float vital::Reverb::readAllpass ( const mono_float * lookup,
poly_int offset )
inline

Reads from the all-pass filters using integer offsets.

Parameters
lookupPointer to the all-pass delay line memory.
offsetThe integer offset into the delay line.
Returns
Sample from the all-pass buffer at that offset.

◆ readFeedback()

force_inline poly_float vital::Reverb::readFeedback ( const mono_float *const * lookups,
poly_float offset )
inline

Reads from the feedback delay line with polynomial interpolation.

Parameters
lookupsPointer array of pointers to delay line memory blocks.
offsetThe fractional read offset (in samples).
Returns
Interpolated sample from the feedback delay line.

◆ setOversampleAmount()

void vital::Reverb::setOversampleAmount ( int oversample_amount)
overridevirtual

Overrides base class to handle changes in oversampling factor.

Updates oversampling and reconfigures the reverb buffers.

Parameters
oversample_amountThe new oversampling factor.
oversample_amountThe oversampling factor.

Reimplemented from vital::Processor.

◆ setSampleRate()

void vital::Reverb::setSampleRate ( int sample_rate)
overridevirtual

Overrides base class to update reverb internal buffers at a new sample rate.

Updates the sample rate and reconfigures the reverb buffers.

Parameters
sample_rateThe new sample rate in Hz.
sample_rateThe new sample rate.

Reimplemented from vital::Processor.

◆ setupBuffersForSampleRate()

void vital::Reverb::setupBuffersForSampleRate ( int sample_rate)

Adjusts internal buffer sizes and states for the given sample rate.

Allocates buffer sizes and resets reverb memory for the given sample_rate.

Parameters
sample_rateThe current sample rate in Hz.

◆ wrapFeedbackBuffer()

force_inline void vital::Reverb::wrapFeedbackBuffer ( mono_float * buffer)
inline

Wraps the feedback buffer to preserve continuity for polynomial interpolation.

Copies the first few samples to the end so wrapping indices read correct data.

Parameters
bufferPointer to the feedback delay memory.

Member Data Documentation

◆ kAllpassDelays

const poly_int vital::Reverb::kAllpassDelays
static
Initial value:
= {
{ 1001, 799, 933, 876 },
{ 895, 807, 907, 853 },
{ 957, 1019, 711, 567 },
{ 833, 779, 663, 997 }
}

Fixed all-pass filter delays for each container.

◆ kAllpassFeedback

mono_float vital::Reverb::kAllpassFeedback = 0.6f
staticconstexpr

Feedback coefficient for all-pass filter sections.

◆ kBaseAllpassBits

int vital::Reverb::kBaseAllpassBits = 10
staticconstexpr

Base bits used for the all-pass filters’ buffer size.

◆ kBaseFeedbackBits

int vital::Reverb::kBaseFeedbackBits = 14
staticconstexpr

Base bits used for feedback buffer size calculations.

◆ kBaseSampleRate

int vital::Reverb::kBaseSampleRate = 44100
staticconstexpr

Reference sample rate for the base reverb time calculations.

◆ kDefaultSampleRate

int vital::Reverb::kDefaultSampleRate = 88200
staticconstexpr

Default sample rate used for internal buffer initialization.

◆ kExtraLookupSample

int vital::Reverb::kExtraLookupSample = 4
staticconstexpr

Extra samples in the buffer to allow for interpolation overflow.

◆ kFeedbackDelays

const poly_float vital::Reverb::kFeedbackDelays
static
Initial value:
= {
{ 6753.2f, 9278.4f, 7704.5f, 11328.5f },
{ 9701.12f, 5512.5f, 8480.45f, 5638.65f },
{ 3120.73f, 3429.5f, 3626.37f, 7713.52f },
{ 4521.54f, 6518.97f, 5265.56f, 5630.25f }
}

Fixed feedback delays (in samples) for each container.

◆ kMaxSizePower

int vital::Reverb::kMaxSizePower = 1
staticconstexpr

Maximum size exponent for reverb buffer scale.

◆ kMinDelay

float vital::Reverb::kMinDelay = 3.0f
staticconstexpr

Minimum delay (in samples) used for certain time-domain operations.

◆ kMinSizePower

int vital::Reverb::kMinSizePower = -3
staticconstexpr

Minimum size exponent for reverb buffer scale.

◆ kNetworkContainers

int vital::Reverb::kNetworkContainers = kNetworkSize / poly_float::kSize
staticconstexpr

Number of poly_float-sized containers covering the entire network.

◆ kNetworkSize

int vital::Reverb::kNetworkSize = 16
staticconstexpr

Number of feedback delay lines in the network.

◆ kSizePowerRange

float vital::Reverb::kSizePowerRange = kMaxSizePower - kMinSizePower
staticconstexpr

The exponent range (max minus min).

◆ kT60Amplitude

mono_float vital::Reverb::kT60Amplitude = 0.001f
staticconstexpr

Amplitude at which we consider the reverb tail to effectively end (T60).


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