# HG changeset patch # User Chris Cannam # Date 1421256796 0 # Node ID cb0380c92c4205d7448aca62d38c4640c00cb599 # Parent ffdeb8808fc1ace4f49d1191e15f843ef31df00c Stub out a collect() function which will (?) assemble a suitable structure from an entire run diff -r ffdeb8808fc1 -r cb0380c92c42 test/test_collect.py --- /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 diff -r ffdeb8808fc1 -r cb0380c92c42 test/test_process.py --- 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 diff -r ffdeb8808fc1 -r cb0380c92c42 vamp/__init__.py --- 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 {} + +