From 6a096230227d1acb12756e798a993bbd5e6a14f0 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Sun, 24 Jul 2022 15:00:36 +1000 Subject: [PATCH] soft clipping --- FaustEffect.dsp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/FaustEffect.dsp b/FaustEffect.dsp index 070b3fc..02b0359 100644 --- a/FaustEffect.dsp +++ b/FaustEffect.dsp @@ -3,7 +3,7 @@ import("aanl.lib"); import("maths.lib"); import("basics.lib"); -process = driver : wrapper : aa.hardclip2 : trimmer; +process = driver : wrapper : softclip : aa.hardclip2 : trimmer; driver(x) = x * drive * squeeze; trimmer(x) = x * (1 / squeeze); @@ -17,4 +17,14 @@ squeeze = db2linear(nentry("squeeze", 0, 0, 1, 0.01) * 20) : si.smoo; slider_raw = nentry("clipping", 0, 0, 1, 0.01); slider = (.85*slider_raw)+0.15; fadeamt = min(20*slider_raw, 1); -clipamt = max(ma.EPSILON, (slider^2)*20); \ No newline at end of file +clipamt = max(ma.EPSILON, (slider^2)*20); + +softclip = softclipamt, _ : softclip_maths ; +softclip_maths( a1, x ) = min( a0 , atan((a0 - a1)/a2 ) * a2 + a1 ) * a3 + with{ + a0 = abs(x); + a2 = (1-a1) * 2/ma.PI ; + a3 = ma.signum(x) ; + }; + +softclipamt = db2linear(nentry("softclip", 0, 0, 1, 0.01) * -3) : si.smoo; \ No newline at end of file