Gin
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
Dynamics Class Reference

Dynamics processor supporting compression, limiting, expansion, and gating. More...

#include <gin_dynamics.h>

Public Types

enum  Type {
  compressor , limiter , expander , gate ,
  compexp
}
 Dynamics processing types. More...
 

Public Member Functions

 Dynamics ()=default
 
 ~Dynamics ()=default
 
void setSampleRate (double sampleRate)
 
void setNumChannels (int ch)
 
void setMode (Type t)
 
void setLinked (bool l)
 
void setParams (float attackS, float holdS, float releaseS, float thresh, float ratio, float kneeWidth)
 
void setInputGain (float g)
 
void setOutputGain (float g)
 
void setDetectorMode (EnvelopeDetector::Mode m)
 How the detector measures level: peak, mean square or RMS.
 
void setRMSWindow (float seconds)
 Averaging window for the ms and rms detector modes, in seconds.
 
void setAnalogTC (bool analog)
 Analog rather than digital time constants.
 
void setLookahead (float seconds)
 Delays the audio so the detector sees each transient before the gain does, in seconds.
 
int getLatencySamples () const
 Lookahead delay in samples, for AudioProcessor::setLatencySamples().
 
void setSidechainFilter (float highpassHz, float lowpassHz)
 Filters the detector's view of the signal without touching what is heard.
 
void setDetectorPeak (float freqHz, float q, float gainDb)
 A peak in the detector path, again heard only through what it makes the gain do.
 
void setAutoMakeupGain (bool enabled)
 Enables automatic makeup gain for compressor/limiter modes.
 
void reset ()
 
void process (juce::AudioSampleBuffer &buffer, juce::AudioSampleBuffer *envelopeOut=nullptr)
 Processes a buffer, with the detector following that same buffer.
 
void process (juce::AudioSampleBuffer &buffer, const juce::AudioSampleBuffer &sidechain, juce::AudioSampleBuffer *envelopeOut=nullptr)
 Processes a buffer, with the detector following a separate side chain.
 
const LevelTrackergetInputTracker ()
 
const LevelTrackergetOutputTracker ()
 
const LevelTrackergetReductionTracker ()
 
float calcCurve (float detectorValue)
 

Detailed Description

Dynamics processor supporting compression, limiting, expansion, and gating.

Dynamics provides a versatile dynamics processing engine that can function as a compressor, limiter, expander, or gate. Based on algorithms from "Designing Audio Effect Plug-ins in C++" by Will Pirkle, it features attack/hold/release envelope detection, adjustable ratio and threshold, soft knee, and optional channel linking for stereo operation.

The compexp mode combines downward compression (above threshold) with upward compression (below the inverted threshold), using the same ratio for both.

Key Features:

Usage:

comp.setSampleRate(44100.0);
comp.setNumChannels(2);
comp.setLinked(true); // Link stereo channels
// Set compression parameters
comp.setParams(0.01f, // 10ms attack
0.0f, // no hold
0.1f, // 100ms release
-20.0f, // -20dB threshold
4.0f, // 4:1 ratio
6.0f); // 6dB soft knee
comp.setInputGain(0.0f); // 0dB input
comp.setOutputGain(3.0f); // +3dB makeup gain
comp.process(audioBuffer);
// keyed off something else: duck the music under the voiceover
// Get metering
float inputLevel = comp.getInputTracker().getLevel();
float outputLevel = comp.getOutputTracker().getLevel();
Dynamics processor supporting compression, limiting, expansion, and gating.
Definition gin_dynamics.h:148
@ compressor
Compression (reduce loud signals)
Definition gin_dynamics.h:165
A lightweight 2D point class for projects that don't use juce_graphics.
Definition gin_point.h:25
See also
EnvelopeDetector, LevelTracker

Member Enumeration Documentation

◆ Type

Dynamics processing types.

Determines the type of dynamics processing applied:

  • compressor: Reduces gain above threshold (ratio > 1:1)
  • limiter: Hard limiting (very high ratio, fast attack)
  • expander: Increases dynamic range (reduces gain below threshold)
  • gate: Attenuates signals below threshold (extreme expansion)
  • compexp: Combined compressor + expander (expander threshold is inverse of compressor threshold)
Enumerator
compressor 

Compression (reduce loud signals)

limiter 

Limiting (prevent peaks above threshold)

expander 

Expansion (increase dynamic range)

gate 

Gate (cut quiet signals)

compexp 

Combined compressor and expander (expander uses inverse threshold)

Constructor & Destructor Documentation

◆ Dynamics()

Dynamics::Dynamics ( )
default

◆ ~Dynamics()

