From 4f02964f2fdc0a41476412b2715323a654aa0e5c Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Fri, 14 Sep 2012 22:43:19 +0200 Subject: [PATCH] equalizer: Reduce lag caused by averaging by giving less weight to older samples --- host_python/equalizer.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/host_python/equalizer.py b/host_python/equalizer.py index b6e7264..9a003b5 100755 --- a/host_python/equalizer.py +++ b/host_python/equalizer.py @@ -100,6 +100,8 @@ def get_color(volume): l = ledbar.Ledbar(PIXELS) history = [] + +history_diminish = np.array([[((i+1.0) / HISTORY_SIZE)**2] * CHUNK_SIZE for i in xrange(HISTORY_SIZE)]) window = np.array([0.5*(1-math.cos(2*math.pi*i/(SAMPLE_SIZE-1))) for i in xrange(SAMPLE_SIZE)]) work = True @@ -119,7 +121,7 @@ try: history.append(indata) if len(history) > HISTORY_SIZE: history.pop(0) elif len(history) < HISTORY_SIZE: continue - fft = np.fft.rfft(np.concatenate(history)*window) + fft = np.fft.rfft(np.concatenate(history*history_diminish)*window) freq_limit = MIN_FREQ freq = 0 i = 0