diff options
| author | Skip Montanaro <[email protected]> | 2021-02-16 20:14:16 -0600 |
|---|---|---|
| committer | Skip Montanaro <[email protected]> | 2021-02-16 20:14:16 -0600 |
| commit | c2587c76f1b416cdbecb979e54941933246bf856 (patch) | |
| tree | bb61ee9128075ce22af4eafa232f13c2e5a07896 /lib/Soundogram.py | |
| parent | d90761a005b24018ae237bf551515772a1de656f (diff) | |
| download | python-0.9.1-patched-QoL-c2587c76f1b416cdbecb979e54941933246bf856.tar.xz python-0.9.1-patched-QoL-c2587c76f1b416cdbecb979e54941933246bf856.zip | |
starting over
Diffstat (limited to 'lib/Soundogram.py')
| -rw-r--r-- | lib/Soundogram.py | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/lib/Soundogram.py b/lib/Soundogram.py index 38dd5ef..aa2edd1 100644 --- a/lib/Soundogram.py +++ b/lib/Soundogram.py @@ -4,33 +4,33 @@ 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 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 + 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 |
