ref: 62a94b75f3e6cd79d11968c9de292956e63faab3
parent: 86026a0bfb4dd50aa25deee1ec797b140fcfe278
author: Paul Brossier <piem@piem.org>
date: Thu Mar 23 22:56:38 EDT 2017
python/lib/aubio/cmd.py: check we found a few beats
--- a/python/lib/aubio/cmd.py
+++ b/python/lib/aubio/cmd.py
@@ -272,9 +272,16 @@
self.beat_locations.append(self.tempo.get_last_s())
def flush(self, frames_read, samplerate):
import numpy as np
- bpms = 60./ np.diff(self.beat_locations)
- median_bpm = np.mean(bpms)
- sys.stdout.write('%.2f bpm' % median_bpm + '\n')
+ if len(self.beat_locations) < 2:
+ outstr = "unknown bpm"
+ else:
+ bpms = 60./ np.diff(self.beat_locations)
+ median_bpm = np.mean(bpms)
+ if len(self.beat_locations) < 10:
+ outstr = "%.2f bpm (uncertain)" % median_bpm
+ else:
+ outstr = "%.2f bpm" % median_bpm
+ sys.stdout.write(outstr + '\n')
class process_notes(default_process):
valid_opts = ['method', 'hop_size', 'buf_size', 'samplerate']