frac32buffer in
frac32buffer sidechain
frac32buffer out
frac32.u.map tresh
frac32.u.map soft
frac32.u.map ratio
frac32.u.map.kdecaytime attack
frac32.u.map.kdecaytime decay
frac32.u.map.gain gain
bool32.tgl sidechain
frac32.vu in
frac32.vu comp
frac32.vu out
bool32 tresh
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 soft = ___SMMUL(param_tresh << 3, param_soft << 1) + (8 << 21);
int32_t treshlog = frac_log(param_tresh - soft);
int32_t Tresh = frac_log(param_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_in[i];
tmp = tmp > 0 ? tmp : -tmp;
In = tmp > In ? tmp : In;
tmp = outlet_out[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;
disp_comp = OVER;
disp_tresh = over1 > 0 ? 1 : 0;
if (param_sidechain == 0) {
IN = inlet_in;
IN = IN > 0 ? IN : -IN;
} else {
int32_t in1 = inlet_in;
in1 = in1 > 0 ? in1 : -in1;
int32_t in2 = inlet_sidechain;
in2 = in2 > 0 ? in2 : -in2;
IN = in1 + in2;
}
if (IN > val) {
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));
}
int32_t out = ___SMMUL(inlet_in << 3, gain << 10);
outlet_out = out;