Converting Graphics to Audio
I am trying to convert graphics created from Graphics.spin into audio for an art project ( see here ).
I have a 470 ohm resistor and a 270 ohm resistor attached to pins 22 and 23 (to create a 2 bit dac). I want the code to read through the graphics/screen buffer and output a value through those pins.
The following code tries to read one line (long) of each tile. It starts by reading line 0 of tile 0, and then line 0 of tile 1, line 0 of tile 2 ... line 1 of tile 0, line 1 of tile 1, etc. The code then looks through that line and sums up all reference to color indices 1 or 2 (I do not want to output any sound for indices 0 or 3) into the value variable. This variable's value determines the output of the dac.
The code kind of works a bit, but definitely not how I am expecting it to. Any suggestions? Am i doing something wrong? Instead of reading the screen, should I read the bitmap instead?
The code ( the object expects a reference to the screen buffer ):
I have a 470 ohm resistor and a 270 ohm resistor attached to pins 22 and 23 (to create a 2 bit dac). I want the code to read through the graphics/screen buffer and output a value through those pins.
The following code tries to read one line (long) of each tile. It starts by reading line 0 of tile 0, and then line 0 of tile 1, line 0 of tile 2 ... line 1 of tile 0, line 1 of tile 1, etc. The code then looks through that line and sums up all reference to color indices 1 or 2 (I do not want to output any sound for indices 0 or 3) into the value variable. This variable's value determines the output of the dac.
The code kind of works a bit, but definitely not how I am expecting it to. Any suggestions? Am i doing something wrong? Instead of reading the screen, should I read the bitmap instead?
The code ( the object expects a reference to the screen buffer ):
CON WIDTH = 16 HEIGHT = 12 VAR long stack[32] long cog long graphics long index long screen long value PUB start(screen_ptr) : okay ' start a cog stop screen := screen_ptr dira[22] := 1 dira[23] := 1 okay := cog := cognew(update, @stack) + 1 PUB stop {{ stop cog if in use }} if cog cogstop(cog~ - 1) PUB update | col, pixels,color, line, pointer, out, row col := 0 row := 0 line := 0 dira[22] := 1 dira[23] := 1 repeat if col == width col:=0 line++ if line > 15 line:=0 row++ if row == height row:=0 'tile := (word[screen+((col)+(row*width))*2]) pointer := ( word[screen][col+(row*width)] & %00000011_11111111) << 6 'palette := long[tile >> 10] pixels := long[pointer][line] value := 0 repeat 16 if (pixels & %11) == 1 OR (pixels & %11) == 2 value++ pixels := pixels >> 2 if value > 12 outa[22] := 1 outa[23] := 1 elseif value > 8 outa[22] := 1 outa[23] := 0 elseif value > 4 outa[22] := 0 outa[23] := 1 else outa[22] := 0 outa[23] := 0 col++