; Bruce Maxwell ; January 2012 ; Examples of several instruments, one created using superposition ; use this option to write to a file ;-g -A -o cs3.aif ; use this option to generate the sound directly -g -odac ; instrument 1 is a single oscillator instr 1 ; amplitude iamp = p4 ; convert the pitch notation to a frequency inote = cpspch( p5 ) ; oscillate a sine wave (table 1) at the given frequency a1 oscil iamp, inote, 1 ; output out a1 endin ; instrument 2 is a single buzz instr 2 ; amplitude iamp = p4 ; convert the pitch notation to a frequency inote = cpspch( p5 ) ; number of harmonics requested iharm = 10 ; buzz at the given frequency a1 buzz iamp, inote, iharm, 1 ; output out a1 endin ; instrument 3 is multiple oscillators and buzzers ; it also has a linear envelope that rises quickly and falls slowly instr 3 ; duration idur = p3 ; amplitude iamp = p4 ; note inote = cpspch( p5 ) ; number of harmonics for buzzer iharm = 10 ; a linear envelope kenv linen iamp, 0.05*idur, idur, .5*idur ; a whole bunch of oscilators and buzzes a1 buzz 1, inote, iharm, 1 a2 buzz 1, inote*0.5-5, iharm, 1 a3 oscil 1, inote, 1 a4 oscil 1, inote*0.996, 1 a5 oscil 1, inote*1.004, 1 a6 oscil 1, 2*inote*0.99, 1 a7 oscil 1, 3*inote*1.03, 1 a8 oscil 1, 4*inote*1.001, 1 a9 oscil 1, 0.5*inote*0.995, 1 ; combine the signals with a weighted average (sum is 1.0) athing = kenv * ( 0.1*a1 + 0.04*a2 + 0.4*a3 + 0.01*a4 + 0.01*a5 + 0.1*a6 + 0.05*a7 + 0.1*a8 + 0.2*a9 ) ; output out athing endin ; Table used to generate a sine wave f 1 0 8192 10 0.7 0.05 0.2 0.05 ; The notes using pitch-class notation where the integer is the octave ; and the following two digits are the note within the octave ; Note Instr Start Dur Amp Freq i 3 0 1 10000 8.00 i 3 1 1 10000 8.02 i 3 2 1 10000 8.04 i 3 3 1 10000 8.05 i 3 4 1 10000 8.07 i 3 5 1 10000 8.09 i 3 6 1 10000 8.11 i 3 7 1 10000 8.12