frac32buffer in
frac32buffer out
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
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 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;
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;