Class thl::dsp::dynamics::CompressorImpl#

class CompressorImpl : public thl::dsp::BaseProcessor#

Inheritance diagram for thl::dsp::dynamics::CompressorImpl:

digraph { graph [bgcolor="#00000000"] node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2] edge [color="#1414CE"] "2" [label="thl::dsp::BaseProcessor" tooltip="thl::dsp::BaseProcessor"] "1" [label="thl::dsp::dynamics::CompressorImpl" tooltip="thl::dsp::dynamics::CompressorImpl" fillcolor="#BFBFBF"] "1" -> "2" [dir=forward tooltip="public-inheritance"] }

Collaboration diagram for thl::dsp::dynamics::CompressorImpl:

digraph { graph [bgcolor="#00000000"] node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2] edge [color="#1414CE"] "3" [label="std::array< thl::dsp::utils::ParameterRange, NumParameters >" tooltip="std::array< thl::dsp::utils::ParameterRange, NumParameters >"] "2" [label="thl::dsp::BaseProcessor" tooltip="thl::dsp::BaseProcessor"] "1" [label="thl::dsp::dynamics::CompressorImpl" tooltip="thl::dsp::dynamics::CompressorImpl" fillcolor="#BFBFBF"] "4" [label="thl::dsp::utils::ParameterRange" tooltip="thl::dsp::utils::ParameterRange"] "3" -> "4" [dir=forward tooltip="usage"] "1" -> "2" [dir=forward tooltip="public-inheritance"] "1" -> "3" [dir=forward tooltip="usage"] }

A compressor and expander: downward and upward, with lookahead, sidechain and mix.

The key signal (the input, or the sidechain of process_with_sidechain()) passes an optional 12 dB/octave high-pass, its level is detected (LevelDetector: peak or RMS) and linked across the channels (StereoLink), the gain computer (GainComputer) turns it into a gain in dB and the smoother (GainSmoother: attack, hold, release, auto release) gives that gain its ballistics. The audio is delayed by the lookahead, so the gain moves before what it reacts to; latency_samples() is the lookahead (its maximum, k_max_lookahead_ms, is max_latency_samples()).

The output is the delayed input times (1 - mix) + mix · gain · makeup: a mix below 1 is parallel compression, with the dry part inside, delayed as the wet one. The compressor shifts no phase, so process_with_dry() is BaseProcessor’s (the input, undelayed, as its contract says). Auto makeup adds half the gain the curve gives at 0 dBFS, negated, to the makeup.

A derived class gives every Parameter through get_parameter_float(); all are read at the start of every process() call, at modulation_offset (process_modulated() applies them at its change points). A NaN becomes the parameter’s default (k_parameter_ranges), the rest is clamped. Enums come as floats, rounded. Makeup and mix glide over k_ramp_seconds. Up to k_max_channels channels; further ones pass unchanged (delayed by the lookahead).

The meters (any thread) hold the last block’s largest gain change, input and output peak.

Threads: prepare() allocates (audio stopped); process(), process_with_sidechain() and reset() are real-time safe.

Public Functions

virtual void prepare(const double &sample_rate, const size_t &samples_per_block, const size_t &num_channels) override#
virtual void process(thl::core::BufferView buffer, uint32_t modulation_offset = 0) override#
void process_with_sidechain(const thl::core::BufferView &buffer, const thl::core::BufferView &sidechain, uint32_t modulation_offset = 0)#

process() keyed by sidechain instead of the input: its channel c drives channel c (its last channel the ones beyond).

An empty sidechain keys by the input. Same length as buffer.

virtual void reset() override#

Clears the detectors, the gain, the sidechain filter and the lookahead delay; the glides end at their targets.

inline float gain_change_db() const#

The last block’s gain change farthest from 0 dB (negative: reduction), in dB.

inline float input_peak_db() const#

The last block’s input peak in dBFS (the key signal’s, before the high-pass).

inline float output_peak_db() const#

The last block’s output peak in dBFS.

Public Static Attributes

static constexpr size_t k_max_channels = 16#
static constexpr float k_max_lookahead_ms = 20.0f#
static constexpr double k_ramp_seconds = 0.02#
static constexpr float k_max_auto_makeup_db = 24.0f#

Protected Types

enum Parameter#

Values:

enumerator Threshold#

dB

enumerator Ratio#

up to infinity: limits (downward) or gates (expansion)

enumerator Knee#

dB

enumerator Range#

dB, the largest gain change

enumerator Mode#

DynamicsMode.

enumerator Attack#

ms

enumerator Hold#

ms

enumerator Release#

ms

enumerator AutoRelease#

‍0.5 on

enumerator Lookahead#

ms

enumerator Detector#

DetectorMode.

enumerator RmsWindow#

ms

enumerator Link#

StereoLink.

enumerator SidechainHighPass#

Hz; below 10 off, capped at 0.49 fs.

enumerator Makeup#

dB

enumerator AutoMakeup#

‍0.5 on

enumerator Mix#

0 dry to 1 wet

enumerator NumParameters#

Protected Functions

virtual float get_parameter_float(Parameter parameter, uint32_t modulation_offset = 0) = 0#

Protected Static Attributes

static constexpr std::array< utils::ParameterRange, NumParameters > k_parameter_ranges  {{{.m_default = -18.0f, .m_min = -80.0f, .m_max = 0.0f},{.m_default = 4.0f,.m_min = 1.0f,.m_max = std::numeric_limits<float>::infinity()},{.m_default = 6.0f, .m_min = 0.0f, .m_max = 24.0f},{.m_default = 60.0f, .m_min = 0.0f, .m_max = 60.0f},{.m_default = 0.0f, .m_min = 0.0f, .m_max = 3.0f},{.m_default = 10.0f, .m_min = 0.0f, .m_max = 500.0f},{.m_default = 0.0f, .m_min = 0.0f, .m_max = 500.0f},{.m_default = 100.0f, .m_min = 0.0f, .m_max = 5000.0f},{.m_default = 0.0f, .m_min = 0.0f, .m_max = 1.0f},{.m_default = 0.0f, .m_min = 0.0f, .m_max =k_max_lookahead_ms},{.m_default = 0.0f, .m_min = 0.0f, .m_max = 1.0f},{.m_default = 10.0f, .m_min = 0.1f, .m_max = 1000.0f},{.m_default = 0.0f, .m_min = 0.0f, .m_max = 2.0f},{.m_default = 0.0f, .m_min = 0.0f, .m_max = 20000.0f},{.m_default = 0.0f, .m_min = -24.0f, .m_max = 24.0f},{.m_default = 0.0f, .m_min = 0.0f, .m_max = 1.0f},{.m_default = 1.0f, .m_min = 0.0f, .m_max = 1.0f},}}

Every parameter’s default and range (enums: their values as floats), e.g.

for a host’s parameter definitions. A NaN reads as the default, the rest is clamped.