Debian Codegraph @

examples/cmp.csd

raw
1 <CsoundSynthesizer>
2 <CsOptions>
3 </CsOptions>
4 <CsInstruments>
5
6 sr = 44100
7 ksmps = 128
8 nchnls = 5
9 0dbfs = 1.0
10
11 ; this is the example file for 'cmp'
12
13 /*
14
15 cmp
16
17 compare audio or arrays, value by value
18
19 Audio:
20 * compare audio signals, sample by sample, against another signal or scalar
21 * compara audio singal, sample by sample, within a range:
22 aout cmp klo, "<", ain, "<=", khi
23
24 Arrays:
25 * compare arrays value by value or against a scalar
26 * compare array value by value within a range:
27 kout[] = klo < kin[] <= khi -> kout[] cmp klo, "<", kin[], "<=", khi
28
29 aout cmp a1, Sop, a2 : aout cmp ain, "<", acmp
30 aout cmp a1, Sop, kval : aout cmp ain, ">=", 0.1
31 kout[] cmp k1[], Sop, k2[] : kout[] cmp kxs, "<", kys
32 iout[] cmp i1[], Sop, i2[] : iout[] cmp ixs, "<", iys
33 kout[] cmp k1[], Sop, k : kout[] cmp kxs, "<", 0.5
34 iout[] cmp i1[], Sop, i : iout[] cmp ixs, "<", 0.5
35 kout[] cmp klo, Sop, kx[], Sop, khi : kout[] cmp 0, "<", kxs, "<=", 1
36 iout[] cmp ilo, Sop, ix[], Sop, ihi : iout[] cmp 0, "<", ixs, "<=", 1
37
38 TODO: implement array operations for multidim. arrays
39 (at the time, array operations work only for 1D-arrays)
40
41 */
42
43 ; for audio operations, render this to a soundfile and open in an editor
44 ; to check the results
45
46 instr 1
47 a0 linseg 0, p3, 1
48 a1 linseg 1, p3, 0
49 aout1 cmp a0, "<", a1
50 aout2 cmp a0, "<=", 0.5
51 aout3 cmp a0, ">", 0.5
52 outch 1, a0
53 outch 2, a1
54 outch 3, aout1
55 outch 4, aout2
56 outch 5, aout3
57 endin
58
59 instr 4
60 ; cmp with arrays
61 ixs[] fillarray 0, 1, 2, 3, 4, 5
62 iys[] cmp ixs, ">=", 3
63 printarray iys, "", "instr 4, iys"
64
65 kxs[] fillarray 0, 1, 2, 3, 4, 5
66 kys[] cmp kxs, ">=", 3
67 printarray kys, 1, "", "instr 4, kys"
68 turnoff
69 endin
70
71 instr 5
72 ; range
73 ixs[] fillarray 0, 1, 2, 3, 4, 5
74 iys[] cmp 1, "<", ixs, "<=", 4
75 printarray iys, "", "instr 5, iys"
76
77 kxs[] fillarray 0, 1, 2, 3, 4, 5
78 kys[] cmp 1, "<", kxs, "<=", 4
79 printarray kys, 1, "", "instr 5, kys"
80 turnoff
81 endin
82
83
84
85 </CsInstruments>
86 <CsScore>
87 i 1 0 2
88 i 4 0 1
89 i 5 0 1
90 </CsScore>
91 </CsoundSynthesizer>
92