File: VUMeter.py

package info (click to toggle)
python 1.5.1-7
  • links: PTS
  • area: main
  • in suites: slink
  • size: 11,616 kB
  • ctags: 32,701
  • sloc: ansic: 90,293; python: 74,171; makefile: 2,449; lisp: 2,097; sh: 702
file content (47 lines) | stat: -rwxr-xr-x 970 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Module 'VUMeter'

import audio
from StripChart import StripChart

K = 1024
Rates = [0, 32*K, 16*K, 8*K]

class VUMeter(StripChart):
	#
	# Override define() and timer() methods
	#
	def define(self, parent):
		self = StripChart.define(self, (parent, 128))
		self.parent.need_timer(self)
		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:
			self.parent.settimer(1)
	#
	# 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()