From 683c89f586d0c726a41aa2e2d4b42f981dcefdc5 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Sat, 30 Jun 2012 23:42:54 +0200 Subject: [PATCH] host_python/equalizer: Ratelimit updates --- host_python/equalizer.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/host_python/equalizer.py b/host_python/equalizer.py index e1a816d..03f1415 100755 --- a/host_python/equalizer.py +++ b/host_python/equalizer.py @@ -5,6 +5,8 @@ import pyaudio import struct import math import numpy as np +import time +from datetime import datetime import ledbar @@ -31,7 +33,7 @@ stream = p.open(format = FORMAT, frames_per_buffer = CHUNK_SIZE) def get_color(volume): - p = 1-15/volume + p = 1-15/(volume) if p <= 0: return (0, 0, 0) p *= p if p <= 0.4: return (0, 0, p*2.5) @@ -44,10 +46,17 @@ history = [] window = np.array([0.5*(1-math.cos(2*math.pi*i/(SAMPLE_SIZE-1))) for i in xrange(SAMPLE_SIZE)]) work = True +nexttrig = 0 + try: while work: try: data = stream.read(CHUNK_SIZE) except IOError: continue + nowtrig = datetime.now().microsecond / 50000 + if (nowtrig == nexttrig): + continue + else: + nexttrig = nowtrig if len(data) == 0: break indata = np.array(struct.unpack('%dh'%CHUNK_SIZE,data)) history.append(indata) @@ -79,6 +88,7 @@ try: c = get_color(volumes[pixel]) l.set_pixel(pixel, c[0], c[1], c[2]) work = l.update() + # time.sleep(0.05) finally: stream.close() p.terminate()