changeset 71:cb0380c92c42

Stub out a collect() function which will (?) assemble a suitable structure from an entire run
author Chris Cannam
date Wed, 14 Jan 2015 17:33:16 +0000
parents ffdeb8808fc1
children ca1b533b9480
files test/test_collect.py test/test_process.py vamp/__init__.py
diffstat 3 files changed, 54 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/test_collect.py	Wed Jan 14 17:33:16 2015 +0000
@@ -0,0 +1,25 @@
+
+import vamp
+import numpy as np
+
+testPluginKey = "vamp-test-plugin:vamp-test-plugin"
+testPluginKeyFreq = "vamp-test-plugin:vamp-test-plugin-freq"
+
+rate = 44100
+
+# Throughout this file we have the assumption that the plugin gets run with a
+# blocksize of 1024, and with a step of 1024 for the time-domain version or 512
+# for the frequency-domain one. That is certainly expected to be the norm for a
+# plugin like this that declares no preference, and the Python Vamp module is
+# expected to follow the norm
+
+blocksize = 1024
+
+def input_data(n):
+    # start at 1, not 0 so that all elts are non-zero
+    return np.arange(n) + 1    
+
+def test_collect_runs_at_all():
+    buf = input_data(blocksize)
+    results = vamp.collect(buf, rate, testPluginKey, {}, "input-summary")
+    assert type(results) == dict
--- a/test/test_process.py	Wed Jan 14 17:19:04 2015 +0000
+++ b/test/test_process.py	Wed Jan 14 17:33:16 2015 +0000
@@ -111,5 +111,4 @@
         # half-way through the input buffer
         expected = i * (blocksize/2) + blocksize/2
         actual = results[i]["input-timestamp"]["values"][0]
-        print("actual = " + str(actual) + ", expected = " + str(expected))
         assert actual == expected
--- a/vamp/__init__.py	Wed Jan 14 17:19:04 2015 +0000
+++ b/vamp/__init__.py	Wed Jan 14 17:33:16 2015 +0000
@@ -71,9 +71,12 @@
     ff = framesFromArray(data, stepSize, blockSize)
     fi = 0
 
+    #!!! should we fill in the correct timestamps here?
+
     for f in ff:
         results = plug.processBlock(f, vampyhost.frame2RealTime(fi, samplerate))
         # results is a dict mapping output number -> list of feature dicts
+        print("results = " + str(results))
         for o in outputs:
             if outIndices[o] in results:
                 for r in results[outIndices[o]]:
@@ -89,3 +92,29 @@
     plug.unload()
 
 
+def collect(data, samplerate, key, parameters = {}, output = ""):
+    
+    plug, stepSize, blockSize = loadAndConfigureFor(data, samplerate, key, parameters)
+
+    plugOuts = plug.getOutputs()
+    if plugOuts == []:
+        return
+
+    outNo = -1
+    for n, o in zip(range(0, len(plugOuts)), plugOuts):
+        if output == "" or o["identifier"] == output:
+            outNo = n
+            break
+
+    assert outNo >= 0 #!!! todo proper error reporting
+
+    ff = framesFromArray(data, stepSize, blockSize)
+    fi = 0
+
+    #!!! todo!
+
+    plug.unload()
+    
+    return {}
+
+