gitignore update.
[Faustine.git] / interpretor / preprocessor / faust-0.9.47mr3 / examples / faust-stk / brass.dsp
1 declare name "Brass";
2 declare description "WaveGuide Brass instrument from STK";
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 brass instrument waveguide model, a la Cook (TBone, HosePlayer).";
8 declare reference "https://ccrma.stanford.edu/~jos/pasp/Brasses.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 pressure = hslider("h:Physical_and_Nonlinearity/v:Physical_Parameters/Pressure
20 [2][tooltip:A value between 0 and 1]",1,0.01,1,0.01);
21 lipTension = hslider("h:Physical_and_Nonlinearity/v:Physical_Parameters/Lip_Tension
22 [2][tooltip:A value between 0 and 1]",0.780,0.01,1,0.001);
23 slideLength = hslider("h:Physical_and_Nonlinearity/v:Physical_Parameters/Slide_Length
24 [2][tooltip:A value between 0 and 1]",0.041,0.01,1,0.001);
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.005,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.001,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.07,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 //lips are simulated by a biquad filter whose output is squared and hard-clipped, bandPassH and saturationPos are declared in instrument.lib
74 lipFilterFrequency = freq*pow(4,(2*lipTension)-1);
75 lipFilter = *(0.03) : bandPassH(lipFilterFrequency,0.997) <: * : saturationPos;
76
77 //stereoizer is declared in instrument.lib and implement a stereo spacialisation in function of
78 //the frequency period in number of samples
79 stereo = stereoizer(SR/freq);
80
81 //delay times in number of samples
82 slideTarget = ((SR/freq)*2 + 3)*(0.5 + slideLength);
83 boreDelay = fdelay(4096,slideTarget);
84
85 //----------------------- Algorithm implementation ----------------------------
86
87 //vibrato
88 vibrato = vibratoGain*osc(vibratoFreq)*envVibrato(vibratoBegin,vibratoAttack,100,vibratoRelease,gate);
89
90 //envelope (Attack / Decay / Sustain / Release), breath pressure and vibrato
91 breathPressure = pressure*adsr(envelopeAttack,envelopeDecay,100,envelopeRelease,gate) + vibrato;
92 mouthPressure = 0.3*breathPressure;
93
94 //scale the delay feedback
95 borePressure = *(0.85);
96
97 //differencial presure
98 deltaPressure = mouthPressure - _;
99
100 process = (borePressure <: deltaPressure,_ :
101 (lipFilter <: *(mouthPressure),(1-_)),_ : _, * :> + :
102 dcblocker) ~ (boreDelay : NLFM) :
103 *(gain)*4 : stereo : instrReverb;