Initial import.
[Faustine.git] / interpretor / faust-0.9.47mr3 / tools / faust2pd / examples / synth / phasemod.syn
1
2 declare name "phasemod -- phase modulation synth";
3 declare author "Albert Graef";
4 declare version "1.0";
5
6 import("music.lib");
7
8 // control variables
9
10 // master volume and pan
11 vol = hslider("vol", 0.3, 0, 10, 0.01); // %
12 pan = hslider("pan", 0.5, 0, 1, 0.01); // %
13
14 // ADSR envelop
15 attack = hslider("attack", 0.01, 0, 1, 0.001); // sec
16 decay = hslider("decay", 0.3, 0, 1, 0.001); // sec
17 sustain = hslider("sustain", 0.5, 0, 1, 0.01); // %
18 release = hslider("release", 0.2, 0, 1, 0.001); // sec
19
20 // voice parameters
21 freq = nentry("freq", 440, 20, 20000, 1); // Hz
22 gain = nentry("gain", 1, 0, 10, 0.01); // %
23 gate = button("gate"); // 0/1
24
25 // generic table-driven oscillator with phase modulation
26
27 // n = the size of the table, must be a power of 2
28 // f = the wave function, must be defined on the range [0,2*PI]
29 // freq = the desired frequency in Hz
30 // mod = the phase modulation signal, in radians
31
32 tblosc(n,f,freq,mod) = (1-d)*rdtable(n,waveform,i&(n-1)) +
33 d*rdtable(n,waveform,(i+1)&(n-1))
34 with {
35 waveform = time*(2.0*PI)/n : f;
36 phase = freq/SR : (+ : decimal) ~ _;
37 modphase = decimal(phase+mod/(2*PI))*n;
38 i = int(floor(modphase));
39 d = decimal(modphase);
40 };
41
42 // phase modulation synth (sine modulated by another sine)
43
44 smooth(c) = *(1-c) : +~*(c);
45
46 process = tblosc(1<<16, sin, freq, mod) * env * (gain:smooth(0.999))
47 : vgroup("2-master", *(vol) : panner(pan))
48 with {
49 env = gate : vgroup("1-adsr", adsr(attack, decay, sustain, release));
50 mod = 2*PI*tblosc(1<<16, sin, freq, 0)*env;
51 };