0
0
mirror of https://github.com/python/cpython.git synced 2024-11-30 18:51:15 +01:00
cpython/Lib/lib-stdwin/VUMeter.py

48 lines
975 B
Python
Raw Normal View History

1990-12-26 16:34:34 +01:00
# Module 'VUMeter'
1990-10-31 12:24:22 +01:00
import audio
from StripChart import StripChart
K = 1024
Rates = [0, 32*K, 16*K, 8*K]
class VUMeter() = StripChart():
#
# Override define() and timer() methods
#
1990-11-05 20:44:31 +01:00
def define(self, parent):
self = StripChart.define(self, (parent, 128))
self.parent.need_timer(self)
1990-10-31 12:24:22 +01:00
self.sampling = 0
self.rate = 3
self.enable(0)
return self
#
def timer(self):
if self.sampling:
chunk = audio.wait_recording()
self.sampling = 0
nums = audio.chr2num(chunk)
ampl = max(abs(min(nums)), abs(max(nums)))
self.append(ampl)
if self.enabled and not self.sampling:
audio.setrate(self.rate)
size = Rates[self.rate]/10
size = size/48*48
audio.start_recording(size)
self.sampling = 1
if self.sampling:
1990-11-05 20:44:31 +01:00
self.parent.settimer(1)
1990-10-31 12:24:22 +01:00
#
# New methods: start() and stop()
#
def stop(self):
if self.sampling:
chunk = audio.stop_recording()
self.sampling = 0
self.enable(0)
#
def start(self):
self.enable(1)
self.timer()