frac32buffer inL
frac32buffer inR
frac32buffer outL
frac32buffer outR
frac32.u.map.gain gain
bool32.tgl limiter
frac32.u.map tresh
frac32.u.map soft
frac32.u.map ratio
frac32.u.map.kdecaytime attack
frac32.u.map.kdecaytime decay
bool32 tresh
frac32.vu in
frac32.vu comp
frac32.vu out
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;
accu = 0;
int32_t TRESH = param_tresh + (8 << 21) + 2;
int32_t soft = ___SMMUL(param_tresh << 3, param_soft << 1) + (8 << 21);
int32_t treshlog = frac_log(TRESH - soft);
int32_t Tresh = frac_log(TRESH);
int32_t makeup = ___SMMUL(Tresh, param_gain >> 1);
Tresh = Tresh - treshlog;
float32_t ratio = (float32_t)(1 << 27) / Tresh;
int32_t attack;
int32_t decay;
MTOF((1 << 27) - (param_attack << 1), attack)
MTOF((1 << 27) - (param_decay << 1), decay)
int32_t In = 0;
int32_t OUT = 0;
int32_t OVER = 0;
int32_t tmp = 0;
for (i = 0; i < BUFSIZE; i++) {
tmp = inlet_inL[i] > inlet_inR[i] ? inlet_inL[i] : inlet_inR[i];
tmp = tmp > 0 ? tmp : -tmp;
In = tmp > In ? tmp : In;
tmp = outlet_outL[i] > outlet_outR[i] ? outlet_outL[i] : outlet_outR[i];
tmp = tmp > 0 ? tmp : -tmp;
OUT = tmp > OUT ? tmp : OUT;
tmp = ___SMMUL(over1, ___SMMUL(over2 << 3, param_ratio << 2)) << 5;
tmp = tmp > 0 ? tmp : -tmp;
OVER = tmp > OVER ? tmp : OVER;
}
disp_in = In;
disp_out = OUT >> 6;
disp_comp = OVER;
disp_tresh = over1 > 0 ? 1 : 0;
int32_t iL = inlet_inL;
int32_t iR = inlet_inR;
iL = iL > 0 ? iL : -iL;
iR = iR > 0 ? iR : -iR;
IN = iL > iR ? iL : iR;
if (IN > val) {
if (param_limiter == 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 - treshlog;
over2 = __USAT((over1 >> 1) * ratio, 27);
over1 = over1 - over2 / ratio;
int32_t gain;
if (over1 < 0) {
// gain = 0x80000;
gain = frac_exp(makeup);
} else {
gain = frac_exp(
makeup - (___SMMUL(over1, ___SMMUL(over2 << 3, param_ratio << 2)) << 5));
}
outlet_outL = ___SMMUL(inlet_inL << 3, gain << 10);
outlet_outR = ___SMMUL(inlet_inR << 3, gain << 10);