Debian Codegraph @

src/Examples/FLOSS Manual Examples/04 Sound Synthesis/04A08_Risset_played_by_Midi.csd

raw
1 <CsoundSynthesizer>
2 <CsOptions>
3 -o dac -m0
4 </CsOptions>
5 <CsInstruments>
6 sr = 44100
7 ksmps = 32
8 nchnls = 2
9 0dbfs = 1
10 seed 0
11
12 ;frequency and amplitude multipliers for 11 partials of Risset's bell
13 giFqs[] fillarray .56, .563, .92, .923, 1.19, 1.7, 2, 2.74, 3, 3.74, 4.07
14 giAmps[] fillarray 1, 2/3, 1, 1.8, 8/3, 5/3, 1.46, 4/3, 4/3, 1, 4/3
15
16 massign 0, 1 ;all midi channels to instr 1
17
18 instr 1 ;master instrument
19 ;;scale desired deviations for maximum velocity
20 ;frequency (cent)
21 imxfqdv = 100
22 ;amplitude (dB)
23 imxampdv = 12
24 ;duration (%)
25 imxdurdv = 100
26 ;;get midi values
27 ibasfreq cpsmidi ;base frequency
28 iampmid ampmidi 1 ;receive midi-velocity and scale 0-1
29 ;;calculate maximum deviations depending on midi-velocity
30 ifqdev = imxfqdv * iampmid
31 iampdev = imxampdv * iampmid
32 idurdev = imxdurdv * iampmid
33 ;;trigger subinstruments
34 indx = 0
35 while indx < 11 do
36 ifqmult = giFqs[indx]
37 ifreq = ibasfreq * ifqmult
38 iampmult = giAmps[indx]
39 iamp = iampmult / 20 ;scale
40 event_i "i", 10, 0, 3, ifreq, iamp, ifqdev, iampdev, idurdev
41 indx += 1
42 od
43 endin
44
45 instr 10 ;subinstrument for playing one partial
46 ;receive the parameters from the master instrument
47 ifreqnorm = p4 ;standard frequency of this partial
48 iampnorm = p5 ;standard amplitude of this partial
49 ifqdev = p6 ;maximum freq deviation in cents
50 iampdev = p7 ;maximum amp deviation in dB
51 idurdev = p8 ;maximum duration deviation in %
52 ;calculate frequency
53 icent random -ifqdev, ifqdev ;cent deviation
54 ifreq = ifreqnorm * cent(icent)
55 ;calculate amplitude
56 idb random -iampdev, iampdev ;dB deviation
57 iamp = iampnorm * ampdb(idb)
58 ;calculate duration
59 idurperc random -idurdev, idurdev ;duration deviation (%)
60 iptdur = p3 * 2^(idurperc/100)
61 p3 = iptdur ;set p3 to the calculated value
62 ;play partial
63 aenv transeg 0, .01, 0, iamp, p3-.01, -10, 0
64 apart poscil aenv, ifreq
65 outs apart, apart
66 endin
67
68 </CsInstruments>
69 <CsScore>
70
71 </CsScore>
72 </CsoundSynthesizer>
73 ;example by joachim heintz