Bug fixed for unix error "readlink /proc/self/fd/0" on MacOS.
[Faustine.git] / interpreter / preprocessor / faust-0.9.47mr3 / examples / faust-stk / NLFeks.dsp
1 declare name "Nonlinear EKS";
2 declare author "Julius Smith and Romain Michon";
3 declare version "1.0";
4 declare license "STK-4.3";
5 declare copyright "Julius Smith";
6 declare reference "http://ccrma.stanford.edu/~jos/pasp/vegf.html";
7 // -> Virtual\_Electric\_Guitars\_Faust.html";
8
9 import("music.lib"); // Define SR, delay
10 import("instrument.lib");
11 import("effect.lib"); // stereopanner
12
13 //==================== GUI SPECIFICATION ================
14
15 // standard MIDI voice parameters:
16 // NOTE: The labels MUST be "freq", "gain", and "gate" for faust2pd
17 freq = nentry("freq", 440, 20, 7040, 1); // Hz
18 gain = nentry("gain", 1, 0, 10, 0.01); // 0 to 1
19 gate = button("gate"); // 0 or 1
20
21 // Additional parameters (MIDI "controllers"):
22
23 // Pick angle in [0,0.9]:
24 pickangle = 0.9 * hslider("pick_angle",0,0,0.9,0.1);
25
26 // Normalized pick-position in [0,0.5]:
27 beta = hslider("pick_position [midi: ctrl 0x81]", 0.13, 0.02, 0.5, 0.01);
28 // MIDI Control 0x81 often "highpass filter frequency"
29
30 // String decay time in seconds:
31 t60 = hslider("decaytime_T60", 4, 0, 10, 0.01); // -60db decay time (sec)
32
33 // Normalized brightness in [0,1]:
34 B = hslider("brightness [midi:ctrl 0x74]", 0.5, 0, 1, 0.01);// 0-1
35 // MIDI Controller 0x74 is often "brightness"
36 // (or VCF lowpass cutoff freq)
37
38 // Dynamic level specified as dB level desired at Nyquist limit:
39 L = hslider("dynamic_level", -10, -60, 0, 1) : db2linear;
40 // Note: A lively clavier is obtained by tying L to gain (MIDI velocity).
41
42 //Nonlinear filter parameters
43 typeModulation = nentry("v:Nonlinear Filter/typeMod",0,0,4,1);
44 nonLinearity = hslider("Nonlinearity",0,0,1,0.01) : smooth(0.999);
45 frequencyMod = hslider("freqMod",220,20,1000,0.1) : smooth(0.999);
46
47 //==================== SIGNAL PROCESSING ================
48
49 //----------------------- noiseburst -------------------------
50 // White noise burst (adapted from Faust's karplus.dsp example)
51 // Requires music.lib (for noise)
52 noiseburst(gate,P) = noise : *(gate : trigger(P))
53 with {
54 diffgtz(x) = (x-x') > 0;
55 decay(n,x) = x - (x>0)/n;
56 release(n) = + ~ decay(n);
57 trigger(n) = diffgtz : release(n) : > (0.0);
58 };
59
60 nlfOrder = 6;
61 P = SR/freq ; // fundamental period in samples
62 Pmax = 4096; // maximum P (for delay-line allocation)
63
64 ppdel = beta*P; // pick position delay
65 pickposfilter = ffcombfilter(Pmax,ppdel,-1); // defined in filter.lib
66
67 excitation = noiseburst(gate,P) : *(gain); // defined in signal.lib
68
69 rho = pow(0.001,1.0/(freq*t60)); // multiplies loop-gain
70
71 // Original EKS damping filter:
72 b1 = 0.5*B; b0 = 1.0-b1; // S and 1-S
73 dampingfilter1(x) = rho * ((b0 * x) + (b1 * x'));
74
75 // Linear phase FIR3 damping filter:
76 h0 = (1.0 + B)/2; h1 = (1.0 - B)/4;
77 dampingfilter2(x) = rho * (h0 * x' + h1*(x+x''));
78
79 loopfilter = dampingfilter2; // or dampingfilter1
80
81 filtered_excitation = excitation : smooth(pickangle)
82 : pickposfilter : levelfilter(L,freq); // see filter.lib
83
84 //nonlinear allpass filter (nonLinearModulator is declared in instrument.lib)
85 NLFM = nonLinearModulator(nonLinearity,1,freq,typeModulation,frequencyMod,nlfOrder);
86
87 //declared in instrument.lib
88 stereo = stereoizer(P);
89
90 stringloop = (+ : fdelay4(Pmax, P-2)) ~ (loopfilter : NLFM);
91
92 process = filtered_excitation : stringloop : stereo : instrReverb;