shithub: aubio

Download patch

ref: 066433db7ff0966faf04a301b8562d0fd0dfd16e
parent: 8212692b7d1df87a305b3fe5ac23ea343dd7fe04
parent: 37eb9ceb5cba5492740af27f78e914c43ecdb3b5
author: Paul Brossier <piem@piem.org>
date: Sat Jan 9 10:51:20 EST 2010

merge with mono

--- a/examples/utils.c
+++ b/examples/utils.c
@@ -237,7 +237,7 @@
   }
 #endif /* HAVE_LASH */
 
-  woodblock = new_fvec (overlap_size, channels);
+  woodblock = new_fvec (overlap_size);
   if (output_filename || usejack) {
     /* dummy assignement to keep egcs happy */
     found_wood = (onsetfile = new_aubio_sndfile_ro (onset_filename)) ||
@@ -250,11 +250,11 @@
   }
   if (onsetfile) {
     /* read the output sound once */
-    aubio_sndfile_read (onsetfile, overlap_size, woodblock);
+    aubio_sndfile_read_mono (onsetfile, overlap_size, woodblock);
   }
 
-  ibuf = new_fvec (overlap_size, channels);
-  obuf = new_fvec (overlap_size, channels);
+  ibuf = new_fvec (overlap_size);
+  obuf = new_fvec (overlap_size);
 
 }
 
--- a/interfaces/python/aubio/__init__.py
+++ b/interfaces/python/aubio/__init__.py
@@ -3,9 +3,7 @@
 
 class fvec(numpy.ndarray):
 
-    def __init__(self, length = 1024, **kwargs):
-        super(numpy.ndarray, self).__init__(**kwargs)
-
     def __new__(self, length = 1024, **kwargs):
-        self = numpy.zeros(length, dtype='float32', **kwargs)
-        return self
+        if type(length) == type([]):
+            return numpy.array(length, dtype='float32', **kwargs)
+        return numpy.zeros(length, dtype='float32', **kwargs)
--- a/interfaces/python/aubioinput.py
+++ b/interfaces/python/aubioinput.py
@@ -9,8 +9,11 @@
 def gst_buffer_to_numpy_array(buffer, chan):
     import numpy
     samples = numpy.frombuffer(buffer.data, dtype=numpy.float32) 
-    samples.resize([len(samples)/chan, chan])
-    return samples.T
+    if chan == 1:
+        return samples.T
+    else:
+        samples.resize([len(samples)/chan, chan])
+        return samples.T
 
 class AubioSink(gst.BaseSink):
     _caps = gst.caps_from_string('audio/x-raw-float, \
@@ -52,7 +55,14 @@
             v = gst_buffer_to_numpy_array(block, chan)
             if self.process:
                 self.process(v, self.pos)
-            self.pos += 1    
+            self.pos += 1
+        remaining = self.adapter.available()
+        if remaining < blocksize and remaining > 0:
+            block = self.adapter.take_buffer(remaining)
+            v = gst_buffer_to_numpy_array(block, chan)
+            if self.process:
+                self.process(v, self.pos)
+            self.pos += 1
         return gst.FLOW_OK
 
 gobject.type_register(AubioSink)
--- /dev/null
+++ b/interfaces/python/demo_beat.py
@@ -1,0 +1,27 @@
+#! /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_filterbank.py
@@ -1,0 +1,12 @@
+from aubio import filterbank, fvec
+
+f = filterbank(9, 1024)
+freq_list = [60, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]
+freqs = fvec(freq_list)
+f.set_triangle_bands(freq_list, 48000)
+f.get_coeffs().T
+
+from pylab import loglog, show
+loglog(f.get_coeffs().T, '+-')
+show()
+
--- a/interfaces/python/test_fvec.py
+++ b/interfaces/python/test_fvec.py
@@ -13,6 +13,10 @@
         #del a
         assert_equal(array(a), 0.)
 
+    def test_vector_create_with_list(self):
+        a = fvec([0,1,2,3])
+        assert_equal (range(4), a)
+
     def test_vector_assign_element(self):
         a = fvec()
         a[0] = 1
@@ -52,6 +56,9 @@
         a = array([0, 1], dtype='float32')
         from math import sqrt
         assert_almost_equal (alpha_norm(a, 2), sqrt(2)/2.)
+
+    def test_alpha_norm_of_none(self):
+        self.assertRaises (ValueError, alpha_norm, None, 1)
 
     def test_alpha_norm_of_array_of_float32(self):
         # check scalar fails
--- a/tests/src/test-pitch.c
+++ b/tests/src/test-pitch.c
@@ -2,11 +2,10 @@
 
 int main(){
         /* allocate some memory */
-        uint_t win_s      = 1024;                       /* window size */
-        uint_t channels   = 1;                          /* number of channel */
-        fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
-        fvec_t * out      = new_fvec (1, channels); /* input buffer */
-        aubio_pitch_t *p = new_aubio_pitch ("default", win_s, win_s / 2, channels, 44100);
+        uint_t win_s      = 1024; /* window size */
+        fvec_t * in       = new_fvec (win_s); /* input buffer */
+        fvec_t * out      = new_fvec (1); /* input buffer */
+        aubio_pitch_t *p = new_aubio_pitch ("default", win_s, win_s / 2, 44100);
         uint_t i = 0;
 
         while (i < 10) {