Ignore .o, .a, and .svg files.
[Faustine.git] / interpretor / faust-0.9.47mr3 / examples / faust-stk / bass.dsp
1 declare name "Bass";
2 declare description "Nonlinear WaveGuide Acoustic Bass";
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
8 import("instrument.lib");
9 import("music.lib");
10
11 //==================== GUI SPECIFICATION ================
12
13 freq = nentry("h:Basic_Parameters/freq [1][unit:Hz] [tooltip:Tone frequency]",120,20,20000,1);
14 gain = nentry("h:Basic_Parameters/gain [1][tooltip:Gain (value between 0 and 1)]",1,0,1,0.01);
15 gate = button("h:Basic_Parameters/gate [1][tooltip:noteOn = 1, noteOff = 0]");
16
17 touchLength = hslider("v:Physical_Parameters/Touch_Length
18 [2][tooltip:A value between 0 and 1]",0.15,0,1,0.01)*2;
19
20 typeModulation = nentry("v:Nonlinear_Filter_Parameters/Modulation_Type
21 [3][tooltip: 0=theta is modulated by the incoming signal; 1=theta is modulated by the averaged incoming signal;
22 2=theta is modulated by the squared incoming signal; 3=theta is modulated by a sine wave of frequency freqMod;
23 4=theta is modulated by a sine wave of frequency freq;]",0,0,4,1);
24 nonLinearity = hslider("v:Nonlinear_Filter_Parameters/Nonlinearity
25 [3][tooltip:Nonlinearity factor (value between 0 and 1)]",0,0,1,0.01);
26 frequencyMod = hslider("v:Nonlinear_Filter_Parameters/Modulation_Frequency
27 [3][unit:Hz][tooltip:Frequency of the sine wave for the modulation of theta (works if Modulation Type=3)]",220,20,1000,0.1);
28
29 //==================== SIGNAL PROCESSING ======================
30
31 //----------------------- Nonlinear filter ----------------------------
32 //nonlinearities are created by the nonlinear passive allpass ladder filter declared in filter.lib
33
34 //nonlinear filter order
35 nlfOrder = 6;
36
37 //nonLinearModultor is declared in instrument.lib, it adapts allpassnn from filter.lib
38 //for using it with waveguide instruments
39 NLFM = nonLinearModulator((nonLinearity : smooth(0.999)),1,freq,
40 typeModulation,(frequencyMod : smooth(0.999)),nlfOrder);
41
42 //----------------------- Synthesis parameters computing and functions declaration ----------------------------
43
44 //delay length in number of samples
45 delayLength = float(SR)/freq;
46
47 //stereoizer is declared in instrument.lib and implement a stereo spacialisation in function of
48 //the frequency period in number of samples
49 stereo = stereoizer(delayLength);
50
51 //string excitation
52 excitation = asympT60(-0.5,-0.985,0.02,gate),noise*asympT60(gain,0,touchLength,gate) :
53 onePoleSwep : excitationFilter : excitationFilter
54 with{
55 //the exitation filter is a one pole filter (declared in instrument.lib)
56 excitationFilter = onePole(0.035,-0.965);
57 };
58
59 //the bodyfilter is a bandpass filter (declared in instrument.lib)
60 bodyFilter = bandPass(108,0.997);
61
62 //the reflexion filter is pole zero filter (declared in instrument.lib) whose coefficients are
63 //modulated in function of the tone being played
64 reflexionFilter = poleZero(b0,b1,a1)
65 with{
66 //filter coefficients are stored in a C++ function
67 loopFilterb0 = ffunction(float getValueBassLoopFilterb0(float), <bass.h>,"");
68 loopFilterb1 = ffunction(float getValueBassLoopFilterb1(float), <bass.h>,"");
69 loopFiltera1 = ffunction(float getValueBassLoopFiltera1(float), <bass.h>,"");
70 freqToNoteNumber = (log - log(440))/log(2)*12 + 69 + 0.5 : int;
71 freqn = freq : freqToNoteNumber;
72 b0 = loopFilterb0(freqn);
73 b1 = loopFilterb1(freqn);
74 a1 = loopFiltera1(freqn);
75 };
76
77 delayLine = asympT60(0,delayLength,0.01,gate),_ : fdelay(4096);
78
79 //the resonance duration is different whether a note-on signal is sent or not
80 resonanceGain = gate + (gate < 1 <: *(asympT60(1,0.9,0.05)));
81
82 process = excitation :
83 (+)~(delayLine : NLFM : reflexionFilter*resonanceGain) <:
84 bodyFilter*1.5 + *(0.5) : *(4) : stereo : instrReverb;