Last active
August 5, 2020 22:36
-
-
Save jpcima/31f4b2abd9bd11057d819f6c23edd566 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import("stdfaust.lib"); | |
disto(depth, tone, x) = x : toneLpf(toneCutoff) : dist : fi.dcblockerat(5.0) with { | |
// low pass filter | |
toneCutoff = 21+tone*1.08; | |
toneLpf(f) = fi.iir((1.-p), (0.-p)) with { p = exp(-2.*ma.PI*f/ma.SR) : si.smoo; }; | |
// distortion | |
dist(x) = shs*hh(x)+(1.0-shs)*lh(x); | |
// sigmoid parameters | |
a = depth*0.2+2.0; | |
b = 2.0; | |
// smooth hysteresis transition | |
shs = hs : si.smooth(ba.tau2pole(10e-3)); | |
// the low and high hysteresis | |
lh(x) = sig(a*x)*b; | |
hh(x) = (sig(a*x)-1.0)*b; | |
// | |
sig10 = environment { // sigmoid sampled from -10 to +10 | |
tablesize = 256; | |
table(i) = rdtable(tablesize, exact(float(ba.time)/float(tablesize)*20.0-10.0), i); | |
exact(x) = exp(x)/(exp(x)+1.0); | |
approx(x) = s1+mu*(s2-s1) with { | |
index = (x+10.0)*(1.0/20.0)*(sig10.tablesize-1) : max(0.0); | |
mu = index-int(index); | |
s1 = sig10.table(int(index) : min(sig10.tablesize-1)); | |
s2 = sig10.table(int(index) : +(1) : min(sig10.tablesize-1)); | |
}; | |
}; | |
//sig = sig10.exact; | |
sig = sig10.approx; | |
} | |
letrec { | |
// hysteresis selection | |
'hs = ba.if((x<x') & (x<-0.25), 1, ba.if((x>x') & (x>0.25), 0, hs)); | |
}; | |
process = _ : *(dry) <: (_, _) : (*(1.0-wet), (disto(d, t) : *(wet))) :> + with { | |
d = hslider("[1] Depth", 100.0, 0.0, 100.0, 0.01); | |
t = hslider("[2] Tone", 100.0, 0.0, 100.0, 0.01); | |
dry = hslider("[3] Dry", 100.0, 0.0, 100.0, 0.01) : *(0.01); | |
wet = hslider("[4] Wet", 100.0, 0.0, 100.0, 0.01) : *(0.01); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment