bool32 gate
frac32 A1
frac32 A2
frac32 A3
frac32 D1
frac32 D2
frac32 D3
frac32 R1
frac32 R2
frac32 R3
frac32.positive output
frac32.u.map SLvl
frac32.s.map.klineartime.exp ATim
frac32.s.map.klineartime.exp DTim
frac32.s.map.klineartime.exp RTim
int32_t Agate;
int32_t Dgate;
int32_t Rgate;
int32_t val;
int32_t RAval;
int32_t RDval;
int32_t Aval;
int32_t Dval;
int32_t Rval;
int32_t DLvl;
int32_t RLvl;
int32_t RRval;
int32_t t;
int32_t AOval;
int32_t DOval;
int32_t ROval;
int32_t RRel;
int32_t Rdel;
int32_t Adel;
int32_t Agate = 0;
int32_t Dgate = 0;
int32_t Rgate = 0;
Aval = 0;
// ATTACK
Agate = inlet_gate;
if ((Agate > 0) & (ROval > 0)) {
Aval = ___SMMUL(ROval << 3, RRval << 2);
}
MTOF(-param_ATim, t);
if ((Agate > 0) & (Aval < ((1 << 27) - 1 - (t >> 7)))) {
Aval = Aval + (t >> 7);
RAval = Aval;
} else {
if (Agate > 0) {
Aval = (1 << 27);
Dgate = (1 << 27);
RAval = Aval;
} else {
RAval = Aval;
Aval = 0;
}
}
// BEZIER ATTACK
{
int(x1) = RAval;
int(y1) = ((1 << 27) - RAval);
int p0 = 0;
int p1 = inlet_A1;
int p2 = inlet_A2;
int p3 = inlet_A3;
int p4 = (1 << 27);
int x2 = ___SMMUL(x1 << 3, x1 << 2);
int x3 = ___SMMUL(x2 << 3, x1 << 2);
int x4 = ___SMMUL(x3 << 3, x1 << 2);
int y2 = ___SMMUL(y1 << 3, y1 << 2);
int y3 = ___SMMUL(y2 << 3, y1 << 2);
int y4 = ___SMMUL(y3 << 3, y1 << 2);
int a = ___SMMUL(y4 << 3, p0 << 2);
int b = ___SMMUL(x1 << 4, ___SMMUL(y3 << 3, p1 << 2) << 1) * 4;
int c = ___SMMUL(x2 << 4, ___SMMUL(y2 << 3, p2 << 2) << 1) * 6;
int d = ___SMMUL(x3 << 4, ___SMMUL(y1 << 3, p3 << 2) << 1) * 4;
int e = ___SMMUL(x4 << 3, p4 << 2);
int f = AOval = a + b + c + d + e;
// SUSTAIN
DLvl = (AOval)-param_SLvl;
if (Agate == 0) {
Dgate = 0;
}
// DECAY
MTOF(-param_DTim, t);
if ((Dgate > 0) & (Dval < ((1 << 27) - 1 - (t >> 7)))) {
Dval = Dval + (t >> 7);
RDval = Dval;
} else {
if ((Dgate > 0) & (Dval > ((1 << 27) - 1 - (t >> 7)))) {
Dval = (1 << 27);
RDval = Dval;
} else if (Dgate == 0) {
RDval = Dval;
Dval = 0;
}
}
// BEZIER DECAY
{
int(x1) = RDval;
int(y1) = ((1 << 27) - RDval);
int p0 = 0;
int p1 = inlet_D1;
int p2 = inlet_D2;
int p3 = inlet_D3;
int p4 = (1 << 27);
int x2 = ___SMMUL(x1 << 3, x1 << 2);
int x3 = ___SMMUL(x2 << 3, x1 << 2);
int x4 = ___SMMUL(x3 << 3, x1 << 2);
int y2 = ___SMMUL(y1 << 3, y1 << 2);
int y3 = ___SMMUL(y2 << 3, y1 << 2);
int y4 = ___SMMUL(y3 << 3, y1 << 2);
int a = ___SMMUL(y4 << 3, p0 << 2);
int b = ___SMMUL(x1 << 4, ___SMMUL(y3 << 3, p1 << 2) << 1) * 4;
int c = ___SMMUL(x2 << 4, ___SMMUL(y2 << 3, p2 << 2) << 1) * 6;
int d = ___SMMUL(x3 << 4, ___SMMUL(y1 << 3, p3 << 2) << 1) * 4;
int e = ___SMMUL(x4 << 3, p4 << 2);
int f = DOval = a + b + c + d + e;
}
RDval = ___SMMUL(DOval << 3, DLvl << 2);
// RELEASE
if ((Agate == 0) & (((AOval) - (RDval)) > 0)) {
Rval = ((1 << 27));
RRval = (AOval) - (RDval);
}
if (!((Agate == 0) & (((AOval) - (RDval)) > 0))) {
MTOF(-param_RTim, t);
if ((Agate == 0) & ((Rval - (t >> 7)) > 0)) {
Rval = Rval - (t >> 7);
} else {
Rval = 0;
}
}
RRel = Rdel;
Rdel = Rval;
}
// BEZIER RELEASE
{
int(x1) = RRel;
int(y1) = ((1 << 27) - RRel);
int p0 = 0;
int p1 = (1 << 27) - inlet_R3;
int p2 = (1 << 27) - inlet_R2;
int p3 = (1 << 27) - inlet_R1;
int p4 = (1 << 27);
int x2 = ___SMMUL(x1 << 3, x1 << 2);
int x3 = ___SMMUL(x2 << 3, x1 << 2);
int x4 = ___SMMUL(x3 << 3, x1 << 2);
int y2 = ___SMMUL(y1 << 3, y1 << 2);
int y3 = ___SMMUL(y2 << 3, y1 << 2);
int y4 = ___SMMUL(y3 << 3, y1 << 2);
int a = ___SMMUL(y4 << 3, p0 << 2);
int b = ___SMMUL(x1 << 4, ___SMMUL(y3 << 3, p1 << 2) << 1) * 4;
int c = ___SMMUL(x2 << 4, ___SMMUL(y2 << 3, p2 << 2) << 1) * 6;
int d = ___SMMUL(x3 << 4, ___SMMUL(y1 << 3, p3 << 2) << 1) * 4;
int e = ___SMMUL(x4 << 3, p4 << 2);
int f = ROval = a + b + c + d + e;
}
if (Agate > 0) {
ROval = 0;
}
// OUTCOME
outlet_out =
(AOval)-___SMMUL(DOval << 3, DLvl << 2) + ___SMMUL(ROval << 3, RRval << 2);
Adel = Agate;