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