; simple linear pan of a repeating note sr = 44100 kr = 4410 ksmps = 10 nchnls = 2 instr 1 ; simple linear pan of a repeating burst of noise imaxamp = 32767 ; maximum amplitude of source sound (noise) iseed = p2 ; seed for the random number generator anoise rand imaxamp, iseed, 0 ; white noise kenv oscil p4, p5/2., 1 ; periodic sine function (LFO) for amplitude envelope kenv = kenv*kenv ; make it all positive and steeper anoise = kenv*anoise ; control amplitude of noise with envelope k1 line 1.,p3,0. ; straight line from 1 to 0 k2 = 1.-k1 ; straight line from 0 to 1 a1 = anoise*k1 ; fade left speaker from full to none a2 = anoise*k2 ; fade right speaker from none to full outs a1, a2 ; stereo output endin ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; example of the use of a global control instrument instr 2 ; linear function for use as a global control k1 line p4, p3, p5 ; straight line from p4 to p5 (in range 0 to 1) gk1 = 1.-k1 ; global variable for scaling left channel amplitude gk2 = k1 ; global variable for scaling right channel amplitude endin instr 3 ; instrument with stereo balance controlled by instrument 2 imaxamp = 32767 ; maximum amplitude of source sound (noise) iseed = p2 ; seed for the random number generator anoise rand imaxamp, iseed, 0 ; white noise kenv oscil p4, p5/2, 1 ; periodic sine function (LFO) for amplitude envelope kenv = kenv*kenv ; make it all positive and steeper anoise = kenv*anoise ; control amplitude of noise with envelope a1 = anoise*gk1 a2 = anoise*gk2 outs a1, a2 endin ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; example of the use of a global control instrument instr 4 ; linear function for use as a global control k1 line p4, p3, p5 ; straight line from p4 to p5 (in range 0 to 1) gk1a = 1.-k1 ; global variable for scaling left channel amplitude gk2a = k1 ; global variable for scaling right channel amplitude 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*gk1a ; amount to left channel a2 = acarrier*gk2a ; amount to right channel outs a1, a2 endin