Add input csv files of examples to track list.
[Faustine.git] / interpreter / preprocessor / faust-0.9.47mr3 / examples / faust-stk / clarinet.dsp
1 declare name "Clarinet";
2 declare description "Nonlinear WaveGuide Clarinet";
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 simple clarinet physical model, as discussed by Smith (1986), McIntyre, Schumacher, Woodhouse (1983), and others.";
8 declare reference "https://ccrma.stanford.edu/~jos/pasp/Woodwinds.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 reedStiffness = hslider("h:Physical_and_Nonlinearity/v:Physical_Parameters/Reed_Stiffness
20 [2][tooltip:Reed stiffness (value between 0 and 1)]",0.5,0,1,0.01);
21 noiseGain = hslider("h:Physical_and_Nonlinearity/v:Physical_Parameters/Noise_Gain
22 [2][tooltip:Breath noise gain (value between 0 and 1)]",0,0,1,0.01);
23 pressure = hslider("h:Physical_and_Nonlinearity/v:Physical_Parameters/Pressure
24 [2][tooltip:Breath pressure (value bewteen 0 and 1)]",1,0,1,0.01);
25
26 typeModulation = nentry("h:Physical_and_Nonlinearity/v:Nonlinear_Filter_Parameters/Modulation_Type
27 [3][tooltip: 0=theta is modulated by the incoming signal; 1=theta is modulated by the averaged incoming signal;
28 2=theta is modulated by the squared incoming signal; 3=theta is modulated by a sine wave of frequency freqMod;
29 4=theta is modulated by a sine wave of frequency freq;]",0,0,4,1);
30 nonLinearity = hslider("h:Physical_and_Nonlinearity/v:Nonlinear_Filter_Parameters/Nonlinearity
31 [3][tooltip:Nonlinearity factor (value between 0 and 1)]",0,0,1,0.01);
32 frequencyMod = hslider("h:Physical_and_Nonlinearity/v:Nonlinear_Filter_Parameters/Modulation_Frequency
33 [3][unit:Hz][tooltip:Frequency of the sine wave for the modulation of theta (works if Modulation Type=3)]",220,20,1000,0.1);
34 nonLinAttack = hslider("h:Physical_and_Nonlinearity/v:Nonlinear_Filter_Parameters/Nonlinearity_Attack
35 [3][unit:s][Attack duration of the nonlinearity]",0.1,0,2,0.01);
36
37 vibratoFreq = hslider("h:Envelopes_and_Vibrato/v:Vibrato_Parameters/Vibrato_Freq
38 [4][unit:Hz]",5,1,15,0.1);
39 vibratoGain = hslider("h:Envelopes_and_Vibrato/v:Vibrato_Parameters/Vibrato_Gain
40 [4][tooltip:A value between 0 and 1]",0.1,0,1,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 //reed table parameters
72 reedTableOffset = 0.7;
73 reedTableSlope = -0.44 + (0.26*reedStiffness);
74
75 //the reed function is declared in instrument.lib
76 reedTable = reed(reedTableOffset,reedTableSlope);
77
78 //delay line with a length adapted in function of the order of nonlinear filter
79 delayLength = SR/freq*0.5 - 1.5 - (nlfOrder*nonLinearity)*(typeModulation < 2);
80 delayLine = fdelay(4096,delayLength);
81
82 //one zero filter used as a allpass: pole is set to -1
83 filter = oneZero0(0.5,0.5);
84
85 //stereoizer is declared in instrument.lib and implement a stereo spacialisation in function of
86 //the frequency period in number of samples
87 stereo = stereoizer(SR/freq);
88
89 //----------------------- Algorithm implementation ----------------------------
90
91 //Breath pressure + vibrato + breath noise + envelope (Attack / Decay / Sustain / Release)
92 envelope = adsr(envelopeAttack,envelopeDecay,100,envelopeRelease,gate)*pressure*0.9;
93
94 vibrato = osc(vibratoFreq)*vibratoGain*
95 envVibrato(0.1*2*vibratoAttack,0.9*2*vibratoAttack,100,vibratoRelease,gate);
96 breath = envelope + envelope*noise*noiseGain;
97 breathPressure = breath + breath*vibrato;
98
99 process =
100 //Commuted Loss Filtering
101 (_,(breathPressure <: _,_) : (filter*-0.95 - _ <:
102
103 //Non-Linear Scattering
104 *(reedTable)) + _) ~
105
106 //Delay with Feedback
107 (delayLine : NLFM) :
108
109 //scaling and stereo
110 *(gain)*1.5 : stereo : instrReverb;