ref: 228e8d80880f3258ed2ae5637afe3338eba76708
parent: 493e6f7a0834dbb57621a1d06596b8a94b5ed3ad
author: Paul Brossier <piem@piem.org>
date: Sat Jan 9 10:22:41 EST 2010
aubioinput.py: flush last frame, no resizing in mono
--- 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)