Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::signal::CompressorT< SampleType > Class Template Reference

#include <compressor.hpp>

Classes

struct  Params

Public Member Functions

void set_params (const Params &p)
void set_ballistics (CompressorBallistics ballistics) noexcept
 Select how gain reduction is smoothed (see CompressorBallistics).
CompressorBallistics ballistics () const noexcept
void set_sample_rate (SampleType sr)
void set_sidechain_hpf_hz (SampleType hz)
 Set the sidechain high-pass cutoff (Hz).
SampleType sidechain_hpf_hz () const
void set_lookahead_ms (SampleType ms)
 Set the lookahead in milliseconds.
SampleType lookahead_ms () const
int latency_samples () const
 Latency reported to the host = lookahead in samples (0 when off).
SampleType process (SampleType input)
 Process one sample.
SampleType process_with_sidechain (SampleType input, SampleType sidechain)
 Process one sample with an explicit sidechain detector input.
void process (SampleType *buffer, int num_samples)
 Process a block in place; the buffer is also the sidechain.
void process_with_sidechain (SampleType *buffer, const SampleType *sidechain, int num_samples)
 Process a block with a separate sidechain input.
SampleType attack_coefficient () const
 Envelope smoothing coefficients in force for the current parameters and sample rate: the per-sample step toward a lower (attack) or higher (release) gain target is coefficient * (target_db - envelope_db).
SampleType release_coefficient () const
SampleType gain_reduction_db () const
GainReduction gain_reduction () const noexcept
 Canonical non-negative gain-reduction magnitude for shared meters.
void reset ()

Static Public Member Functions

static SampleType detector_level_db (SampleType detector)
 Detector level in dB for one sample: 20 log10(|x|), floored at -200 dB.
static SampleType gain_computer_db (SampleType input_db, const Params &params)
 The static curve: gain change in dB (<= 0) for a detector level in dB under params (threshold, ratio and knee; attack, release and makeup do not enter).
static SampleType ballistic_coefficient (SampleType time_ms, SampleType sample_rate)
 One-pole smoothing coefficient for a time constant in ms: 1 - exp(-1 / (tau fs)), or 1 (instant) for a non-positive time.
static SampleType branching_step (SampleType envelope, SampleType target, SampleType attack, SampleType release)
 One step of the branching ballistics: the envelope (gain change in dB) moves toward target with the attack coefficient when more reduction is asked for and the release coefficient otherwise.
static SampleType decoupled_hold (SampleType hold, SampleType target, SampleType release)
 The decoupled ballistics' peak hold on gain changes (<= 0 dB): it jumps to any deeper reduction at once and otherwise decays toward the target with the release coefficient (Giannoulis et al.
static SampleType db_to_gain (SampleType db)
 Linear gain for a gain change in dB (FastMath for float).

Member Function Documentation

◆ attack_coefficient()

template<typename SampleType = float>
SampleType pulp::signal::CompressorT< SampleType >::attack_coefficient ( ) const
inline

Envelope smoothing coefficients in force for the current parameters and sample rate: the per-sample step toward a lower (attack) or higher (release) gain target is coefficient * (target_db - envelope_db).

◆ ballistic_coefficient()

template<typename SampleType = float>
SampleType pulp::signal::CompressorT< SampleType >::ballistic_coefficient ( SampleType time_ms,
SampleType sample_rate )
inlinestatic

One-pole smoothing coefficient for a time constant in ms: 1 - exp(-1 / (tau fs)), or 1 (instant) for a non-positive time.

◆ ballistics()

template<typename SampleType = float>
CompressorBallistics pulp::signal::CompressorT< SampleType >::ballistics ( ) const
inlinenoexcept

◆ branching_step()

template<typename SampleType = float>
SampleType pulp::signal::CompressorT< SampleType >::branching_step ( SampleType envelope,
SampleType target,
SampleType attack,
SampleType release )
inlinestatic

One step of the branching ballistics: the envelope (gain change in dB) moves toward target with the attack coefficient when more reduction is asked for and the release coefficient otherwise.

◆ db_to_gain()

template<typename SampleType = float>
SampleType pulp::signal::CompressorT< SampleType >::db_to_gain ( SampleType db)
inlinestatic

Linear gain for a gain change in dB (FastMath for float).

◆ decoupled_hold()

template<typename SampleType = float>
SampleType pulp::signal::CompressorT< SampleType >::decoupled_hold ( SampleType hold,
SampleType target,
SampleType release )
inlinestatic

The decoupled ballistics' peak hold on gain changes (<= 0 dB): it jumps to any deeper reduction at once and otherwise decays toward the target with the release coefficient (Giannoulis et al.

's y1 = max(x, aR y1 + (1 - aR) x) with the sign flipped). The envelope then follows the hold: envelope + attack * (hold - envelope).

◆ detector_level_db()

template<typename SampleType = float>
SampleType pulp::signal::CompressorT< SampleType >::detector_level_db ( SampleType detector)
inlinestatic

