Debian Codegraph @

examples/imageopcodesdemo2.csd

raw
1 <CsoundSynthesizer>
2
3 <CsOptions>
4 ; Select audio/midi flags here according to platform
5 ; Audio out Audio in
6 -odac -iadc ;;;RT audio I/O
7 ; For Non-realtime ouput leave only the line below:
8 ; -o imageopcodesdemo2.wav -W ;;; for file output any platform
9 </CsOptions>
10
11 <CsInstruments>
12 sr = 48000
13 ksmps = 100
14 nchnls = 2
15
16 ;By Cesare Marilungo 2008
17 zakinit 10,1
18
19 ;Load the image - should be 512x512 pixels
20 giimage imageload "test1.png"
21 ;giimage imageload "test2.png" ;--try this too
22 giimagew, giimageh imagesize giimage
23
24 giwave ftgen 1, 0, 1024, 10, 1
25 gifrqs ftgen 2,0,512,-5, 1,512,10
26 giamps ftgen 3, 0, 512, 10, 1
27
28 instr 100
29
30 kindex = 0
31 icnt = giimageh
32 kx_ linseg 0, p3, 1
33 kenv linseg 0, .2, 500, p3 - .4, 500, .2, 0
34
35 ; Read a column of pixels and store the red values
36 ; inside the table 'giamps'
37 loop:
38 ky_ = kindex/giimageh
39
40 ;Get the pixel color values at kx_, ky_
41 kred, kgreen, kblue imagegetpixel giimage, kx_, ky_
42
43 ;Write the red values inside the table 'giamps'
44 tablew kred, kindex, giamps
45 kindex = kindex+1
46
47 if (kindex < icnt) kgoto loop
48
49 ; Use an oscillator bank (additive synthesis) to generate sound
50 ; setting amplitudes for each partial according to the image
51 asig adsynt kenv, 220, giwave, gifrqs, giamps, icnt, 2
52 outs asig, asig
53
54 endin
55
56 instr 101
57 ; Free memory used by the image
58 imagefree giimage
59 endin
60
61 </CsInstruments>
62 <CsScore>
63
64 t 0 60
65
66 i100 1 20
67 i101 21 1
68
69 e
70
71 </CsScore>
72 </CsoundSynthesizer>