1 2declare name "phasemod -- phase modulation synth"; 3declare author "Albert Graef"; 4declare version "1.0"; 5 6import("music.lib"); 7 8// control variables 9 10// master volume and pan 11vol = hslider("vol", 0.3, 0, 10, 0.01); // % 12pan = hslider("pan", 0.5, 0, 1, 0.01); // % 13 14// ADSR envelop 15attack = hslider("attack", 0.01, 0, 1, 0.001); // sec 16decay = hslider("decay", 0.3, 0, 1, 0.001); // sec 17sustain = hslider("sustain", 0.5, 0, 1, 0.01); // % 18release = hslider("release", 0.2, 0, 1, 0.001); // sec 19 20// voice parameters 21freq = nentry("freq", 440, 20, 20000, 1); // Hz 22gain = nentry("gain", 1, 0, 10, 0.01); // % 23gate = 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 32tblosc(n,f,freq,mod) = (1-d)*rdtable(n,wave,i&(n-1)) + 33 d*rdtable(n,wave,(i+1)&(n-1)) 34with { 35 wave = 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 44smooth(c) = *(1-c) : +~*(c); 45 46process = tblosc(1<<16, sin, freq, mod) * env * (gain:smooth(0.999)) 47 : vgroup("2-master", *(vol) : panner(pan)) 48with { 49 env = gate : vgroup("1-adsr", adsr(attack, decay, sustain, release)); 50 mod = 2*PI*tblosc(1<<16, sin, freq, 0)*env; 51}; 52