Add octave scripts for examples into track list.
[Faustine.git] / interpretor / preprocessor / faust-0.9.47mr3 / examples / faust-stk / flutestk.dsp
1 declare name "FluteSTK";
2 declare description "Nonlinear WaveGuide Flute from STK";
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 flute physical model, as discussed by Karjalainen, Smith, Waryznyk, etc. The jet model uses a polynomial, a la Cook.";
8 declare reference "https://ccrma.stanford.edu/~jos/pasp/Flutes_Recorders_Pipe_Organs.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 embouchureAjust = hslider("h:Physical_and_Nonlinearity/v:Physical_Parameters/Embouchure_Ajust
20 [2][tooltip:A 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:A value between 0 and 1]",0.03,0,1,0.01);
23 pressure = hslider("h:Physical_and_Nonlinearity/v:Physical_Parameters/Pressure
24 [2][tooltip:Breath pressure (value between 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]",6,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.05,0,1,0.01);
41 vibratoBegin = hslider("h:Envelopes_and_Vibrato/v:Vibrato_Parameters/Vibrato_Begin
42 [4][unit:s][tooltip:Vibrato silence duration before attack]",0.05,0,2,0.01);
43 vibratoAttack = hslider("h:Envelopes_and_Vibrato/v:Vibrato_Parameters/Vibrato_Attack
44 [4][unit:s][tooltip:Vibrato attack duration]",0.5,0,2,0.01);
45 vibratoRelease = hslider("h:Envelopes_and_Vibrato/v:Vibrato_Parameters/Vibrato_Release
46 [4][unit:s][tooltip:Vibrato release duration]",0.1,0,2,0.01);
47
48 envelopeAttack = hslider("h:Envelopes_and_Vibrato/v:Envelope_Parameters/Envelope_Attack
49 [5][unit:s][tooltip:Envelope attack duration]",0.03,0,2,0.01);
50 envelopeDecay = hslider("h:Envelopes_and_Vibrato/v:Envelope_Parameters/Envelope_Decay
51 [5][unit:s][tooltip:Envelope decay duration]",0.01,0,2,0.01);
52 envelopeRelease = hslider("h:Envelopes_and_Vibrato/v:Envelope_Parameters/Envelope_Release
53 [5][unit:s][tooltip:Envelope release duration]",0.3,0,2,0.01);
54
55 //==================== SIGNAL PROCESSING ================
56
57 //----------------------- Nonlinear filter ----------------------------
58 //nonlinearities are created by the nonlinear passive allpass ladder filter declared in filter.lib
59
60 //nonlinear filter order
61 nlfOrder = 6;
62
63 //attack - sustain - release envelope for nonlinearity (declared in instrument.lib)
64 envelopeMod = asr(nonLinAttack,100,envelopeRelease,gate);
65
66 //nonLinearModultor is declared in instrument.lib, it adapts allpassnn from filter.lib
67 //for using it with waveguide instruments
68 NLFM = nonLinearModulator((nonLinearity : smooth(0.999)),envelopeMod,freq,
69 typeModulation,(frequencyMod : smooth(0.999)),nlfOrder);
70
71 //----------------------- Synthesis parameters computing and functions declaration ----------------------------
72
73 jetReflexion = 0.5;
74 //jetRatio = 0.08 + (0.48*embouchureAjust); //original stk function
75 jetRatio = 1+(0.5-embouchureAjust); //corrected function
76 endReflexion = 0.5;
77
78 //Delay lines lengths in number of samples
79 //jetDelayLength = (SR/freq-2)*jetRatio; //original stk function for jet delay length
80 jetDelayLength = (SR/(freq*2)-2)*jetRatio; //corrected function for jet delay length
81 boreDelayLength = SR/(freq*2)-2; //original function for bore delay length
82 //boreDelayLength = SR/(freq)-2; //corrected function for bore delay length
83 filterPole = 0.7 - (0.1*22050/SR);
84
85 //One Pole Filter (declared in instrument.lib)
86 onePoleFilter = _*gain : onePole(b0,a1)
87 with{
88 gain = -1;
89 pole = 0.7 - (0.1*22050/SR);
90 b0 = 1 - pole;
91 a1 = -pole;
92 };
93
94 //stereoizer is declared in instrument.lib and implement a stereo spacialisation in function of
95 //the frequency period in number of samples
96 stereo = stereoizer(SR/freq);
97
98 //----------------------- Algorithm implementation ----------------------------
99
100 //the vibrato amplitude is controled by an envelope generator (declared in instrument.lib)
101 vibrato = vibratoGain*envVibrato(vibratoBegin,vibratoAttack,100,vibratoRelease,gate)*osc(vibratoFreq);
102
103 //Breath pressure is controlled by an Attack / Decay / Sustain / Release envelope
104 envelopeBreath = pressure*adsr(pressure*envelopeAttack,envelopeDecay,80,envelopeRelease,gate);
105 breathPressure = envelopeBreath + envelopeBreath*(noiseGain*noise + vibrato) + 10.0^(-15.0);
106
107 //delay lines
108 jetDelay = fdelay(4096,jetDelayLength);
109 boreDelay = fdelay(4096,boreDelayLength);
110
111 //reflexion filter is a one pole and a dcblocker
112 reflexionFilters = onePoleFilter : dcblocker;
113
114 process =
115 (reflexionFilters <:
116 //Differential Pressure
117 ((breathPressure - _*jetReflexion) :
118 jetDelay : jetTable) + (_*endReflexion)) ~ (boreDelay : NLFM) :
119 //output scaling and stereo signal
120 *(0.3*gain) : stereo : instrReverb;
121