Gin
Loading...
Searching...
No Matches
EnvelopeDetector Class Reference

Envelope follower for dynamics processing. More...

#include <gin_dynamics.h>

Public Types

enum  Mode { peak , ms , rms }
 Envelope detection modes. More...

Public Member Functions

 EnvelopeDetector ()=default
 ~EnvelopeDetector ()=default
void setSampleRate (double f)
void setParams (float attackS, float holdS, float releaseS, bool analogTC, Mode detect, bool logDetector)
void setRMSWindow (float seconds)
 Averaging window for the ms and rms modes, in seconds.
void reset ()
float process (float input)

Protected Member Functions

void setAttackTime (float attackS)
void setHoldTime (float holdS)
void setReleaseTime (float releaseS)

Protected Attributes

double sampleRate = 44100.0
Mode mode = peak
float attackTime = 0.0f
float releaseTime = 0.0f
float envelope = 0.0
float holdTime = 0.0f
float holdRemaining = 0.0f
bool analogTC = false
bool logDetector = false
float rmsWindow = 0.010f
float rmsA = 1.0f
float rmsB = 0.0f
float rmsState = 0.0f

Detailed Description

Envelope follower for dynamics processing.

EnvelopeDetector tracks the amplitude envelope of an audio signal using configurable attack, hold, and release times. It supports multiple detection modes (peak, mean-square, RMS) and can use analog-style or digital time constants for natural or precise envelope following.

Key Features:

  • Three detection modes: peak, MS, RMS
  • Attack, hold, and release time controls
  • Analog or digital time constants
  • Optional logarithmic detector for dB domain
  • Sample-by-sample processing
  • Used by compressors, gates, expanders, limiters

The envelope detector is the core component for gain reduction calculations in dynamics processors, providing a smooth representation of signal level over time.

See also
Dynamics, LevelTracker

Member Enumeration Documentation

◆ Mode

Envelope detection modes.

Determines how the input signal is converted to an envelope value:

  • peak: Track the absolute peak value
  • ms: Mean square (squared values, more sensitive to transients)
  • rms: Root mean square (true RMS level detection)
Enumerator
peak 

Peak detection (absolute value).

ms 

Mean square detection.

rms 

RMS (root mean square) detection.

Constructor & Destructor Documentation

◆ EnvelopeDetector()

EnvelopeDetector::EnvelopeDetector ( )
default

◆ ~EnvelopeDetector()

EnvelopeDetector::~EnvelopeDetector ( )
default

Member Function Documentation

◆ setSampleRate()

void EnvelopeDetector::setSampleRate ( double f)

References rmsWindow, sampleRate, and setRMSWindow().

◆ setParams()

void EnvelopeDetector::setParams ( float attackS,
float holdS,
float releaseS,
bool analogTC,
Mode detect,
bool logDetector )

References analogTC, and logDetector.

◆ setRMSWindow()

void EnvelopeDetector::setRMSWindow ( float seconds)

Averaging window for the ms and rms modes, in seconds.

This is what makes RMS detection mean anything: the squared input is averaged over the window before the attack and release stages see it, so the detector responds to how much energy is in the signal rather than to individual samples. Short windows (1 ms) approach peak detection, long ones (50 ms+) ignore transients almost entirely, which is the loudness-following behaviour a bus compressor wants.

Has no effect in peak mode.

Referenced by setSampleRate().

◆ reset()

void EnvelopeDetector::reset ( )

◆ process()

float EnvelopeDetector::process ( float input)

◆ setAttackTime()

void EnvelopeDetector::setAttackTime ( float attackS)
protected

◆ setHoldTime()

void EnvelopeDetector::setHoldTime ( float holdS)
protected

◆ setReleaseTime()

void EnvelopeDetector::setReleaseTime ( float releaseS)
protected

Member Data Documentation

◆ sampleRate

double EnvelopeDetector::sampleRate = 44100.0
protected

Referenced by setSampleRate().

◆ mode

Mode EnvelopeDetector::mode = peak
protected

◆ attackTime

float EnvelopeDetector::attackTime = 0.0f
protected

◆ releaseTime

float EnvelopeDetector::releaseTime = 0.0f
protected

◆ envelope

float EnvelopeDetector::envelope = 0.0
protected

◆ holdTime

float EnvelopeDetector::holdTime = 0.0f
protected

◆ holdRemaining

float EnvelopeDetector::holdRemaining = 0.0f
protected

◆ analogTC

bool EnvelopeDetector::analogTC = false
protected

Referenced by setParams().

◆ logDetector

bool EnvelopeDetector::logDetector = false
protected

Referenced by setParams().

◆ rmsWindow

float EnvelopeDetector::rmsWindow = 0.010f
protected

Referenced by setSampleRate().

◆ rmsA

float EnvelopeDetector::rmsA = 1.0f
protected

◆ rmsB

float EnvelopeDetector::rmsB = 0.0f
protected

◆ rmsState

float EnvelopeDetector::rmsState = 0.0f
protected

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