aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVee9ahd1 <>2021-05-11 15:29:40 -0400
committerVee9ahd1 <>2021-05-11 15:29:40 -0400
commit194676e190b827c6b12318213261d4e47ec7e6aa (patch)
tree37802291ed88fcc79f5e0946d7a283ca345afb12 /src
initial commit
Diffstat (limited to 'src')
-rw-r--r--src/util.dsp26
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);
+};