b0416ae02c974777341c0a5b9a87ff6eea7cbe32
[Faustine.git] / interpretor / faust-0.9.47mr3 / tools / faust2pd / examples / synth / flanger.dsp
1
2 /* Stereo flanger with feedback. */
3
4 /* This is basically just a chorus with a different kind of LFO (triangle wave
5 instead of sine), smaller delay times (typically 1-10 ms instead of 20-30
6 ms) and (much) larger sweep depth, which makes this unit sound more like a
7 time-varying filter (in fact, that's just what it is), in contrast to the
8 gentle pitch modulation produced by a chorus.
9
10 There's also an additional feedback loop which can be used to produce
11 metallic sounds, and a stereo control which allows you to change the
12 stereo spread (a.k.a. phase difference between left and right LFO).
13
14 Note that you can actually make this unit sound pretty much like a chorus
15 by cranking up the delay time while setting the feedback to zero and
16 reducing level and depth (the latter by at least an order of magnitude). */
17
18 declare name "flanger -- stereo flanger with feedback";
19 declare author "Albert Graef";
20 declare version "1.0";
21
22 import("music.lib");
23
24 level = hslider("level", 1, 0, 1, 0.01);
25 freq = hslider("freq", 2, 0, 10, 0.01);
26 dtime = hslider("delay", 0.002, 0, 0.04, 0.001);
27 depth = hslider("depth", 0.5, 0, 1, 0.001);
28 feedback = hslider("feedback", 0.1, 0, 1, 0.001);
29 stereo = hslider("stereo", 1, 0, 1, 0.001);
30
31 tblosc(n,f,freq,mod) = (1-d)*rdtable(n,waveform,i&(n-1)) +
32 d*rdtable(n,waveform,(i+1)&(n-1))
33 with {
34 waveform = time*(2.0*PI)/n : f;
35 phase = freq/SR : (+ : decimal) ~ _;
36 modphase = decimal(phase+mod/(2*PI))*n;
37 i = int(floor(modphase));
38 d = decimal(modphase);
39 };
40
41 triangle(t) = ((0<=t) & (t<=PI))*((2*t-PI)/PI) +
42 ((PI<t) & (t<=2*PI))*((3*PI-2*t)/PI);
43
44 flanger(dtime,freq,level,feedback,depth,phase,x)
45 = (x+(loop(x)*level))/(1+level)
46 with {
47 t = SR*dtime/2*(1+depth*tblosc(1<<16, triangle, freq, phase));
48 loop = (+ : fdelay(1<<16, t)) ~ *(feedback);
49 };
50
51 process = vgroup("flanger", (left, right))
52 with {
53 left = flanger(dtime,freq,level,feedback,depth,0);
54 right = flanger(dtime,freq,level,feedback,depth,stereo*PI);
55 };