diff options
author | Walter Bender <walter.bender@gmail.com> | 2012-06-23 20:24:21 (GMT) |
---|---|---|
committer | Walter Bender <walter.bender@gmail.com> | 2012-06-23 20:24:21 (GMT) |
commit | f5c4667bd8fc18e246c137489c7cbb16183ff561 (patch) | |
tree | 1bd94f471c337d14ec9fee93c4a2e0e80cc88d87 /plugins/audio_sensors | |
parent | 144d719779dfdb7b4b99ce0799d119fcb73087dc (diff) |
improved pitch tracking
Diffstat (limited to 'plugins/audio_sensors')
-rw-r--r-- | plugins/audio_sensors/audio_sensors.py | 16 |
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: |