sr = 44100 kr = 4410 ksmps = 10 nchnls = 2 instr 4 apan line p4, p3, p5 ; line from p4 to p5 over the course of a "note" ; lookup the value in a stored table of 1/4 sine galeft table (1.-apan)*4096, 2 ; left goes inverse-exponentially to 0 garight table (apan)*4096, 2 ; right goes inverse-exponentially to 1 endin instr 5 ; FM instrument with stereo balance controlled by instrument 4 imaxamp = 32767 ; maximum amplitude of source sound ifreqc = cpspch(p5) ; convert octave.pitch notation to Hz for carrier ifreqm = ifreqc*p6 ; p6 = harmonicity index kmodindex linseg p7, p8, p9, p10, p11 ; modulation index amodulator oscil ifreqm*kmodindex, ifreqm, 1 ; modulating oscillator kenv adsr 0.005, 0.12, 0.125, 0.125 ; amplitude envelope for carrier kenv = kenv*imaxamp*p4 ; scale to full range, within p4 acarrier oscil kenv, ifreqc+amodulator, 1 ; carrier oscillator a1 = acarrier*galeft ; amount to left channel a2 = acarrier*garight ; amount to right channel outs a1, a2 endin ; this instrument is not used, but is included just for comparison instr 6 ; same as instr 4, using square root instead of lookup table apan line p4, p3, p5 ; line from p4 to p5 over the course of a "note" ; amplitude varies as the square root of intensity ; so apan is being thought of as intensity, ; and to keep equal intensity, we need to take its square root ; to get the proper corresponding amplitude galeft = sqrt(1.-aamp) ; left goes inverse-exponentially to 0 garight = sqrt(aamp) ; right goes inverse-exponentially to 1 endin