equalizer: Reduce lag caused by averaging by giving less weight to older samples

This commit is contained in:
Petr Baudis 2012-09-14 22:43:19 +02:00
parent ca762a30f1
commit 4f02964f2f

View file

@ -100,6 +100,8 @@ def get_color(volume):
l = ledbar.Ledbar(PIXELS) l = ledbar.Ledbar(PIXELS)
history = [] 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)]) window = np.array([0.5*(1-math.cos(2*math.pi*i/(SAMPLE_SIZE-1))) for i in xrange(SAMPLE_SIZE)])
work = True work = True
@ -119,7 +121,7 @@ try:
history.append(indata) history.append(indata)
if len(history) > HISTORY_SIZE: history.pop(0) if len(history) > HISTORY_SIZE: history.pop(0)
elif len(history) < HISTORY_SIZE: continue 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_limit = MIN_FREQ
freq = 0 freq = 0
i = 0 i = 0