libsndfile-ocaml source files.
[Faustine.git] / interpretor / preprocessor / faust-0.9.47mr3 / examples / faust-stk / tibetanBowl.dsp
1 declare name "Tibetan Bowl";
2 declare description "Banded Waveguide Modeld Tibetan Bowl";
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 "This instrument uses banded waveguide. For more information, see Essl, G. and Cook, P. Banded Waveguides: Towards Physical Modelling of Bar Percussion Instruments, Proceedings of the 1999 International Computer Music Conference.";
8
9 import("music.lib");
10 import("instrument.lib");
11
12 //==================== GUI SPECIFICATION ================
13
14 freq = nentry("h:Basic_Parameters/freq [1][unit:Hz] [tooltip:Tone frequency]",440,20,20000,1);
15 gain = nentry("h:Basic_Parameters/gain [1][tooltip:Gain (value between 0 and 1)]",0.8,0,1,0.01);
16 gate = button("h:Basic_Parameters/gate [1][tooltip:noteOn = 1, noteOff = 0]");
17
18 select = nentry("h:Physical_and_Nonlinearity/v:Physical_Parameters/Excitation_Selector
19 [2][tooltip:0=Bow; 1=Strike]",0,0,1,1);
20 integrationConstant = hslider("h:Physical_and_Nonlinearity/v:Physical_Parameters/Integration_Constant
21 [2][tooltip:A value between 0 and 1]",0,0,1,0.01);
22 baseGain = hslider("h:Physical_and_Nonlinearity/v:Physical_Parameters/Base_Gain
23 [2][tooltip:A value between 0 and 1]",1,0,1,0.01);
24 bowPressure = hslider("h:Physical_and_Nonlinearity/v:Physical_Parameters/Bow_Pressure
25 [2][tooltip:Bow pressure on the instrument (Value between 0 and 1)]",0.2,0,1,0.01);
26 bowPosition = hslider("h:Physical_and_Nonlinearity/v:Physical_Parameters/Bow_Position
27 [2][tooltip:Bow position on the instrument (Value between 0 and 1)]",0,0,1,0.01);
28
29 typeModulation = nentry("h:Physical_and_Nonlinearity/v:Nonlinear_Filter_Parameters/Modulation_Type
30 [3][tooltip: 0=theta is modulated by the incoming signal; 1=theta is modulated by the averaged incoming signal;
31 2=theta is modulated by the squared incoming signal; 3=theta is modulated by a sine wave of frequency freqMod;
32 4=theta is modulated by a sine wave of frequency freq;]",0,0,4,1);
33 nonLinearity = hslider("h:Physical_and_Nonlinearity/v:Nonlinear_Filter_Parameters/Nonlinearity
34 [3][tooltip:Nonlinearity factor (value between 0 and 1)]",0,0,1,0.01);
35 frequencyMod = hslider("h:Physical_and_Nonlinearity/v:Nonlinear_Filter_Parameters/Modulation_Frequency
36 [3][unit:Hz][tooltip:Frequency of the sine wave for the modulation of theta (works if Modulation Type=3)]",220,20,1000,0.1);
37 nonLinAttack = hslider("h:Physical_and_Nonlinearity/v:Nonlinear_Filter_Parameters/Nonlinearity_Attack
38 [3][unit:s][Attack duration of the nonlinearity]",0.1,0,2,0.01);
39
40 //==================== MODAL PARAMETERS ================
41
42 preset = 0;
43
44 nMode(0) = 12;
45
46 modes(0,0) = 0.996108344;
47 basegains(0,0) = 0.999925960128219;
48 excitation(0,0) = 11.900357 / 10;
49
50 modes(0,1) = 1.0038916562;
51 basegains(0,1) = 0.999925960128219;
52 excitation(0,1) = 11.900357 / 10;
53
54 modes(0,2) = 2.979178;
55 basegains(0,2) = 0.999982774366897;
56 excitation(0,2) = 10.914886 / 10;
57
58 modes(0,3) = 2.99329767;
59 basegains(0,3) = 0.999982774366897;
60 excitation(0,3) = 10.914886 / 10;
61
62 modes(0,4) = 5.704452;
63 basegains(0,4) = 1.0;
64 excitation(0,4) = 42.995041 / 10;
65
66 modes(0,5) = 5.704452;
67 basegains(0,5) = 1.0;
68 excitation(0,5) = 42.995041 / 10;
69
70 modes(0,6) = 8.9982;
71 basegains(0,6) = 1.0;
72 excitation(0,6) = 40.063034 / 10;
73
74 modes(0,7) = 9.01549726;
75 basegains(0,7) = 1.0;
76 excitation(0,7) = 40.063034 / 10;
77
78 modes(0,8) = 12.83303;
79 basegains(0,8) = 0.999965497558225;
80 excitation(0,8) = 7.063034 / 10;
81
82 modes(0,9) = 12.807382;
83 basegains(0,9) = 0.999965497558225;
84 excitation(0,9) = 7.063034 / 10;
85
86 modes(0,10) = 17.2808219;
87 basegains(0,10) = 0.9999999999999999999965497558225;
88 excitation(0,10) = 57.063034 / 10;
89
90 modes(0,11) = 21.97602739726;
91 basegains(0,11) = 0.999999999999999965497558225;
92 excitation(0,11) = 57.063034 / 10;
93
94 //==================== SIGNAL PROCESSING ================
95
96 //----------------------- Nonlinear filter ----------------------------
97 //nonlinearities are created by the nonlinear passive allpass ladder filter declared in filter.lib
98
99 //nonlinear filter order
100 nlfOrder = 6;
101
102 //nonLinearModultor is declared in instrument.lib, it adapts allpassnn from filter.lib
103 //for using it with waveguide instruments
104 NLFM = nonLinearModulator((nonLinearity : smooth(0.999)),1,freq,
105 typeModulation,(frequencyMod : smooth(0.999)),nlfOrder);
106
107 //----------------------- Synthesis parameters computing and functions declaration ----------------------------
108
109 //the number of modes depends on the preset being used
110 nModes = nMode(preset);
111
112 //bow table parameters
113 tableOffset = 0;
114 tableSlope = 10 - (9*bowPressure);
115
116 delayLengthBase = SR/freq;
117
118 //delay lengths in number of samples
119 delayLength(x) = delayLengthBase/modes(preset,x);
120
121 //delay lines
122 delayLine(x) = delay(4096,delayLength(x));
123
124 //Filter bank: bandpass filters (declared in instrument.lib)
125 radius = 1 - PI*32/SR;
126 bandPassFilter(x) = bandPass(freq*modes(preset,x),radius);
127
128 //Delay lines feedback for bow table lookup control
129 baseGainApp = 0.8999999999999999 + (0.1*baseGain);
130 velocityInputApp = integrationConstant;
131 velocityInput = velocityInputApp + _*baseGainApp,par(i,(nModes-1),(_*baseGainApp)) :> +;
132
133 //Bow velocity is controled by an ADSR envelope
134 maxVelocity = 0.03 + 0.1*gain;
135 bowVelocity = maxVelocity*adsr(0.02,0.005,90,0.01,gate);
136
137 //stereoizer is declared in instrument.lib and implement a stereo spacialisation in function of
138 //the frequency period in number of samples
139 stereo = stereoizer(delayLengthBase);
140
141 //----------------------- Algorithm implementation ----------------------------
142
143 //Bow table lookup (bow is decalred in instrument.lib)
144 bowing = bowVelocity - velocityInput <: *(bow(tableOffset,tableSlope)) : /(nModes);
145
146 //One resonance
147 resonance(x) = + : + (excitation(preset,x)*select) : delayLine(x) : *(basegains(preset,x)) : bandPassFilter(x);
148
149 process =
150 //Bowed Excitation
151 (bowing*((select-1)*-1) <:
152 //nModes resonances with nModes feedbacks for bow table look-up
153 par(i,nModes,(resonance(i)~_)))~par(i,nModes,_) :> + :
154 //Signal Scaling and stereo
155 NLFM : stereo : instrReverb;