]> git.parisson.com Git - timeside.git/commitdiff
restore input adapter nframes() suppressed in r123
authorOlivier Guilyardi <olivier@samalyse.com>
Fri, 19 Feb 2010 13:49:48 +0000 (13:49 +0000)
committerOlivier Guilyardi <olivier@samalyse.com>
Fri, 19 Feb 2010 13:49:48 +0000 (13:49 +0000)
core.py
tests/testinputadapter.py

diff --git a/core.py b/core.py
index b4c3153d1394a4094ceff05623db840770e77428..f5b3c31810c566f1193a37301bff8863af46c73a 100644 (file)
--- a/core.py
+++ b/core.py
@@ -106,6 +106,19 @@ class FixedSizeInputAdapter(object):
         self.len         = 0
         self.pad         = pad
 
+    def nframes(self, input_nframes):
+        """Return the total number of frames that this adapter will output according to the
+        input_nframes argument"""
+
+        nframes = input_nframes
+        if self.pad:
+            mod = input_nframes % self.buffer_size
+            if mod:
+                nframes += self.buffer_size - mod
+
+        return nframes                
+
+
     def process(self, frames, eod):
         """Returns an iterator over tuples of the form (buffer, eod) where buffer is a 
         fixed-sized block of data, and eod indicates whether this is the last block.
index 0c051c763de79b292fa9fee359d9df38a0842d4b..28550e1da00f58f81b6bcf8d39a6fdf7a1caf64d 100644 (file)
@@ -23,6 +23,11 @@ data = numpy.arange(44).reshape(2,22).transpose()
 adapter = FixedSizeInputAdapter(4, 2)
 stdout.write("%s simple test" % adapter.__class__.__name__)
 
+expected = len(data)
+actual   = adapter.nframes(len(data))
+if actual != expected:
+    raise Exception("%d != %d nframes", (actual, expected))
+
 test(adapter, data[0:1], False, [])
 test(adapter, data[1:5], False, [data[0:4]], False)
 test(adapter, data[5:12], False, [data[4:8], data[8:12]], False)
@@ -37,6 +42,11 @@ stdout.write(" OK\n")
 adapter = FixedSizeInputAdapter(4, 2, pad=True)
 stdout.write("%s padding test" % adapter.__class__.__name__)
 
+expected = len(data) + 2
+actual   = adapter.nframes(len(data))
+if actual != expected:
+    raise Exception("%d != %d nframes", (actual, expected))
+
 test(adapter, data[0:21], False, [data[0:4], data[4:8], data[8:12], data[12:16], data[16:20]], False)
 test(adapter, data[21:22], True, [[
     [20, 42],