From 194676e190b827c6b12318213261d4e47ec7e6aa Mon Sep 17 00:00:00 2001 From: Vee9ahd1 <> Date: Tue, 11 May 2021 15:29:40 -0400 Subject: initial commit --- src/util.dsp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/util.dsp (limited to 'src/util.dsp') diff --git a/src/util.dsp b/src/util.dsp new file mode 100644 index 0000000..72902d3 --- /dev/null +++ b/src/util.dsp @@ -0,0 +1,26 @@ +import("stdfaust.lib"); + +/* phasor: 0.0 to 1.0 at freq Hz */ +phase(freq) = (+(freq/ma.SR) : _,1.0 : fmod) ~ _; + +/* knee is a piecewise linear mapping + * [0,m) -> [0,0.5) + * and [m,1] -> [0.5,1] */ +knee(c, in) = 0.5*(min(x, m)/m + max(x - m, 0.0)/(1.0 - m)) +with { + x = clamp(0.0, 1.0, in); + m = clamp(0.001, 0.999, c); +}; + +/* simple wave folding */ +fold(x) = 4*(abs(0.25*x + 0.25 - int(0.25*x + 0.25)) - 0.25); + +clamp(m, M) = _ : min(M) : max(m); + +blendthree(value, inA, inB, inC) = + max(-clamped_value, 0.0)*inA + + max(clamped_value, 0.0)*inC + + max(1.0 - abs(clamped_value), 0.0)*inC +with { + clamped_value = value : clamp(-1.0, 1.0); +}; -- cgit v1.2.1