; Example by Bruce Maxwell ; January 2012 ; Use this option to save the sound to a file ;-g -A -o gran01.aif ; Use this option to play the sound immediately -g -odac ; uses a sample to fm modify a carrier signal instr 1 idur = p3 iamp = p4 ; use this to oscillate at a pitch ifreq = cpspch( p5 ) istart = p6 itbl = p7 ipatchlength = 8192 ; environment shape kenv linen iamp, 0.05*idur, idur, 0.25*idur ; this version uses a random sample as the fm modifier aphs lphasor ipatchlength/(idur*44100), istart, istart + ipatchlength, 1, istart ; interpolate from a table atbl tablei aphs, itbl ; oscilate a sine wave at the given frequency am oscili 1, ifreq *(1 + 1*atbl), 1 ; output signal is the table modified by the environmental shape aout = am * kenv ; output out aout endin ; plays a short part of a sample at a given speed instr 2 ; duration idur = p3 ; amplitude iamp = p4 ; frequency modifier (2.0 plays at regular speed) ifreq = p5 ; starting location in samples istart = p6 ; which table to use itbl = p7 ; environment shape kenv linen iamp, 0.05*idur, idur, 0.25*idur ; phasor that loops through numbers aphs lphasor ifreq, istart, istart + idur*44100*ifreq, 1, istart ; table lookup atbl tablei aphs, itbl ; output signal aout = atbl * kenv out aout endin ; function table 1 sine wave ; index start samples GEN max amplitude f 1 0 8192 10 1 ; function table 2 sound sample ; f 2 0 131072 1 "interactive-digital-media.aiff" 0 0 0 ; The following score was generated by python scripts ; Note Instr Start Dur Amp Freq scps table patchlength p ; example of instrument 2 i 2 2.79 1.50 8000.00 2.00 97896 2 i 2 8.07 1.50 8000.00 2.00 93061 2 i 2 5.70 1.50 8000.00 2.00 17940 2 i 2 5.02 1.50 8000.00 2.00 71305 2 i 2 6.76 1.50 8000.00 2.00 78968 2 i 2 4.18 1.50 8000.00 2.00 4990 2 i 2 4.33 1.50 8000.00 2.00 98362 2 i 2 1.45 1.50 8000.00 2.00 13535 2 i 2 0.24 1.50 8000.00 2.00 130978 2 i 2 7.15 1.50 8000.00 2.00 89899 2 ; example of instrument 1 i 1 0.00 1.70 10000.00 7.00 51246 2 i 1 2.00 1.70 10000.00 7.00 77865 2 i 1 4.00 1.70 10000.00 7.00 37719 2 i 1 6.00 1.70 10000.00 7.00 38937 2 i 1 8.00 1.70 10000.00 7.00 60396 2 e