Merge branch 'master' of https://scm.cri.ensmp.fr/git/Faustine
[Faustine.git] / interpretor / preprocessor / faust-0.9.47mr3 / examples / faust-stk / blowBottle.dsp
1 declare name "BlowBottle";
2 declare description "Blown Bottle Instrument";
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 "This object implements a helmholtz resonator (biquad filter) with a polynomial jet excitation (a la Cook).";
8
9 import("math.lib");
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 noiseGain = hslider("h:Physical_and_Nonlinearity/v:Physical_Parameters/Noise_Gain
20 [2][tooltip:Breath noise gain (value between 0 and 1)]",0.5,0,1,0.01)*2;
21 pressure = hslider("h:Physical_and_Nonlinearity/v:Physical_Parameters/Pressure
22 [2][tooltip:Breath pressure (value bewteen 0 and 1)]",1,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]",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.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.01,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.5,0,2,0.01);
52
53
54 //==================== SIGNAL PROCESSING ================
55
56 //----------------------- Nonlinear filter ----------------------------
57 //nonlinearities are created by the nonlinear passive allpass ladder filter declared in filter.lib
58
59 //nonlinear filter order
60 nlfOrder = 6;
61
62 //attack - sustain - release envelope for nonlinearity (declared in instrument.lib)
63 envelopeMod = asr(nonLinAttack,100,envelopeRelease,gate);
64
65 //nonLinearModultor is declared in instrument.lib, it adapts allpassnn from filter.lib
66 //for using it with waveguide instruments
67 NLFM = nonLinearModulator((nonLinearity : smooth(0.999)),envelopeMod,freq,
68 typeModulation,(frequencyMod : smooth(0.999)),nlfOrder);
69
70 //----------------------- Synthesis parameters computing and functions declaration ----------------------------
71
72 //botlle radius
73 bottleRadius = 0.999;
74
75 //stereoizer is declared in instrument.lib and implement a stereo spacialisation in function of
76 //the frequency period in number of samples
77 stereo = stereoizer(SR/freq);
78
79 bandPassFilter = bandPass(freq,bottleRadius);
80
81 //----------------------- Algorithm implementation ----------------------------
82
83 //global envelope is of type attack - decay - sustain - release
84 envelopeG = gain*adsr(gain*envelopeAttack,envelopeDecay,80,envelopeRelease,gate);
85
86 //pressure envelope is also ADSR
87 envelope = pressure*adsr(gain*0.02,0.01,80,gain*0.2,gate);
88
89 //vibrato
90 vibrato = osc(vibratoFreq)*vibratoGain*envVibrato(vibratoBegin,vibratoAttack,100,vibratoRelease,gate)*osc(vibratoFreq);
91
92 //breat pressure
93 breathPressure = envelope + vibrato;
94
95 //breath noise
96 randPressure = noiseGain*noise*breathPressure ;
97
98 process =
99 //differential pressure
100 (-(breathPressure) <:
101 ((+(1))*randPressure : +(breathPressure)) - *(jetTable),_ : bandPassFilter,_)~NLFM : !,_ :
102 //signal scaling
103 dcblocker*envelopeG*0.5 : stereo : instrReverb;