Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/audio_sensors/audio_sensors.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/plugins/audio_sensors/audio_sensors.py b/plugins/audio_sensors/audio_sensors.py
index 355fe98..0a7fb81 100644
--- a/plugins/audio_sensors/audio_sensors.py
+++ b/plugins/audio_sensors/audio_sensors.py
@@ -325,11 +325,17 @@ class Audio_sensors(Plugin):
buf = append(
buf, self.ringbuffer[channel].read(None, self.input_step))
if len(buf) > 0:
- r = []
- for j in rfft(buf):
- r.append(abs(j))
- # Convert output to Hertz
- pitch = r.index(max(r)) * 48000 / len(buf)
+ buf = rfft(buf)
+ buf = abs(buf)
+ maxi = buf.argmax()
+ if maxi == 0:
+ pitch = 0
+ else: # Simple interpolation
+ a, b, c = buf[maxi - 4], buf[maxi], buf[maxi + 4]
+ maxi -= (4. * a) / float(a + b + c)
+ maxi += (4. * c) / float(a + b + c)
+ pitch = maxi * 48000 / (len(buf) * 2)
+
self._parent.lc.update_label_value('pitch', pitch)
return pitch
else: