shithub: aubio

Download patch

ref: d47a5e19c1969a4dcf26bb7a9696609bb16b9107
parent: 41121f51edcfa64979de4b23c4ab31d05013f31c
author: Paul Brossier <[email protected]>
date: Mon Dec 2 07:21:43 EST 2013

python/demos/demo_tempo_plot.py: update

--- a/python/demos/demo_tempo_plot.py
+++ b/python/demos/demo_tempo_plot.py
@@ -32,21 +32,16 @@
     samples, read = s()
     is_beat = o(samples)
     if is_beat:
-        this_beat = int(total_frames - delay + is_beat[0] * hop_s)
-        #print "%f" % (this_beat / float(samplerate))
+        this_beat = o.get_last_s()
         beats.append(this_beat)
     total_frames += read
     if read < hop_s: break
 
-#convert samples to seconds
-beats = map( lambda x: x / float(samplerate), beats)
-
-bpms = [60./(b - a) for a,b in zip(beats[:-1],beats[1:])]
-
-if len(bpms):
+if len(beats) > 1:
     # do plotting
-    from numpy import array, arange, mean, median
+    from numpy import array, arange, mean, median, diff
     import matplotlib.pyplot as plt
+    bpms = 60./ diff(beats)
     print 'mean period:', "%.2f" % mean(bpms), 'bpm', 'median', "%.2f" % median(bpms), 'bpm'
     print 'plotting', filename
     plt1 = plt.axes([0.1, 0.75, 0.8, 0.19])
@@ -80,5 +75,5 @@
     plt.show()
 
 else:
-    print 'mean period:', "%.2f" % 0, 'bpm', 'median', "%.2f" % 0, 'bpm', 
+    print 'mean period:', "%.2f" % 0, 'bpm', 'median', "%.2f" % 0, 'bpm',
     print 'nothing to plot, file too short?'