Cleaning the examples' Makefiles and octaves scripts.
[Faustine.git] / interpretor / preprocessor / faust-0.9.47mr3 / examples / faust-stk / bowed.dsp
1 declare name "Bowed";
2 declare description "Nonlinear WaveGuide Bowed Instrument";
3 declare author "Romain Michon";
4 declare copyright "Romain Michon (rmichon@ccrma.stanford.edu)";
5 declare version "1.0";
6 declare licence "STK-4.3"; // Synthesis Tool Kit 4.3 (MIT style license);
7 declare description "A bowed string model, a la Smith (1986), after McIntyre, Schumacher, Woodhouse (1983).";
8 declare reference "https://ccrma.stanford.edu/~jos/pasp/Bowed_Strings.html";
9
10 import("music.lib");
11 import("instrument.lib");
12
13 //==================== GUI SPECIFICATION ================
14
15 freq = nentry("h:Basic_Parameters/freq [1][unit:Hz] [tooltip:Tone frequency]",440,20,20000,1);
16 gain = nentry("h:Basic_Parameters/gain [1][tooltip:Gain (value between 0 and 1)]",1,0,1,0.01);
17 gate = button("h:Basic_Parameters/gate [1][tooltip:noteOn = 1, noteOff = 0]");
18
19 bowPosition = hslider("h:Physical_and_Nonlinearity/v:Physical_Parameters/Bow_Position
20 [2][tooltip:Bow position along the string (value between 0 and 1)]",0.7,0.01,1,0.01);
21 bowPressure = hslider("h:Physical_and_Nonlinearity/v:Physical_Parameters/Bow_Pressure
22 [2][tooltip:Bow pressure on the string (value between 0 and 1)]",0.75,0,1,0.01);
23
24 typeModulation = nentry("h:Physical_and_Nonlinearity/v:Nonlinear_Filter_Parameters/Modulation_Type
25 [3][tooltip: 0=theta is modulated by the incoming signal; 1=theta is modulated by the averaged incoming signal;
26 2=theta is modulated by the squared incoming signal; 3=theta is modulated by a sine wave of frequency freqMod;
27 4=theta is modulated by a sine wave of frequency freq;]",0,0,4,1);
28 nonLinearity = hslider("h:Physical_and_Nonlinearity/v:Nonlinear_Filter_Parameters/Nonlinearity
29 [3][tooltip:Nonlinearity factor (value between 0 and 1)]",0,0,1,0.01);
30 frequencyMod = hslider("h:Physical_and_Nonlinearity/v:Nonlinear_Filter_Parameters/Modulation_Frequency
31 [3][unit:Hz][tooltip:Frequency of the sine wave for the modulation of theta (works if Modulation Type=3)]",220,20,1000,0.1);
32 nonLinAttack = hslider("h:Physical_and_Nonlinearity/v:Nonlinear_Filter_Parameters/Nonlinearity_Attack
33 [3][unit:s][Attack duration of the nonlinearity]",0.1,0,2,0.01);
34
35 vibratoFreq = hslider("h:Envelopes_and_Vibrato/v:Vibrato_Parameters/Vibrato_Freq
36 [4][unit:Hz]",6,1,15,0.1);
37 vibratoGain = hslider("h:Envelopes_and_Vibrato/v:Vibrato_Parameters/Vibrato_Gain
38 [4][tooltip:A value between 0 and 1]",0.01,0,1,0.01);
39 vibratoBegin = hslider("h:Envelopes_and_Vibrato/v:Vibrato_Parameters/Vibrato_Begin
40 [4][unit:s][tooltip:Vibrato silence duration before attack]",0.05,0,2,0.01);
41 vibratoAttack = hslider("h:Envelopes_and_Vibrato/v:Vibrato_Parameters/Vibrato_Attack
42 [4][unit:s][tooltip:Vibrato attack duration]",0.5,0,2,0.01);
43 vibratoRelease = hslider("h:Envelopes_and_Vibrato/v:Vibrato_Parameters/Vibrato_Release
44 [4][unit:s][tooltip:Vibrato release duration]",0.01,0,2,0.01);
45
46 envelopeAttack = hslider("h:Envelopes_and_Vibrato/v:Envelope_Parameters/Envelope_Attack
47 [5][unit:s][tooltip:Envelope attack duration]",0.01,0,2,0.01);
48 envelopeDecay = hslider("h:Envelopes_and_Vibrato/v:Envelope_Parameters/Envelope_Decay
49 [5][unit:s][tooltip:Envelope decay duration]",0.05,0,2,0.01);
50 envelopeRelease = hslider("h:Envelopes_and_Vibrato/v:Envelope_Parameters/Envelope_Release
51 [5][unit:s][tooltip:Envelope release duration]",0.1,0,2,0.01);
52
53 //==================== SIGNAL PROCESSING ================
54
55 //----------------------- Nonlinear filter ----------------------------
56 //nonlinearities are created by the nonlinear passive allpass ladder filter declared in filter.lib
57
58 //nonlinear filter order
59 nlfOrder = 6;
60
61 //attack - sustain - release envelope for nonlinearity (declared in instrument.lib)
62 envelopeMod = asr(nonLinAttack,100,envelopeRelease,gate);
63
64 //nonLinearModultor is declared in instrument.lib, it adapts allpassnn from filter.lib
65 //for using it with waveguide instruments
66 NLFM = nonLinearModulator((nonLinearity : smooth(0.999)),envelopeMod,freq,
67 typeModulation,(frequencyMod : smooth(0.999)),nlfOrder);
68
69 //----------------------- Synthesis parameters computing and functions declaration ----------------------------
70
71 //Parameters for the bow table
72 tableOffset = 0;
73 tableSlope = 5 - (4*bowPressure);
74
75 //the bow table is declared in instrument.lib
76 bowTable = bow(tableOffset,tableSlope);
77
78 //a attack - decay - sustain - release envelope is used
79 envelope = adsr(gain*envelopeAttack,envelopeDecay,90, (1-gain)*envelopeRelease,gate);
80 maxVelocity = 0.03 + (0.2 * gain);
81
82 //Delay lines declaration and vibrato, the length of the two delay lines are evolving propotionally
83 betaRatio = 0.027236 + (0.2*bowPosition);
84 fdelneck = (SR/freq-4)*(1 - betaRatio);
85 vibratoEnvelope = envVibrato(vibratoBegin,vibratoAttack,100,vibratoRelease,gate);
86 vibrato = fdelneck + ((SR/freq - 4)*vibratoGain*vibratoEnvelope*osc(vibratoFreq));
87 neckDelay = fdelay(4096,vibrato);
88 fdelbridge = (SR/freq - 4)*betaRatio;
89 bridgeDelay = delay(4096,fdelbridge);
90
91 //Body Filter: a biquad filter with a normalized pick gain (declared in instrument.lib)
92 bodyFilter = bandPass(500,0.85);
93
94 //String Filter: a lowpass filter (declared in instrument.lib)
95 stringFilter = *(0.95) : -onePole(b0,a1)
96 with{
97 pole = 0.6 - (0.1*22050/SR);
98 gain = 0.95;
99 b0 = 1-pole;
100 a1 = -pole;
101 };
102
103 //stereoizer is declared in instrument.lib and implement a stereo spacialisation in function of
104 //the frequency period in number of samples
105 stereo = stereoizer(SR/freq);
106
107 //----------------------- Algorithm implementation ----------------------------
108
109 bowVelocity = envelope*maxVelocity;
110 instrumentBody(feedBckBridge) = (*(-1) <: +(feedBckBridge),_ : (bowVelocity-_ <: *(bowTable) <: _,_),_ :
111 _, + : +(feedBckBridge),_) ~ (neckDelay) : !,_;
112
113 process = (stringFilter : instrumentBody) ~ (bridgeDelay : NLFM) : bodyFilter(*(0.2)) :
114 _*gain*8 : stereo : instrReverb;