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); };