limiter

Author: Smashed Transistors
License: LGPL
Github: tiar/gain/limiter.axo

Inlets

frac32buffer audio input

frac32 gain input

Outlets

bool32 active

frac32buffer output

Declaration
float d[32];
int cd;

float gain, amp, scomp;
Init
gain = amp = scomp = cd = 0;
for (int i = 0; i < 32; i++) {
  d[i] = 0.0f;
}
Control Rate
gain = arm::q_to_float(inlet_gain, 27) * 7.0f + 1.0f;
outlet_active = scomp < 0.99f;
Audio Rate
float x = arm::q_to_float(inlet_in, 27) * gain;

// short delay line
d[cd] = x;
cd--;
cd &= 15;

// input
float ax = fabsf(1.1f * x); // the 1.1f factor is a margin

// amplitude detector
amp = ax > amp ? ax : amp + 0.001f * (ax - amp);

float comp = amp <= 1.0f ? 1.0f : 1.0f / amp;

// smoothed compression to avoid artifacts
scomp += 0.1f * (comp - scomp);

// the delayed output is used (it takes account of
// the delay implied by the smoothed compression factor).

outlet_out = arm::float_to_q(scomp * d[cd], 27);

Privacy

© 2024 Zrna Research