Detector level in dB for one sample: 20 log10(|x|), floored at -200 dB.

Float uses FastMath's branch-free conversion.

◆ gain_computer_db()

template<typename SampleType = float>
SampleType pulp::signal::CompressorT< SampleType >::gain_computer_db ( SampleType input_db,
const Params & params )
inlinestatic

The static curve: gain change in dB (<= 0) for a detector level in dB under params (threshold, ratio and knee; attack, release and makeup do not enter).

Written as selects over precomputed candidates so the block path's static-curve pass vectorizes.

◆ gain_reduction()

template<typename SampleType = float>
GainReduction pulp::signal::CompressorT< SampleType >::gain_reduction ( ) const
inlinenoexcept

Canonical non-negative gain-reduction magnitude for shared meters.

◆ gain_reduction_db()

template<typename SampleType = float>
SampleType pulp::signal::CompressorT< SampleType >::gain_reduction_db ( ) const
inline

◆ latency_samples()

template<typename SampleType = float>
int pulp::signal::CompressorT< SampleType >::latency_samples ( ) const
inline

Latency reported to the host = lookahead in samples (0 when off).

◆ lookahead_ms()

template<typename SampleType = float>
SampleType pulp::signal::CompressorT< SampleType >::lookahead_ms ( ) const
inline

◆ process() [1/2]

template<typename SampleType = float>
void pulp::signal::CompressorT< SampleType >::process ( SampleType * buffer,
int num_samples )
inline

Process a block in place; the buffer is also the sidechain.

Same as process_with_sidechain(buffer, buffer, num_samples).

◆ process() [2/2]

template<typename SampleType = float>
SampleType pulp::signal::CompressorT< SampleType >::process ( SampleType input)
inline

Process one sample.

The sidechain signal defaults to input, matching the original non-sidechain behavior.

◆ process_with_sidechain() [1/2]

template<typename SampleType = float>
void pulp::signal::CompressorT< SampleType >::process_with_sidechain ( SampleType * buffer,
const SampleType * sidechain,
int num_samples )
inline

Process a block with a separate sidechain input.

Both buffers must be at least num_samples long.

Equivalent to calling process_with_sidechain(SampleType, SampleType) per sample, including the reset at a non-finite sample, but run in kSnapChunkSamples chunks of three passes each (detector and static curve, envelope recursion, gain), so the transcendental work in the outer passes vectorizes. The float path computes the same values; the envelope's denormal snap runs once per chunk (see run_chunks()).

◆ process_with_sidechain() [2/2]

template<typename SampleType = float>
SampleType pulp::signal::CompressorT< SampleType >::process_with_sidechain ( SampleType input,
SampleType sidechain )
inline

Process one sample with an explicit sidechain detector input.

sidechain is the signal that drives the envelope follower; input is the signal that gets the gain applied.

◆ release_coefficient()

template<typename SampleType = float>
SampleType pulp::signal::CompressorT< SampleType >::release_coefficient ( ) const
inline

◆ reset()

template<typename SampleType = float>
void pulp::signal::CompressorT< SampleType >::reset ( )
inline

◆ set_ballistics()

template<typename SampleType = float>
void pulp::signal::CompressorT< SampleType >::set_ballistics ( CompressorBallistics ballistics)
inlinenoexcept

Select how gain reduction is smoothed (see CompressorBallistics).

Takes effect from the next sample; the detector state carries over.

◆ set_lookahead_ms()

template<typename SampleType = float>
void pulp::signal::CompressorT< SampleType >::set_lookahead_ms ( SampleType ms)
inline

Set the lookahead in milliseconds.

The dry input is delayed by this amount so the envelope follower can react before the transient arrives. 0 disables lookahead (default). Maximum supported lookahead is 50 ms — beyond that the internal ring buffer is too large for low-latency contexts.

◆ set_params()

template<typename SampleType = float>
void pulp::signal::CompressorT< SampleType >::set_params ( const Params & p)
inline

◆ set_sample_rate()

template<typename SampleType = float>
void pulp::signal::CompressorT< SampleType >::set_sample_rate ( SampleType sr)
inline

◆ set_sidechain_hpf_hz()

template<typename SampleType = float>
void pulp::signal::CompressorT< SampleType >::set_sidechain_hpf_hz ( SampleType hz)
inline

Set the sidechain high-pass cutoff (Hz).

0 disables the HPF and the sidechain detector sees the raw signal. Typical values: 80–200 Hz for "duck on bass" prevention. The filter is a second-order Butterworth biquad (Q ≈ 0.707).

◆ sidechain_hpf_hz()

template<typename SampleType = float>
SampleType pulp::signal::CompressorT< SampleType >::sidechain_hpf_hz ( ) const
inline

The documentation for this class was generated from the following file:
  • /home/runner/work/pulp/pulp/core/signal/include/pulp/signal/compressor.hpp