frac32 in
frac32 Glide
bool32 glideOFF
frac32 out
frac32.u.map glide
int32.hradio mode
int32_t prev;
int32_t follow;
int64_t diff;
int64_t rate;
int32_t glide;
glide = param_glide + inlet_Glide;
glide = glide > (1 << 27) ? (1 << 27) : glide;
glide = glide < 0 ? 0 : glide;
rate = ___SMMUL(glide << 3, glide << 2);
rate = rate << 8;
if (inlet_glideOFF == 0) {
if (param_mode == 0) {
diff = inlet_in - follow;
diff = (diff << 21) / ((1 << 21) + rate);
follow += diff;
outlet_out = follow;
}
if (param_mode == 1) {
if (!(inlet_in == prev)) {
diff = inlet_in - follow;
}
if (diff > 0) {
if (follow > inlet_in) {
diff = 0;
follow = inlet_in;
}
}
if (diff < 0) {
if (follow < inlet_in) {
diff = 0;
follow = inlet_in;
}
}
follow += (diff << 21) / ((1 << 21) + rate);
outlet_out = follow;
prev = inlet_in;
}
if (param_mode == 2) {
if (!(inlet_in == prev)) {
diff = inlet_in - follow;
diff = diff > 0 ? (1 << 27) : -(1 << 27);
}
if (diff > 0) {
if (follow > inlet_in) {
diff = 0;
follow = inlet_in;
}
}
if (diff < 0) {
if (follow < inlet_in) {
diff = 0;
follow = inlet_in;
}
}
follow += (diff << 21) / ((1 << 21) + rate);
outlet_out = follow;
prev = inlet_in;
}
} else {
outlet_out = inlet_in;
}