2 declare name "karplusplus -- Karplus-Strong + Fuzz";
3 declare author "Yann Orlarey, Albert Graef";
10 // master volume and pan
11 vol = hslider("vol", 0.3, 0, 10, 0.01); // %
12 pan = hslider("pan", 0.5, 0, 1, 0.01); // %
14 // excitator and resonator parameters
15 size = hslider("samples", 512, 1, 1024, 1); // #samples
16 dtime = hslider("decay time", 4, 0, 10, 0.01);// -60db decay time
19 drive = hslider("drive", 0, 0, 50, 0.1); // overdrive factor
20 res = hslider("res", 0, 0, 20, 0.1); // filter resonance
21 tone = hslider("tone", 20, 1, 20, 0.1); // filter cutoff harmonic
22 level = hslider("level", 1, 0, 10, 0.01); // output gain (%)
25 freq = nentry("freq", 440, 20, 20000, 1); // Hz
26 gain = nentry("gain", 1, 0, 10, 0.01); // %
27 gate = button("gate"); // 0/1
31 upfront(x) = (x-x') > 0.0;
32 decay(n,x) = x - (x>0)/n;
33 release(n) = + ~ decay(n);
34 trigger(n) = upfront : release(n) : >(0.0) : +(leak);
35 leak = 1.0/65536.0; // avoid denormals on Pentium
36 excitator = trigger(size);
40 average(x) = (x+x')/2;
41 att(d,t) = 1-1/pow(db2linear(60), d/(SR*t));
42 comb(d,a) = (+ : fdelay(4096, d-1.5)) ~ (average : *(1.0-a));
43 resonator(d) = comb(d,att(d,dtime));
45 /* DC blocker (see http://ccrma.stanford.edu/~jos/filters/DC_Blocker.html): */
47 dcblocker(x) = (x-x') : (+ ~ *(0.995));
51 // This is a tweaked Butterworth filter by David Werner and Patrice Tarrabia,
52 // see http://www.musicdsp.org and http://www.experimentalscene.com for
55 // res = resonance in dB above DC gain
56 // freq = cutoff frequency
58 lowpass(res,freq) = f : (+ ~ g) : *(a)
60 f(x) = a0*x+a1*x'+a2*x'';
62 a = 1/db2linear(0.5*res);
64 c = 1.0/tan(PI*(freq/SR));
66 r = 1/db2linear(2.0*res);
68 a0 = 1.0/(1.0+(q*c)+(c2));
77 clip(x) = f*x+1-f with { f = abs(drive*x)<=1; };
78 fuzz(freq) = clip : lowpass(res,tone*freq) : *(level);
80 /* Karplus-Strong string synthesizer: */
82 process = vgroup("1-excitator", noise*gain : *(gate : excitator))
83 : vgroup("2-resonator", resonator(SR/freq)) : dcblocker
84 : vgroup("3-fuzz", fuzz(freq))
85 : vgroup("4-master", *(vol) : panner(pan));