bool32.rising trigger
frac32.positive envelope output
frac32.s.map.klineartime.exp a
frac32.s.map.klineartime.exp d
frac32.s.map curveA
frac32.s.map curveD
bool32.tgl mode
bool32.tgl gated
int8_t stage;
int ntrig;
int32_t val;
ntrig = 0;
val = 0;
int32_t crv1;
int32_t crv2;
if (param_mode == 0) {
crv1 = param_curveA;
crv2 = param_curveD;
} else {
crv1 = param_curveA + param_curveD;
crv2 = param_curveA - param_curveD;
}
if ((inlet_trig > 0) && !ntrig) {
ntrig = 1;
stage = 1;
} else if (!(inlet_trig > 0)) {
ntrig = 0;
if (param_gated > 0) {
stage = 0;
}
}
int32_t t;
if (stage == 0) {
MTOF(-(param_d << 1) + ___SMMUL(val - (1 << 30), -crv2 << 2), t);
val = __USAT(val - (t >> 3), 31);
} else {
MTOF(-(param_a << 1) + ___SMMUL(val - (1 << 30), -crv1 << 2), t);
val = val + (t >> 3);
if (val < 0) {
val = 0x7FFFFFFF;
stage = 0;
}
}
outlet_env = val >> 4;