From 704724bb94970553226c3f2247a1045f4ef94a9e Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Sat, 23 Jun 2012 20:40:03 +0000 Subject: improved logging of freq. --- diff --git a/audiograb.py b/audiograb.py index 745cceb..6f349ea 100644 --- a/audiograb.py +++ b/audiograb.py @@ -293,11 +293,18 @@ class AudioGrab(): def _sample_frequency(self, data_buffer): ''' The maximum frequency in the sample ''' - r = [] - for j in rfft(data_buffer): - r.append(abs(j)) + buf = rfft(data_buffer) + buf = abs(buf) + maxi = buf.argmax() + if maxi == 0: + pitch = 0.0 + else: # Simple interpolation + a, b, c = buf[maxi - 1], buf[maxi], buf[maxi + 1] + maxi -= a / float(a + b + c) + maxi += c / float(a + b + c) + pitch = maxi * 48000 / (len(buf) * 2) # Convert output to Hertz - return r.index(max(r)) * 48000. / len(data_buffer) + return pitch def _calibrate_resistance(self, data_buffer): ''' Return calibrated value for resistance ''' -- cgit v0.9.1