Debian Codegraph @

src/Examples/FLOSS Manual Examples/01 Basics/01D04_trirand.csd

raw
1 <CsoundSynthesizer>
2 <CsOptions>
3 -odac -m0
4 </CsOptions>
5 <CsInstruments>
6 sr = 44100
7 ksmps = 32
8 nchnls = 2
9 0dbfs = 1
10 seed 0
11
12 ;****UDO FOR TRIANGULAR DISTRIBUTION****
13 opcode trirnd, i, ii
14 iMin, iMax xin
15 ;generate two random values with the random opcode
16 iOne random iMin, iMax
17 iTwo random iMin, iMax
18 ;get the mean and output
19 iRnd = (iOne+iTwo) / 2
20 xout iRnd
21 endop
22
23 ;****INSTRUMENTS FOR UNIFORM AND TRIANGULAR DISTRIBUTION****
24
25 instr notes_uniform
26 prints "... instr notes_uniform playing:\n"
27 prints "EQUAL LIKELINESS OF ALL PITCHES AND DURATIONS\n"
28 ;how many notes to be played
29 iHowMany = p4
30 ;trigger as many instances of instr play as needed
31 iThisNote = 0
32 iStart = 0
33 until iThisNote == iHowMany do
34 iMidiPch random 36, 84 ;midi note
35 iDur random .25, 1.75 ;duration
36 event_i "i", "play", iStart, iDur, int(iMidiPch)
37 iStart += iDur ;increase start
38 iThisNote += 1 ;increase counter
39 enduntil
40 ;reset the duration of this instr to make all events happen
41 p3 = iStart + 2
42 ;trigger next instrument two seconds after the last note
43 event_i "i", "notes_trirnd", p3, 1, iHowMany
44 endin
45
46 instr notes_trirnd
47 prints "... instr notes_trirnd playing:\n"
48 prints "MEDIUM NOTES AND DURATIONS PREFERRED\n"
49 iHowMany = p4
50 iThisNote = 0
51 iStart = 0
52 until iThisNote == iHowMany do
53 iMidiPch trirnd 36, 84 ;medium pitches preferred
54 iDur trirnd .25, 1.75 ;medium durations preferred
55 event_i "i", "play", iStart, iDur, int(iMidiPch)
56 iStart += iDur
57 iThisNote += 1
58 enduntil
59 ;reset the duration of this instr to make all events happen
60 p3 = iStart + 2
61 ;call instr to exit csound
62 event_i "i", "exit", p3+1, 1
63 endin
64
65
66 ;****INSTRUMENTS TO PLAY THE SOUNDS AND EXIT CSOUND****
67
68 instr play
69 ;increase duration in random range
70 iDur random p3, p3*1.5
71 p3 = iDur
72 ;get midi note and convert to frequency
73 iMidiNote = p4
74 iFreq cpsmidinn iMidiNote
75 ;generate note with karplus-strong algorithm
76 aPluck pluck .2, iFreq, iFreq, 0, 1
77 aPluck linen aPluck, 0, p3, p3
78 ;filter
79 aFilter mode aPluck, iFreq, .1
80 ;mix aPluck and aFilter according to MidiNote
81 ;(high notes will be filtered more)
82 aMix ntrpol aPluck, aFilter, iMidiNote, 36, 84
83 ;panning also according to MidiNote
84 ;(low = left, high = right)
85 iPan = (iMidiNote-36) / 48
86 aL, aR pan2 aMix, iPan
87 outs aL, aR
88 endin
89
90 instr exit
91 exitnow
92 endin
93
94 </CsInstruments>
95 <CsScore>
96 i "notes_uniform" 0 1 23 ;set number of notes per instr here
97 ;instr trirnd will be triggered automatically
98 e 99999 ;make possible to perform long (exit will be automatically)
99 </CsScore>
100 </CsoundSynthesizer>
101 ;example by joachim heintz