Skip to content

Instantly share code, notes, and snippets.

@jpcima
Created May 15, 2021 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpcima/ae30413e1eedd9cbd58b4c5604d13611 to your computer and use it in GitHub Desktop.
Save jpcima/ae30413e1eedd9cbd58b4c5604d13611 to your computer and use it in GitHub Desktop.
Linear smoother
import("stdfaust.lib");
// slewRate: a slew rate limiter
// - rate: maximum variation allowed in the time frame of a second (positive)
slewRate(rate) = next with {
next(x) = y letrec {
'y = y+step(rate/ma.SR,x-y);
}
with {
step(r, dy) = abs(dy) : min(r) : *(ba.if(dy>0,1,-1));
};
};
// linSmooth: a linear smoother
// - t: time to converge to the final value
linSmooth(t) = next with {
next(x) = y letrec {
'y = x : slewRate(r);
'r = ba.if(rch, abs((y-x)/dt), r);
}
letrec {
'dt = ba.if(rch, t, max(0,dt-1.0/ma.SR));
}
with {
rch = (x!=x')|(t!=t');
};
};
process = (value : linSmooth(smoothTime)),
(value : si.smooth(ba.tau2pole(smoothTime/6.91)))
with {
value = hslider("[1] value", 0.0, -1.0, 1.0, 0.001);
smoothTime = hslider("[2] smooth time (ms)", 100, 0, 500, 1) : *(1e-3);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment