2 declare name "phasemod -- phase modulation synth";
3 declare author "Albert Graef";
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); // %
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
21 freq = nentry("freq", 440, 20, 20000, 1); // Hz
22 gain = nentry("gain", 1, 0, 10, 0.01); // %
23 gate = button("gate"); // 0/1
25 // generic table-driven oscillator with phase modulation
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
32 tblosc(n,f,freq,mod) = (1-d)*rdtable(n,waveform,i&(n-1)) +
33 d*rdtable(n,waveform,(i+1)&(n-1))
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);
42 // phase modulation synth (sine modulated by another sine)
44 smooth(c) = *(1-c) : +~*(c);
46 process = tblosc(1<<16, sin, freq, mod) * env * (gain:smooth(0.999))
47 : vgroup("2-master", *(vol) : panner(pan))
49 env = gate : vgroup("1-adsr", adsr(attack, decay, sustain, release));
50 mod = 2*PI*tblosc(1<<16, sin, freq, 0)*env;