Debian Codegraph @

examples/maparray.csd

raw
1 <CsoundSynthesizer>
2 <CsOptions>
3 ; Select audio/midi flags here according to platform
4 -n
5 </CsOptions>
6 <CsInstruments>
7
8 sr = 44100
9 ksmps = 32
10 nchnls = 2
11 0dbfs = 1
12
13 instr 1
14
15 ;create an array and fill with numbers
16 kArrSrc[] fillarray 1.01, 2.02, 3.03, 4.05, 5.08, 6.13, 7.21
17
18 ;print source array
19 printf "%s", 1, "\nSource array:\n"
20 kndx = 0
21 until kndx == lenarray(kArrSrc) do
22 printf "kArrSrc[%d] = %f\n", kndx+1, kndx, kArrSrc[kndx]
23 kndx += 1
24 od
25
26 ;create an empty array for the results
27 kArrRes[] init 7
28
29 ;apply the sqrt() function to each element
30 kArrRes maparray kArrSrc, "sqrt"
31
32 ;print the result
33 printf "%s", 1, "\nResult after applying sqrt() to source array\n"
34 kndx = 0
35 until kndx == lenarray(kArrRes) do
36 printf "kArrRes[%d] = %f\n", kndx+1, kndx, kArrRes[kndx]
37 kndx += 1
38 od
39
40 ;apply the log() function to each element
41 kArrRes maparray kArrSrc, "log"
42
43 ;print the result
44 printf "%s", 1, "\nResult after applying log() to source array\n"
45 kndx = 0
46 until kndx == lenarray(kArrRes) do
47 printf "kArrRes[%d] = %f\n", kndx+1, kndx, kArrRes[kndx]
48 kndx += 1
49 od
50
51 ;apply the int() function to each element
52 kArrRes maparray kArrSrc, "int"
53
54 ;print the result
55 printf "%s", 1, "\nResult after applying int() to source array\n"
56 kndx = 0
57 until kndx == lenarray(kArrRes) do
58 printf "kArrRes[%d] = %f\n", kndx+1, kndx, kArrRes[kndx]
59 kndx += 1
60 od
61
62 ;apply the frac() function to each element
63 kArrRes maparray kArrSrc, "frac"
64
65 ;print the result
66 printf "%s", 1, "\nResult after applying frac() to source array\n"
67 kndx = 0
68 until kndx == lenarray(kArrRes) do
69 printf "kArrRes[%d] = %f\n", kndx+1, kndx, kArrRes[kndx]
70 kndx += 1
71 od
72
73 ;turn instrument instance off
74 turnoff
75
76 endin
77
78
79 </CsInstruments>
80 <CsScore>
81 i 1 0 0.1
82 e
83 </CsScore>
84 </CsoundSynthesizer>