New version name (Version 1.0) for access from the FEEVER website.
[Faustine.git] / interpreter / preprocessor / faust-0.9.47mr3 / tools / faust2pd / examples / basic / karplus.dsp
1
2 declare name "karplus -- Karplus-Strong string synth";
3 declare author "Yann Orlarey";
4 declare version "1.0";
5
6 import("music.lib");
7
8 // control variables
9
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); // %
13
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
17
18 // voice parameters
19 freq = nentry("freq", 440, 20, 20000, 1); // Hz
20 gain = nentry("gain", 1, 0, 10, 0.01); // %
21 gate = button("gate"); // 0/1
22
23 /* The excitator: */
24
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);
31
32 /* The resonator: */
33
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));
38
39 /* DC blocker (see http://ccrma.stanford.edu/~jos/filters/DC_Blocker.html): */
40
41 dcblocker(x) = (x-x') : (+ ~ *(0.995));
42
43 /* Karplus-Strong string synthesizer: */
44
45 process = vgroup("1-excitator", noise*gain : *(gate : excitator))
46 : vgroup("2-resonator", resonator(SR/freq)) : dcblocker
47 : vgroup("3-master", *(vol) : panner(pan));