ref: 1ebfa8c6f4dba41452dfc8a21ad5806f0b33c817
parent: f1d2af7cd309a97034c3095cdcbd95246e00e502
parent: f1198eff4b34b29bc4d6bdd5e3c1e03d5a8d068e
author: Paul Brossier <piem@piem.org>
date: Thu Jul 26 17:43:27 EDT 2012
Merge branch 'develop' into io
--- a/interfaces/python/demo_beat.py
+++ /dev/null
@@ -1,27 +1,0 @@
-#! /usr/bin/python
-
-import sys
-from os.path import splitext, basename
-from aubio import tempo
-from aubioinput import aubioinput
-
-win_s = 512 # fft size
-hop_s = win_s / 2 # hop size
-beat = tempo("default", win_s, hop_s)
-
-beats = []
-
-def process(samples, pos):
- isbeat = beat(samples)
- if isbeat:
- thisbeat = (float(isbeat[0]) + pos * hop_s) / 44100.
- print thisbeat
- beats.append (thisbeat)
-
-if len(sys.argv) < 2:
- print "Usage: %s <filename>" % sys.argv[0]
-else:
- filename = sys.argv[1]
- a = aubioinput(filename, process = process, hopsize = hop_s,
- caps = 'audio/x-raw-float, rate=44100, channels=1')
- a.run()
--- /dev/null
+++ b/interfaces/python/demo_beats_and_tempo.py
@@ -1,0 +1,39 @@
+#! /usr/bin/python
+
+import sys
+from aubio import tempo, source
+
+win_s = 512 # fft size
+hop_s = win_s / 2 # hop size
+samplerate = 44100
+
+if len(sys.argv) < 2:
+ print "Usage: %s <filename>" % sys.argv[0]
+ sys.exit(1)
+
+filename = sys.argv[1]
+beats = []
+
+s = source(filename, samplerate, hop_s)
+t = tempo("default", win_s, hop_s)
+
+block_read = 0
+while True:
+ samples, read = s()
+ isbeat = t(samples)
+ if isbeat:
+ thisbeat = (block_read * hop_s + isbeat[0]) / samplerate
+ print "%.4f" % thisbeat
+ beats.append (thisbeat)
+ block_read += 1
+ if read < hop_s: break
+
+periods = [60./(b - a) for a,b in zip(beats[:-1],beats[1:])]
+
+from numpy import mean, median
+print 'mean period:', mean(periods), 'bpm'
+print 'median period:', median(periods), 'bpm'
+
+from pylab import plot, show
+plot(beats[1:], periods)
+show()
--- a/interfaces/python/py-filter.c
+++ b/interfaces/python/py-filter.c
@@ -96,7 +96,7 @@
err = aubio_filter_set_c_weighting (self->o, samplerate);
if (err > 0) {
PyErr_SetString (PyExc_ValueError,
- "error when setting filter to A-weighting");
+ "error when setting filter to C-weighting");
return NULL;
}
return Py_None;