Revert "Examples Makefile."
[Faustine.git] / interpretor / preprocessor / faust-0.9.47mr3 / examples / faust-stk / uniBar.dsp
1 declare name "UniBar";
2 declare description "Nonlinear Banded Waveguide Models";
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 //==================== MODAL PARAMETERS ================
30
31 preset = 1;
32
33 nMode(1) = 4;
34
35 modes(1,0) = 1;
36 basegains(1,0) = pow(0.9,1);
37 excitation(1,0) = 1*gain/nMode(1);
38
39 modes(1,1) = 2.756;
40 basegains(1,1) = pow(0.9,2);
41 excitation(1,1) = 1*gain/nMode(1);
42
43 modes(1,2) = 5.404;
44 basegains(1,2) = pow(0.9,3);
45 excitation(1,2) = 1*gain/nMode(1);
46
47 modes(1,3) = 8.933;
48 basegains(1,3) = pow(0.9,4);
49 excitation(1,3) = 1*gain/nMode(1);
50
51 //==================== SIGNAL PROCESSING ================
52
53 //----------------------- Synthesis parameters computing and functions declaration ----------------------------
54
55 //the number of modes depends on the preset being used
56 nModes = nMode(preset);
57
58 //bow table parameters
59 tableOffset = 0;
60 tableSlope = 10 - (9*bowPressure);
61
62 delayLengthBase = SR/freq;
63
64 //delay lengths in number of samples
65 delayLength(x) = delayLengthBase/modes(preset,x);
66
67 //delay lines
68 delayLine(x) = delay(4096,delayLength(x));
69
70 //Filter bank: bandpass filters (declared in instrument.lib)
71 radius = 1 - PI*32/SR;
72 bandPassFilter(x) = bandPass(freq*modes(preset,x),radius);
73
74 //Delay lines feedback for bow table lookup control
75 baseGainApp = 0.8999999999999999 + (0.1*baseGain);
76 velocityInputApp = integrationConstant;
77 velocityInput = velocityInputApp + _*baseGainApp,par(i,(nModes-1),(_*baseGainApp)) :> +;
78
79 //Bow velocity is controled by an ADSR envelope
80 maxVelocity = 0.03 + 0.1*gain;
81 bowVelocity = maxVelocity*adsr(0.02,0.005,90,0.01,gate);
82
83 //stereoizer is declared in instrument.lib and implement a stereo spacialisation in function of
84 //the frequency period in number of samples
85 stereo = stereoizer(delayLengthBase);
86
87 //----------------------- Algorithm implementation ----------------------------
88
89 //Bow table lookup (bow is decalred in instrument.lib)
90 bowing = bowVelocity - velocityInput <: *(bow(tableOffset,tableSlope)) : /(nModes);
91
92 //One resonance
93 resonance(x) = + : + (excitation(preset,x)*select) : delayLine(x) : *(basegains(preset,x)) : bandPassFilter(x);
94
95 process =
96 //Bowed Excitation
97 (bowing*((select-1)*-1) <:
98 //nModes resonances with nModes feedbacks for bow table look-up
99 par(i,nModes,(resonance(i)~_)))~par(i,nModes,_) :> + :
100 //Signal Scaling and stereo
101 *(14) : stereo : instrReverb;