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 setAutoMakeupGain (bool enabled)
 Enables automatic makeup gain for compressor/limiter modes.
 
void reset ()
 
void process (juce::AudioSampleBuffer &buffer, juce::AudioSampleBuffer *envelopeOut=nullptr)
 
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);
// Get metering
float inputLevel = comp.getInputTracker().getLevel();
float outputLevel = comp.getOutputTracker().getLevel();
Dynamics processor supporting compression, limiting, expansion, and gating.
Definition gin_dynamics.h:130
@ compressor
Compression (reduce loud signals)
Definition gin_dynamics.h:147
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)

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

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

◆ 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: