2 declare name "karplus -- Karplus-Strong string synth";
3 declare author "Yann Orlarey";
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 freq = nentry("freq", 440, 20, 20000, 1); // Hz
20 gain = nentry("gain", 1, 0, 10, 0.01); // %
21 gate = button("gate"); // 0/1
25 upfront(x) = (x-x') > 0.0;
26 decay(n,x) = x - (x>0)/n;
27 release(n) = + ~ decay(n);
28 trigger(n) = upfront : release(n) : >(0.0) : +(leak);
29 leak = 1.0/65536.0; // avoid denormals on Pentium
30 excitator = trigger(size);
34 average(x) = (x+x')/2;
35 att(d,t) = 1-1/pow(db2linear(60), d/(SR*t));
36 comb(d,a) = (+ : fdelay(4096, d-1.5)) ~ (average : *(1.0-a));
37 resonator(d) = comb(d,att(d,dtime));
39 /* DC blocker (see http://ccrma.stanford.edu/~jos/filters/DC_Blocker.html): */
41 dcblocker(x) = (x-x') : (+ ~ *(0.995));
43 /* Karplus-Strong string synthesizer: */
45 process = vgroup("1-excitator", noise*gain : *(gate : excitator))
46 : vgroup("2-resonator", resonator(SR/freq)) : dcblocker
47 : vgroup("3-master", *(vol) : panner(pan));