compressor2

Dynamic range compressor with soft-treshold function, ratio, attack/release and gain.
Author: Remco van der Most
License: BSD
Github: sss/dyn/compressor2.axo

Inlets

frac32buffer in

Outlets

frac32buffer out

Parameters

frac32.u.map.gain gain

bool32.tgl limit

int32 extendA

int32 extendD

frac32.u.map tresh

frac32.u.map ratio

frac32.u.map.kdecaytime attack

frac32.u.map.kdecaytime decay

Displays

frac32.vu in

frac32.vu comp

frac32.vu out

bool32 tresh

Declaration
int32_t frac_log(int32_t a) {
  Float_t f;
  f.f = a;
  // a=a>0?a:-1;
  int32_t r1 = ((f.parts.exponent & 0x7F) - 18) << 24;
  int32_t r3 = logt[f.parts.mantissa >> 15] << 10;
  return r1 + r3;
}

int32_t frac_exp(int32_t a) {
  int8_t s = (a >> 24) + 4;
  uint8_t ei = a >> 16;
  if (s >= 0)
    return expt[ei] << s;
  else
    return expt[ei] >> (-s);
}

int32_t accu;
int32_t prev;
int32_t IN;
int32_t val;
int i;
int32_t over1;
int32_t over2;
Init
accu = 0;
Control Rate
int32_t TRESH = param_tresh + (8 << 21) + 2;
int32_t Tresh = frac_log(TRESH);
float32_t ratio = (float32_t)(1 << 27) / Tresh;
int32_t attack;
int32_t decay;
MTOF((1 << 27) - (param_attack << 1), attack)
attack = attack >> param_extendA;
MTOF((1 << 27) - (param_decay << 1), decay)
decay = decay >> param_extendD;
Audio Rate
IN = inlet_in;
IN = IN > 0 ? IN : -IN;
if (IN > val) {
  if (param_limit == 1) {
    val = IN;
  } else {
    val = ___SMMLA((IN - val) << 1, attack, val);
  }
} else {
  val = ___SMMLA((IN - val) << 1, decay, val);
}

int32_t inlog = frac_log(val);
over1 = (inlog > Tresh ? Tresh : inlog) - inlog;
int32_t gain;
gain = frac_exp((1 << 27) + (___SMMUL(over1, param_ratio) << 7));

int32_t out = ___SMMUL(inlet_in << 3, gain << 2);
outlet_out = out;

Privacy

© 2024 Zrna Research