bool32.rising trigger
frac32.positive main
frac32.positive envelope output
frac32.positive env2
bool32 trg1
bool32 trg2
bool32 n1
bool32 n2
bool32 mn
int32 s1
int32 s2
int32 ms
frac32.s.map.klineartime.exp a
frac32.s.map.klineartime.exp h
frac32.s.map.kdecaytime.exp d
frac32.s.map.kdecaytime.exp r
frac32.u.map.gain s
int8_t stage;
int ntrig;
int32_t val;
int32_t vol;
bool sel;
int32_t hold;
uint32_t v30 = 1 << 30;
int prv;
ntrig = 0;
val = 0;
outlet_trg1 = 0;
outlet_trg2 = 0;
if ((inlet_trig > 0) && !ntrig) {
sel = (sel + 1) & 1;
if (sel == 0) {
outlet_trg1 = 1;
} else {
outlet_trg2 = 1;
}
hold = 0;
uint32_t tmp = vol;
vol = val;
val = tmp;
ntrig = 1;
stage = 1;
} else if (!(inlet_trig > 0)) {
ntrig = 0;
stage = 0;
}
vol = ___SMMUL(vol, param_r) << 1;
if (stage == 0) {
val = ___SMMUL(val, param_r) << 1;
} else if (stage == 3) {
val = param_s + (___SMMUL(val - param_s, param_d) << 1);
} else if (stage == 2) {
int32_t t;
MTOF(-param_h, t);
hold = hold + (t >> 3);
if (hold < 0) {
hold = 0x7FFFFFFF;
stage = 3;
}
} else if (stage == 1) {
int32_t t;
MTOF(-param_a, t);
val = val + (t >> 3);
if (val < 0) {
val = 0x7FFFFFFF;
stage = 2;
}
}
if (sel == 0) {
outlet_env1 = val >> 4;
outlet_env2 = vol >> 4;
outlet_s1 = stage;
outlet_s2 = 0;
outlet_n2 = 0;
outlet_n1 = !(stage == prv) ? 1 : 0;
} else if (sel == 1) {
outlet_env1 = vol >> 4;
outlet_env2 = val >> 4;
outlet_s2 = stage;
outlet_s1 = 0;
outlet_n1 = 0;
outlet_n2 = !(stage == prv);
}
outlet_ms = stage;
outlet_mn = !(stage == prv);
outlet_main = (val > vol ? val : vol) >> 4;
prv = stage;