Fix an amazing number of typos & malformed sentences reported by Detlef
[python/dscho.git] / Lib / lib-stdwin / Soundogram.py
blobe3c797e3dd9169d4854613c04ea75199e3786684
1 # Module 'Soundogram'
3 import audio
4 from Histogram import Histogram
6 class Soundogram(Histogram):
8 def define(self, win, chunk):
9 width, height = corner = win.getwinsize()
10 bounds = (0, 0), corner
11 self.chunk = chunk
12 self.step = (len(chunk)-1)/(width/2+1) + 1
13 ydata = _make_ydata(chunk, self.step)
14 return Histogram.define(self, (win, bounds, ydata, (0, 128)))
16 def setchunk(self, chunk):
17 self.chunk = chunk
18 self.recompute()
20 def recompute(self):
21 (left, top), (right, bottom) = self.bounds
22 width = right - left
23 self.step = (len(chunk)-1)/width + 1
24 ydata = _make_ydata(chunk, self.step)
25 self.setdata(ydata, (0, 128))
29 def _make_ydata(chunk, step):
30 ydata = []
31 for i in range(0, len(chunk), step):
32 piece = audio.chr2num(chunk[i:i+step])
33 mi, ma = min(piece), max(piece)
34 y = max(abs(mi), abs(ma))
35 ydata.append(y)
36 return ydata