Update readme, install and license files.
[Faustine.git] / interpretor / preprocessor / faust-0.9.47mr3 / examples / faust-stk / flute.dsp
1 declare name "Flute";
2 declare description "Nonlinear WaveGuide Flute";
3 declare author "Romain Michon (rmichon@ccrma.stanford.edu)";
4 declare copyright "Romain Michon";
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 based on Smith algorythm: https://ccrma.stanford.edu/~jos/pasp/Flutes_Recorders_Pipe_Organs.html";
8
9 import("music.lib");
10 import("instrument.lib");
11 import("effect.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]") : int;
18
19 pressure = hslider("h:Physical_and_Nonlinearity/v:Physical_Parameters/Pressure
20 [2][tooltip:Breath pressure (value bewteen 0 and 1)]",0.9,0,1.5,0.01) : smooth(0.999);
21 breathAmp = hslider("h:Physical_and_Nonlinearity/v:Physical_Parameters/Noise Gain
22 [2][tooltip:Breath noise gain (value between 0 and 1)]",0.1,0,1,0.01)/10;
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]",5,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.1,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.1,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.2,0,2,0.01);
45
46 pressureEnvelope = checkbox("h:Envelopes_and_Vibrato/v:Pressure_Envelope_Parameters/Pressure_Env
47 [5][unit:s][tooltip:Activate Pressure envelope]") : int;
48 env1Attack = hslider("h:Envelopes_and_Vibrato/v:Pressure_Envelope_Parameters/Press_Env_Attack
49 [5][unit:s][tooltip:Pressure envelope attack duration]",0.05,0,2,0.01);
50 env1Decay = hslider("h:Envelopes_and_Vibrato/v:Pressure_Envelope_Parameters/Press_Env_Decay
51 [5][unit:s][tooltip:Pressure envelope decay duration]",0.2,0,2,0.01);
52 env1Release = hslider("h:Envelopes_and_Vibrato/v:Pressure_Envelope_Parameters/Press_Env_Release
53 [5][unit:s][tooltip:Pressure envelope release duration]",1,0,2,0.01);
54
55 env2Attack = hslider("h:Envelopes_and_Vibrato/v:Global_Envelope_Parameters/Glob_Env_Attack
56 [6][unit:s][tooltip:Global envelope attack duration]",0.1,0,2,0.01);
57 env2Release = hslider("h:Envelopes_and_Vibrato/v:Global_Envelope_Parameters/Glob_Env_Release
58 [6][unit:s][tooltip:Global envelope release duration]",0.1,0,2,0.01);
59
60 //==================== SIGNAL PROCESSING ================
61
62 //----------------------- Nonlinear filter ----------------------------
63 //nonlinearities are created by the nonlinear passive allpass ladder filter declared in filter.lib
64
65 //nonlinear filter order
66 nlfOrder = 6;
67
68 //attack - sustain - release envelope for nonlinearity (declared in instrument.lib)
69 envelopeMod = asr(nonLinAttack,100,0.1,gate);
70
71 //nonLinearModultor is declared in instrument.lib, it adapts allpassnn from filter.lib
72 //for using it with waveguide instruments
73 NLFM = nonLinearModulator((nonLinearity : smooth(0.999)),envelopeMod,freq,
74 typeModulation,(frequencyMod : smooth(0.999)),nlfOrder);
75
76 //----------------------- Synthesis parameters computing and functions declaration ----------------------------
77
78 //Loops feedbacks gains
79 feedBack1 = 0.4;
80 feedBack2 = 0.4;
81
82 //Delay Lines
83 embouchureDelayLength = (SR/freq)/2-2;
84 boreDelayLength = SR/freq-2;
85 embouchureDelay = fdelay(4096,embouchureDelayLength);
86 boreDelay = fdelay(4096,boreDelayLength);
87
88 //Polinomial
89 poly = _ <: _ - _*_*_;
90
91 //jet filter is a lowwpass filter (declared in filter.lib)
92 reflexionFilter = lowpass(1,2000);
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 //Pressure envelope
101 env1 = adsr(env1Attack,env1Decay,90,env1Release,(gate | pressureEnvelope))*pressure*1.1;
102
103 //Global envelope
104 env2 = asr(env2Attack,100,env2Release,gate)*0.5;
105
106 //Vibrato Envelope
107 vibratoEnvelope = envVibrato(vibratoBegin,vibratoAttack,100,vibratoRelease,gate)*vibratoGain;
108
109 vibrato = osc(vibratoFreq)*vibratoEnvelope;
110
111 breath = noise*env1;
112
113 flow = env1 + breath*breathAmp + vibrato;
114
115 //instrReverb is declared in instrument.lib
116 process = (_ <: (flow + *(feedBack1) : embouchureDelay : poly) + *(feedBack2) : reflexionFilter)~(boreDelay : NLFM) : *(env2)*gain :
117 stereo : instrReverb;