changeset 74:78a4034c3830

Multi-output features & start on feature select/timestamp/collect
author Chris Cannam
date Wed, 21 Jan 2015 11:08:29 +0000
parents c12589026ff4
children ad08a0fe6673
files test/test_process.py vamp/__init__.py
diffstat 2 files changed, 55 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/test/test_process.py	Wed Jan 21 11:06:03 2015 +0000
+++ b/test/test_process.py	Wed Jan 21 11:08:29 2015 +0000
@@ -29,6 +29,16 @@
     results = list(vamp.process(buf, rate, testPluginKeyFreq, {}, [ "input-summary" ]))
     assert len(results) == 2 # one complete block starting at zero, one half-full
 
+def test_process_default_output():
+    # If no output is specified, we should get the first one (instants)
+    buf = input_data(blocksize)
+    results = list(vamp.process(buf, rate, testPluginKey, {}, []))
+    assert len(results) == 10
+    for i in range(len(results)):
+        expectedTime = vamp.vampyhost.RealTime('seconds', i * 1.5)
+        actualTime = results[i]["instants"]["timestamp"]
+        assert expectedTime == actualTime
+    
 def test_process_summary_param():
     buf = input_data(blocksize * 10)
     results = list(vamp.process(buf, rate, testPluginKey, { "produce_output": 0 }, [ "input-summary" ]))
@@ -112,3 +122,22 @@
         expected = i * (blocksize/2) + blocksize/2
         actual = results[i]["input-timestamp"]["values"][0]
         assert actual == expected
+
+def test_process_multiple_outputs():
+    buf = input_data(blocksize * 10)
+    results = list(vamp.process(buf, rate, testPluginKey, {}, [ "input-summary", "input-timestamp" ]))
+    assert len(results) == 20
+    si = 0
+    ti = 0
+    for r in results:
+        assert "input-summary" in r or "input-timestamp" in r
+        if "input-summary" in r:
+            expected = blocksize + si * blocksize + 1
+            actual = r["input-summary"]["values"][0]
+            assert actual == expected
+            si = si + 1
+        if "input-timestamp" in r:
+            expected = ti * blocksize
+            actual = r["input-timestamp"]["values"][0]
+            assert actual == expected
+            ti = ti + 1
--- a/vamp/__init__.py	Wed Jan 21 11:06:03 2015 +0000
+++ b/vamp/__init__.py	Wed Jan 21 11:08:29 2015 +0000
@@ -27,8 +27,8 @@
         i = i + stepSize
 
 
-def loadAndConfigureFor(data, samplerate, key, parameters):
-    plug = vampyhost.loadPlugin(key, samplerate,
+def loadAndConfigureFor(data, sampleRate, key, parameters):
+    plug = vampyhost.loadPlugin(key, sampleRate,
                                 vampyhost.AdaptInputDomain +
                                 vampyhost.AdaptChannelCount)
 
@@ -50,10 +50,10 @@
     return (plug, stepSize, blockSize)
 
 
-def process(data, samplerate, key, parameters = {}, outputs = []):
+def process(data, sampleRate, key, parameters = {}, outputs = []):
 #!!! docstring
 
-    plug, stepSize, blockSize = loadAndConfigureFor(data, samplerate, key, parameters)
+    plug, stepSize, blockSize = loadAndConfigureFor(data, sampleRate, key, parameters)
 
     plugOuts = plug.getOutputs()
     if plugOuts == []:
@@ -74,9 +74,8 @@
     #!!! should we fill in the correct timestamps here?
 
     for f in ff:
-        results = plug.processBlock(f, vampyhost.frame2RealTime(fi, samplerate))
+        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]]:
@@ -92,6 +91,12 @@
     plug.unload()
 
 
+def selectFeaturesForOutput(output, features):
+    for ff in features:
+        if output in ff:
+            for f in ff[output]:
+                yield f
+
 ##!!!
 ##
 ## We could also devise a generator for the timestamps that need
@@ -100,10 +105,23 @@
 ##
 ##!!!
 
+# def timestampFeatures(sampleRate, stepSize, outputDescriptor, features):
 
-def collect(data, samplerate, key, parameters = {}, output = ""):
+#     n = 0
     
-    plug, stepSize, blockSize = loadAndConfigureFor(data, samplerate, key, parameters)
+#     if outputDict.sampleType == vampyhost.OneSamplePerStep:
+#         for True:
+#             yield vampyhost.frame2RealTime(n * stepSize, sampleRate)
+#             n = n + 1
+
+#     elif outputDict.sampleType == vampyhost.FixedSampleRate:
+#         for True:
+            
+
+
+def collect(data, sampleRate, key, parameters = {}, output = ""):
+    
+    plug, stepSize, blockSize = loadAndConfigureFor(data, sampleRate, key, parameters)
 
     plugOuts = plug.getOutputs()
     if plugOuts == []: