Guido van Rossum | ee11583 | 1990-12-26 15:34:34 +0000 | [diff] [blame] | 1 | # Module 'VUMeter' |
Guido van Rossum | 36ddc9e | 1990-10-31 11:24:22 +0000 | [diff] [blame] | 2 | |
| 3 | import audio |
| 4 | from StripChart import StripChart |
| 5 | |
| 6 | K = 1024 |
| 7 | Rates = [0, 32*K, 16*K, 8*K] |
| 8 | |
Guido van Rossum | ce08448 | 1991-12-26 13:06:29 +0000 | [diff] [blame] | 9 | class VUMeter(StripChart): |
Guido van Rossum | 36ddc9e | 1990-10-31 11:24:22 +0000 | [diff] [blame] | 10 | # |
| 11 | # Override define() and timer() methods |
| 12 | # |
Guido van Rossum | 0c89ec7 | 1990-11-05 19:44:31 +0000 | [diff] [blame] | 13 | def define(self, parent): |
| 14 | self = StripChart.define(self, (parent, 128)) |
| 15 | self.parent.need_timer(self) |
Guido van Rossum | 36ddc9e | 1990-10-31 11:24:22 +0000 | [diff] [blame] | 16 | self.sampling = 0 |
| 17 | self.rate = 3 |
| 18 | self.enable(0) |
| 19 | return self |
| 20 | # |
| 21 | def timer(self): |
| 22 | if self.sampling: |
| 23 | chunk = audio.wait_recording() |
| 24 | self.sampling = 0 |
| 25 | nums = audio.chr2num(chunk) |
| 26 | ampl = max(abs(min(nums)), abs(max(nums))) |
| 27 | self.append(ampl) |
| 28 | if self.enabled and not self.sampling: |
| 29 | audio.setrate(self.rate) |
| 30 | size = Rates[self.rate]/10 |
| 31 | size = size/48*48 |
| 32 | audio.start_recording(size) |
| 33 | self.sampling = 1 |
| 34 | if self.sampling: |
Guido van Rossum | 0c89ec7 | 1990-11-05 19:44:31 +0000 | [diff] [blame] | 35 | self.parent.settimer(1) |
Guido van Rossum | 36ddc9e | 1990-10-31 11:24:22 +0000 | [diff] [blame] | 36 | # |
| 37 | # New methods: start() and stop() |
| 38 | # |
| 39 | def stop(self): |
| 40 | if self.sampling: |
| 41 | chunk = audio.stop_recording() |
| 42 | self.sampling = 0 |
| 43 | self.enable(0) |
| 44 | # |
| 45 | def start(self): |
| 46 | self.enable(1) |
| 47 | self.timer() |