limiter st

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

Inlets

frac32buffer audio input

frac32buffer inR

frac32 gain input

Outlets

frac32buffer outL

frac32buffer outR

frac32buffer unprocL

frac32buffer unprocR

bool32 active

Declaration
float dL[32], dR[32];
int cd = 0;

float gain, ampL, ampR, scomp;
Init
gain = ampL = ampR = scomp = 0;
for (int i = 0; i < 32; i++) {
  dL[i] = dR[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_inL, 27) * gain;
  // short delay line
  dL[cd] = x;
  // input
  float ax = fabsf(1.1f * x); // the 1.1f factor is a margin
  // amplitude detector
  ampL = ax > ampL ? ax : ampL + 0.001f * (ax - ampL);
}
{
  float x = arm::q_to_float(inlet_inR, 27) * gain;
  // short delay line
  dR[cd] = x;
  // input
  float ax = fabsf(1.1f * x); // the 1.1f factor is a margin
  // amplitude detector
  ampR = ax > ampR ? ax : ampR + 0.001f * (ax - ampR);
}
cd--;
cd &= 15;

float comp = ampL > ampR ? ampL : ampR;
comp = comp <= 1.0f ? 1.0f : 1.0f / comp;

// 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_outL = arm::float_to_q(scomp * dL[cd], 27);
outlet_outR = arm::float_to_q(scomp * dR[cd], 27);
outlet_unprocL = arm::float_to_q(dL[cd], 27);
outlet_unprocR = arm::float_to_q(dR[cd], 27);

Privacy

© 2024 Zrna Research