mirror of
https://github.com/python/cpython.git
synced 2024-12-01 11:15:56 +01:00
89a78697b8
* Many modules: fixes for new, stricter, argument passing rules (most changes were automatic ones -- not all of this is tested!). * gwin.py: now uses mainloop.py for its main loop and window admin. * mainloop.py: always call dispatch() with event as a tuple! * Fix bug in pdb's 'clear' command -- don't set the bpt but clear it!
37 lines
867 B
Python
37 lines
867 B
Python
# Module 'Soundogram'
|
|
|
|
import audio
|
|
from Histogram import Histogram
|
|
|
|
class Soundogram(Histogram):
|
|
#
|
|
def define(self, win, chunk):
|
|
width, height = corner = win.getwinsize()
|
|
bounds = (0, 0), corner
|
|
self.chunk = chunk
|
|
self.step = (len(chunk)-1)/(width/2+1) + 1
|
|
ydata = _make_ydata(chunk, self.step)
|
|
return Histogram.define(self, (win, bounds, ydata, (0, 128)))
|
|
#
|
|
def setchunk(self, chunk):
|
|
self.chunk = chunk
|
|
self.recompute()
|
|
#
|
|
def recompute(self):
|
|
(left, top), (right, bottom) = self.bounds
|
|
width = right - left
|
|
self.step = (len(chunk)-1)/width + 1
|
|
ydata = _make_ydata(chunk, self.step)
|
|
self.setdata(ydata, (0, 128))
|
|
#
|
|
|
|
|
|
def _make_ydata(chunk, step):
|
|
ydata = []
|
|
for i in range(0, len(chunk), step):
|
|
piece = audio.chr2num(chunk[i:i+step])
|
|
mi, ma = min(piece), max(piece)
|
|
y = max(abs(mi), abs(ma))
|
|
ydata.append(y)
|
|
return ydata
|