bool32 gate
frac32 sync
frac32 out
int32 stage
int32 division
int32 A
int32 D
int32 R
frac32.s.map S
uint32_t env;
uint32_t count;
uint32_t timer;
int gtrig;
int stage;
int32_t goal;
int strig;
uint32_t rate;
int32_t level;
int32_t prevlevel;
int otrig;
level = 0;
stage = 3;
otrig = 0;
if ((inlet_gate > 0) && !gtrig) {
gtrig = 1;
env = 0;
stage = 1;
goal = (1 << 27);
prevlevel = level;
} else if (!(inlet_gate > 0)) {
gtrig = 0;
}
if ((inlet_gate == 0) && !otrig) {
otrig = 1;
prevlevel = level;
goal = 0;
stage = 0;
env = 0;
} else if (inlet_gate > 0) {
otrig = 0;
}
if ((level == 0) && (stage == 0)) {
stage = 3;
}
if (stage == 1) {
rate = timer * param_division / param_A;
env += rate;
level = ___SMMUL(env >> 1, goal - prevlevel << 1) + prevlevel;
if (param_A == 0) {
stage = 2;
env = 0;
goal = param_S;
prevlevel = level = (1 << 27);
} else if (((env >> 2) + (rate >> 2)) >= (1 << 30) - 1) {
stage = 2;
env = 0;
goal = param_S;
prevlevel = level;
}
}
if (stage == 2) {
rate = timer * param_division / param_D;
env += rate;
level = ___SMMUL(env >> 1, goal - prevlevel << 1) + prevlevel;
if (param_D == 0) {
stage = 3;
env = 0;
goal = 0;
prevlevel = level;
} else if (((env >> 2) + (rate >> 2)) >= (1 << 30) - 1) {
stage = 3;
prevlevel = level;
env = 0;
goal = 0;
}
}
if (stage == 0) {
if (param_R == 0) {
stage = 3;
level = 0;
prevlevel = level;
env = 0;
} else {
rate = timer * param_division / param_R;
env += rate;
level = ___SMMUL(env >> 1, goal - prevlevel << 1) + prevlevel;
if (((env >> 2) + (rate >> 2)) > (1 << 30) - 1) {
stage = 3;
level = 0;
prevlevel = level;
env = 0;
}
}
}
outlet_out = level;
outlet_stage = stage;
if ((inlet_sync > 0) && !strig) {
strig = 1;
timer = ((1 << 31) / (count)) << 4;
count = 0;
} else if (!(inlet_sync > 0)) {
strig = 0;
}
count += 1;