bc31dac10e3cd493ac2fc72dde1fcb63039a6c57
[Faustine.git] / interpretor / preprocessor / faust-0.9.47mr3 / examples / faust-stk / NLFfm.dsp
1 declare name "NLFfm";
2 declare description "FM synthesizer implemented with a nonlinear passive allpass filter";
3 declare author "Romain Michon";
4 declare copyright "Romain Michon (rmichon@ccrma.stanford.edu)";
5 declare version "1.0";
6
7 import("instrument.lib");
8 import("music.lib");
9
10 //==================== GUI SPECIFICATION ================
11
12 freq = nentry("h:Basic_Parameters/freq [1][unit:Hz] [tooltip:Tone frequency]",440,20,20000,1);
13 gain = nentry("h:Basic_Parameters/gain [1][tooltip:Gain (value between 0 and 1)]",0.8,0,1,0.01);
14 gate = button("h:Basic_Parameters/gate [1][tooltip:noteOn = 1, noteOff = 0]");
15
16 typeModulation = nentry("h:Physical_and_Nonlinearity/v:Nonlinear_Filter_Parameters/Modulation_Type
17 [2][tooltip: 0=theta is modulated by the incoming signal; 1=theta is modulated by the averaged incoming signal;
18 2=theta is modulated by the squared incoming signal; 3=theta is modulated by a sine wave of frequency freqMod;
19 4=theta is modulated by a sine wave of frequency freq;]",0,0,4,1);
20 nonLinearity = hslider("h:Physical_and_Nonlinearity/v:Nonlinear_Filter_Parameters/Nonlinearity
21 [2][tooltip:Nonlinearity factor (value between 0 and 1)]",0,0,1,0.01);
22 frequencyMod = hslider("h:Physical_and_Nonlinearity/v:Nonlinear_Filter_Parameters/Modulation_Frequency
23 [2][unit:Hz][tooltip:Frequency of the sine wave for the modulation of theta (works if Modulation Type=3)]",220,20,1000,0.1);
24 nonLinAttack = hslider("h:Physical_and_Nonlinearity/v:Nonlinear_Filter_Parameters/Nonlinearity_Attack
25 [2][unit:s][Attack duration of the nonlinearity]",0.1,0,2,0.01);
26
27 vibratoFreq = hslider("h:Envelopes_and_Vibrato/v:Vibrato_Parameters/Vibrato_Freq
28 [3][unit:Hz]",5,1,15,0.1);
29 vibratoGain = hslider("h:Envelopes_and_Vibrato/v:Vibrato_Parameters/Vibrato_Gain
30 [3][tooltip:A value between 0 and 1]",0.1,0,1,0.01);
31 vibratoAttack = hslider("h:Envelopes_and_Vibrato/v:Vibrato_Parameters/Vibrato_Attack
32 [3][unit:s][tooltip:Vibrato attack duration]",0.5,0,2,0.01);
33 vibratoRelease = hslider("h:Envelopes_and_Vibrato/v:Vibrato_Parameters/Vibrato_Release
34 [3][unit:s][tooltip:Vibrato release duration]",0.01,0,2,0.01);
35
36 envelopeAttack = hslider("h:Envelopes_and_Vibrato/v:Envelope_Parameters/Envelope_Attack
37 [4][unit:s][tooltip:Envelope attack duration]",0.05,0,2,0.01);
38 envelopeDecay = hslider("h:Envelopes_and_Vibrato/v:Envelope_Parameters/Envelope_Decay
39 [4][unit:s][tooltip:Envelope decay duration]",0.05,0,2,0.01);
40 envelopeRelease = hslider("h:Envelopes_and_Vibrato/v:Envelope_Parameters/Envelope_Release
41 [4][unit:s][tooltip:Envelope release duration]",0.05,0,2,0.01);
42
43 //----------------------- Nonlinear filter ----------------------------
44 //nonlinearities are created by the nonlinear passive allpass ladder filter declared in filter.lib
45
46 //nonlinear filter order
47 nlfOrder = 3;
48
49 //attack - sustain - release envelope for nonlinearity (declared in instrument.lib)
50 envelopeMod = asr(nonLinAttack,100,envelopeRelease,gate);
51
52 //nonLinearModultor is declared in instrument.lib, it adapts allpassnn from filter.lib
53 //for using it with waveguide instruments
54 NLFM = nonLinearModulator((nonLinearity : smooth(0.999)),envelopeMod,freq,
55 typeModulation,(frequencyMod : smooth(0.999)),nlfOrder);
56
57 //----------------------- Algorithm implementation ----------------------------
58
59 //stereoizer is declared in instrument.lib and implement a stereo spacialisation in function of
60 //the frequency period in number of samples
61 stereo = stereoizer(SR/freq);
62
63 //vibrato gain is controled by envVibrato (declared in instrument.LIB)
64 vibrato = osc(vibratoFreq)*vibratoGain*envVibrato(0.1*2*vibratoAttack,0.9*2*vibratoAttack,100,vibratoRelease,gate);
65
66 //output gain is controled by an adsr envelope
67 envelope = adsr(envelopeAttack,envelopeDecay,90,envelopeRelease,gate)*gain;
68 breath = envelope + envelope*vibrato;
69
70 process = osc(freq)*breath : NLFM : stereo : instrReverb;