2
2
from Ledart .Tools .Graphics import Graphics , BLUE , WHITE , BLACK
3
3
4
4
import alsaaudio
5
+ import colorsys
5
6
import audioop
6
7
import struct
7
8
import time
@@ -30,27 +31,31 @@ def mean(self, a):
30
31
def average_lists (self , lists ):
31
32
return map (self .mean , zip (* lists ))
32
33
34
+ def draw_pixel (self , x , y , color ):
35
+ color = [int (c * 0xff ) for c in colorsys .hsv_to_rgb (y / float (self .height ), 1 , 1 )]
36
+ Graphics .draw_pixel (self , x , y , color )
37
+
33
38
def generate (self ):
34
39
self .fill (BLACK )
35
40
l , data = self .stream .read ()
36
41
h = 0
37
42
if l :
38
43
data = struct .unpack ("%dh" % (len (data ) / 2 ), data )
39
44
self .chunks .append (data )
40
- if len (self .chunks ) > 10 :
45
+ if len (self .chunks ) > 100 :
41
46
del self .chunks [0 ]
42
47
data = self .average_lists (self .chunks )
43
48
# scale values to the window.
44
49
data = [translate (val , min (data ), max (data ), 1 , self .height * 0.8 ) for val in data ]
45
50
46
51
for x in xrange (len (data )):
47
- if self .mode == 1 :
52
+ if self .mode == 0 :
48
53
self .draw_line (x , self .height - data [x ], x , self .height , BLUE )
49
- elif self .mode == 2 :
54
+ elif self .mode == 1 :
50
55
self .draw_pixel (x , self .height - data [x ], BLUE )
51
- elif self .mode == 3 :
56
+ elif self .mode == 2 :
52
57
self .draw_line (x , (self .height / 2 ) - data [x ] / 2 , x , (self .height / 2 ) + data [x ] / 2 , BLUE )
53
- elif self .mode == 4 :
58
+ elif self .mode == 3 :
54
59
if x >= (self .width - 1 ):
55
60
self .draw_pixel (x , self .height - data [x ], BLUE )
56
61
else :
@@ -61,4 +66,4 @@ def generate(self):
61
66
# if not (len(data) & 1):
62
67
# h = audioop.max(data, 2) / 100
63
68
# color = [min(h, 0xff), max(0xff - h, 0), 0]
64
- # self.draw_line(x, self.height, x, self.height - h, color)
69
+ # self.draw_line(x, self.height, x, self.height - h, color)
0 commit comments