# HG changeset patch # User Chris Cannam # Date 1421853180 0 # Node ID 7228921e842571dc907607eaae01d69c2101021c # Parent dd56716714e0118d1b5753db78217f915474ccb5 Some way to implementing collect() diff -r dd56716714e0 -r 7228921e8425 test/test_collect.py --- a/test/test_collect.py Wed Jan 21 15:04:05 2015 +0000 +++ b/test/test_collect.py Wed Jan 21 15:13:00 2015 +0000 @@ -20,6 +20,14 @@ return np.arange(n) + 1 def test_collect_runs_at_all(): - buf = input_data(blocksize) - results = vamp.collect(buf, rate, plugin_key, "input-summary") - assert type(results) == dict + buf = input_data(blocksize * 10) + results = list(vamp.collect(buf, rate, plugin_key, "input-timestamp")) + assert results != [] + +def test_collect_one_sample_per_step(): + buf = input_data(blocksize * 10) + results = list(vamp.collect(buf, rate, plugin_key, "input-timestamp")) + assert len(results) == 10 + for r in results: + assert r["timestamp"] == vamp.vampyhost.frame_to_realtime(r["values"][0], rate) + diff -r dd56716714e0 -r 7228921e8425 vamp/collect.py --- a/vamp/collect.py Wed Jan 21 15:04:05 2015 +0000 +++ b/vamp/collect.py Wed Jan 21 15:13:00 2015 +0000 @@ -2,15 +2,7 @@ import vampyhost import load -import frames - -##!!! -## -## We could also devise a generator for the timestamps that need -## filling: provide the output type & rate and get back a timestamp -## generator -## -##!!! +import process def timestamp_features(sample_rate, step_size, output_desc, features): n = -1 @@ -35,28 +27,19 @@ def collect(data, sample_rate, key, output, parameters = {}): - + plug, step_size, block_size = load.load_and_configure(data, sample_rate, key, parameters) - plug_outs = plug.get_outputs() - if plug_outs == []: - return - - outNo = -1 - for n, o in zip(range(0, len(plug_outs)), plug_outs): - if output == "" or o["identifier"] == output: - outNo = n - break - - assert outNo >= 0 #!!! todo proper error reporting - - ff = frames.frames_from_array(data, step_size, block_size) - fi = 0 - - #!!! todo! + if output == "": + out = plug.get_output(0) + else: + out = plug.get_output(output) plug.unload() - - return {} + + results = process.process(data, sample_rate, key, output, parameters) + + return timestamp_features(sample_rate, step_size, out, results) +