Dynamics::~Dynamics ( )
default

Member Function Documentation

◆ setSampleRate()

void Dynamics::setSampleRate ( double  sampleRate)

◆ setNumChannels()

void Dynamics::setNumChannels ( int  ch)

◆ setMode()

void Dynamics::setMode ( Type  t)

◆ setLinked()

void Dynamics::setLinked ( bool  l)

◆ setParams()

void Dynamics::setParams ( float  attackS,
float  holdS,
float  releaseS,
float  thresh,
float  ratio,
float  kneeWidth 
)

◆ setInputGain()

void Dynamics::setInputGain ( float  g)

◆ setOutputGain()

void Dynamics::setOutputGain ( float  g)

◆ setDetectorMode()

void Dynamics::setDetectorMode ( EnvelopeDetector::Mode  m)

How the detector measures level: peak, mean square or RMS.

See also
EnvelopeDetector::Mode, setRMSWindow

◆ setRMSWindow()

void Dynamics::setRMSWindow ( float  seconds)

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

See also
EnvelopeDetector::setRMSWindow

◆ setAnalogTC()

void Dynamics::setAnalogTC ( bool  analog)

Analog rather than digital time constants.

Digital constants reach 99% of the target in the time you asked for, analog ones 63% - the same curve a real capacitor charging through a resistor follows. Analog is slower to arrive and sounds gentler on the attack; digital does what the number says.

◆ setLookahead()

void Dynamics::setLookahead ( float  seconds)

Delays the audio so the detector sees each transient before the gain does, in seconds.

Without it, an attack fast enough to catch a peak has already let the front of that peak through.

Costs latency, which the host has to be told about - see getLatencySamples(). 5 ms is plenty for most material.

◆ getLatencySamples()

int Dynamics::getLatencySamples ( ) const

Lookahead delay in samples, for AudioProcessor::setLatencySamples().

◆ setSidechainFilter()

void Dynamics::setSidechainFilter ( float  highpassHz,
float  lowpassHz 
)

Filters the detector's view of the signal without touching what is heard.

A high pass stops kick drums pumping the whole mix; a low pass stops cymbals doing the same.

Parameters
highpassHzdetector high pass, 0 for none
lowpassHzdetector low pass, 0 for none

◆ setDetectorPeak()

void Dynamics::setDetectorPeak ( float  freqHz,
float  q,
float  gainDb 
)

A peak in the detector path, again heard only through what it makes the gain do.

Boost around 6 kHz and the compressor turns into a de-esser; boost the low mids and it leans on boxiness.

Parameters
freqHzcentre frequency
qwidth
gainDbboost or cut, 0 disables the filter

◆ setAutoMakeupGain()

void Dynamics::setAutoMakeupGain ( bool  enabled)

Enables automatic makeup gain for compressor/limiter modes.

When enabled, gain is automatically applied to compensate for the gain reduction, bringing peaks back to 0dB.

Parameters
enabledTrue to enable auto makeup gain

◆ reset()

void Dynamics::reset ( )

◆ process() [1/2]

void Dynamics::process ( juce::AudioSampleBuffer &  buffer,
juce::AudioSampleBuffer *  envelopeOut = nullptr 
)

Processes a buffer, with the detector following that same buffer.

Parameters
bufferaudio to process, in place
envelopeOutoptional detector envelope, as a linear level. Written to channel 0 when linked and to every channel otherwise, so it needs as many channels as the processor has.

◆ process() [2/2]

void Dynamics::process ( juce::AudioSampleBuffer &  buffer,
const juce::AudioSampleBuffer &  sidechain,
juce::AudioSampleBuffer *  envelopeOut = nullptr 
)

Processes a buffer, with the detector following a separate side chain.

The gain is worked out from sidechain and applied to buffer: ducking, de-essing, and gating something on a source other than itself. A gated reverb is the case that shows why it matters - keyed off its own output, a gate can only chase an envelope the reverb has already smeared, so it opens softly instead of on the transient and its timing shifts whenever the decay does.

Parameters
bufferaudio to process, in place
sidechainwhat the detector follows. Needs at least as many samples as buffer; fewer channels is fine, the last one is reused, so a mono key drives them all. Input gain scales what the detector sees here just as it does without a side chain.
envelopeOutoptional detector envelope, as above

◆ getInputTracker()

const LevelTracker & Dynamics::getInputTracker ( )

◆ getOutputTracker()

const LevelTracker & Dynamics::getOutputTracker ( )

◆ getReductionTracker()

const LevelTracker & Dynamics::getReductionTracker ( )

◆ calcCurve()

float Dynamics::calcCurve ( float  detectorValue)

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