Created
May 15, 2021 13:17
-
-
Save jpcima/ae30413e1eedd9cbd58b4c5604d13611 to your computer and use it in GitHub Desktop.
Linear smoother
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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