diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/util.dsp | 26 |
1 files changed, 26 insertions, 0 deletions
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); +}; |