| 1 |
<CsoundSynthesizer> |
| 2 |
<CsOptions> |
| 3 |
; Select audio/midi flags here according to platform |
| 4 |
-odac --limiter=.95 ;;;realtime audio out and limiter |
| 5 |
;-iadc ;;;uncomment -iadc if realtime audio input is needed too |
| 6 |
; For Non-realtime ouput leave only the line below: |
| 7 |
; -o imagegetpixel.wav -W ;;; for file output any platform |
| 8 |
</CsOptions> |
| 9 |
<CsInstruments> |
| 10 |
|
| 11 |
sr = 44100 |
| 12 |
ksmps = 32 |
| 13 |
0dbfs = 1 |
| 14 |
nchnls = 2 |
| 15 |
|
| 16 |
; by Cesare Marilungo 2008 |
| 17 |
; additions by Menno Knevel 2021 |
| 18 |
|
| 19 |
giimage01 imageload "imageOpcode01.png" ; load 2 images - should be 512x512 pixels |
| 20 |
giimagew01, giimageh01 imagesize giimage01 |
| 21 |
giimage02 imageload "imageOpcode02.png" |
| 22 |
giimagew02, giimageh02 imagesize giimage02 |
| 23 |
|
| 24 |
gisine ftgen 1, 0, 8192, 10, 1 ; sine wave |
| 25 |
gifrqs ftgen 2, 0, 512, -5, 1, 512, 10 ; will hold the frequencies |
| 26 |
giamps ftgen 3, 0, 512, 10, 1 ; ready for amplitude data |
| 27 |
|
| 28 |
instr 1 |
| 29 |
|
| 30 |
kindex = 0 |
| 31 |
icnt = giimageh01 ; height of image imageOpcode01.png |
| 32 |
kx_ linseg 0, p3, 1 ; scans x-axis |
| 33 |
kenv linseg 0, p3*.1, .1, p3*.8, .1, p3*.1, 0 ; amplitude envelope |
| 34 |
|
| 35 |
; Read a column of pixels and store the red values inside the table 'giamps' |
| 36 |
loop: |
| 37 |
ky_ = 1-(kindex/giimageh01) ; reverses direction of reading |
| 38 |
kred, kgreen, kblue imagegetpixel giimage01, kx_, ky_ ; get the pixel color values at kx_, ky_ |
| 39 |
tablew kred, kindex, giamps ; write the red values inside the table 'giamps' |
| 40 |
kindex = kindex+1 |
| 41 |
if (kindex < icnt) kgoto loop |
| 42 |
; setting amplitudes for each partial according to the image |
| 43 |
asig adsynt2 kenv, 110, gisine, gifrqs, giamps, icnt, 2 ; oscillator bank (additive synthesis) |
| 44 |
outs asig, asig |
| 45 |
endin |
| 46 |
|
| 47 |
instr 2 ; Free memory used by imageOpcode01.png |
| 48 |
imagefree giimage01 |
| 49 |
endin |
| 50 |
|
| 51 |
instr 3 |
| 52 |
|
| 53 |
kindex = 0 |
| 54 |
icnt = giimageh02 ; height of image imageOpcode02.png |
| 55 |
kx_ linseg 0, p3, 1 ; scans x-axis |
| 56 |
kenv linseg 0, p3*.2, .02, p3*.4, .02, p3*.2, 0 ; amplitude envelope |
| 57 |
; Read a column of pixels and store the blue values inside the table 'giamps' |
| 58 |
loop: |
| 59 |
ky_ = 1-(kindex/giimageh02) ; reverses direction of reading |
| 60 |
kred, kgreen, kblue imagegetpixel giimage02, kx_, ky_ ; get the pixel color values at kx_, ky_ |
| 61 |
tablew kblue, kindex, giamps ; write the blue values inside the table 'giamps' |
| 62 |
kindex = kindex+1 |
| 63 |
if (kindex < icnt) kgoto loop |
| 64 |
|
| 65 |
asig adsynt2 kenv, 100, gisine, gifrqs, giamps, icnt, 2 ; oscillator bank (additive synthesis) |
| 66 |
outs asig, asig |
| 67 |
endin |
| 68 |
|
| 69 |
instr 4 ; Free memory used by imageOpcode02.png |
| 70 |
imagefree giimage02 |
| 71 |
endin |
| 72 |
|
| 73 |
</CsInstruments> |
| 74 |
<CsScore> |
| 75 |
i1 1 3 ; play first image |
| 76 |
i2 4 .1 ; then unload first image |
| 77 |
i3 5 5 ; play second image |
| 78 |
i4 11 .1 ; and unload that one |
| 79 |
e |
| 80 |
</CsScore> |
| 81 |
</CsoundSynthesizer> |