limiter

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

Inlets

frac32buffer audio input

frac32 gain input

Outlets

frac32buffer output

frac32buffer unprocessed delayed output

bool32 active

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);
outlet_unproc = arm::float_to_q(d[cd], 27);

Privacy

© 2024 Zrna Research