; FM Synthesizer example ; Bruce Maxwell ; January 2012 ; ;-g -A -o fm01.aif -g -odac instr 1 ; example of fm synthesis w/midi ; duration idur = p3 ; overall amplitude iamp = p4 ; convert pitch notation to Hz inote = cpspch(p5) ; carrier ratio kcarRatio = p6 ; modulator ratio kmodRatio = p7 ; environmental shape function ienvshape = p8 ; modulator shape function iidxshape = p9 ; max modulator amplitude imaxidx = .5 ; min modulator amplitude iminidx = .2 ; create a linear envelope of the note duration ; kenvshape linen iamp, 0.5*idur, idur, 0.5*idur kenvshape oscil1i 0, iamp, idur, ienvshape ; this is triangle envelope the length of the duration ; kidxshape linen imaxidx-iminidx, 0.3*idur, idur, 0.2*idur kidxshape oscil1i 0, imaxidx-iminidx, idur, iidxshape ; modulation signal ; amplitude is frequency dependent ; frequency is some multiple of the carrier am oscili (iminidx + kidxshape)*kmodRatio*inote, kmodRatio*inote, 1 ; the output signal ; amplitude is the given Amp and duration envelope ; frequency is (carrier frequency + modulation) ac oscili kenvshape, kcarRatio*inote + am, 1 out ac endin instr 2 ; foscili kcps = cpspch( p5 ) kcar = p6 kmod = p7 kndx oscil1i 0, 0.5-0.2, p3, p9 kenv oscil1i 0, 1, p3, p8 asig foscili kenv*p4, kcps, kcar, kmod, kndx, 1 outs asig, asig endin ; function table 1 ; GEN 10: sine wave ; index start samples GEN max amplitude f 1 0 8192 10 1 ; hamming window f 2 0 1024 20 1 ; gaussian noise f 3 0 4096 21 6 1 ; linear ramp down f 4 0 4096 7 0 4096 1 0 1 ;CLARINET TONES, AFTER CHOWNING f 5 0 512 7 0 50 0.4 50 1 348 1 16 0.8 16 0.5 16 0.3 16 0 ;AMPLITUDE f 6 0 512 7 0 50 0.4 50 1 412 1 ;INDEX ; try w/carRatio 1, modRatio 2 ;MEMBRANOPHONE, AFTER CHOWNING f 7 0 2048 7 0.8 256 0.85 256 1 128 0.9 192 0.45 64 0.3 1152 0 ;AMPLITUDE f 8 0 512 5 1 512 .2 ;INDEX ; ;BRASS, AFTER CHOWNING f 9 0 512 7 0 86 1 86 .75 254 0.6 86 0 ;AMPLITUDE AND INDEX ; exponential falloff (bells) f 10 0 513 5 1 513 .0001 f 11 0 513 5 1 513 .02 p; Note Instr Start Dur Amp Freq carRatio modRatio envshape modshape i 2 0 2.0 8000 7.00 1 1 9 9 i 1 2 2.0 8000 7.00 1 1 9 9 e ;i 1 + 1.0 8000 7.07 . . . . ;i 1 + 3.0 8000 8.00 . . . . ;i 1 6.0 2.0 3000 7.00 . . . . ;i 1 . 2.0 3000 7.04 . . . . ;i 1 . 2.0 3000 7.07 . . . . ;i 1 . 2.0 3000 8.00 . . . . ;e