Mercurial > hg > vampy-host
changeset 150:37d2fd57723e tracks
Restore backward compatibility for last change: return vector as well as tracks
author | Chris Cannam |
---|---|
date | Fri, 21 Apr 2017 14:22:42 +0100 |
parents | 65eeb604253f |
children | 5a6b8f4be9b9 |
files | test/test_collect.py vamp/collect.py |
diffstat | 2 files changed, 33 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/test/test_collect.py Fri Apr 21 13:09:41 2017 +0100 +++ b/test/test_collect.py Fri Apr 21 14:22:42 2017 +0100 @@ -90,7 +90,24 @@ for i in range(len(results)): assert abs(results[i] - i * 0.1) < eps -def test_collect_fixed_sample_rate_2(): +def test_collect_fixed_sample_rate_2_vector(): + # This one has discontinuities and overlaps, so it should be + # returned to us in two forms: as a simple vector, and as an + # additional tracks shape with one vector for each separate + # bit. This test covers the simple vector part + buf = input_data(blocksize * 10) + rdict = vamp.collect(buf, rate, plugin_key, "curve-fsr-timed") + step, results = rdict["vector"] + assert abs(float(step) - 0.4) < eps + assert len(results) == 10 + for i in range(len(results)): + assert abs(results[i] - i * 0.1) < eps + +def test_collect_fixed_sample_rate_2_tracks(): + # This one has discontinuities and overlaps, so it should be + # returned to us in two forms: as a simple vector, and as an + # additional tracks shape with one vector for each separate + # bit. This test covers the tracks part. buf = input_data(blocksize * 10) rdict = vamp.collect(buf, rate, plugin_key, "curve-fsr-timed") results = rdict["tracks"]
--- a/vamp/collect.py Fri Apr 21 13:09:41 2017 +0100 +++ b/vamp/collect.py Fri Apr 21 14:22:42 2017 +0100 @@ -89,11 +89,11 @@ return "vector" return "matrix" - -def reshape_vector(results, out_step, output_desc): +def populate_reshaped_vector(results, out_step, output_desc, return_dict): output = output_desc["identifier"] tracks = [] + whole = [] current_track = [] current_start_time = 0 out_step_secs = out_step.to_float() @@ -103,6 +103,7 @@ for r in results: f = r[output] n = n + 1 + whole.append(f["values"][0]) if output_desc["sampleType"] == vampyhost.FIXED_SAMPLE_RATE: if "timestamp" in f: m = int(round(f["timestamp"].to_float() / out_step_secs)) @@ -121,28 +122,24 @@ tracks.append({ "start": current_start_time, "step": out_step, "values": np.array(current_track, np.float32) }) - return ("tracks", tracks) - else: - return ("vector", (out_step, np.array(current_track, np.float32))) + return_dict["tracks"] = tracks - -def reshape(results, sample_rate, step_size, output_desc, shape): + return_dict["vector"] = (out_step, whole) + +def populate_reshaped_features(results, sample_rate, step_size, output_desc, shape, return_dict): output = output_desc["identifier"] out_step = get_feature_step_time(sample_rate, step_size, output_desc) adjusted_shape = shape if shape == "vector": - (adjusted_shape, rv) = reshape_vector(results, out_step, output_desc) + populate_reshaped_vector(results, out_step, output_desc, return_dict) elif shape == "matrix": #!!! todo: check that each feature has the right number of bins? outseq = [r[output]["values"] for r in results] - rv = ( out_step, np.array(outseq, np.float32) ) + return_dict[shape] = (out_step, np.array(outseq, np.float32)) else: - rv = list(fill_timestamps(results, sample_rate, step_size, output_desc)) - - return (adjusted_shape, rv) - + return_dict[shape] = list(fill_timestamps(results, sample_rate, step_size, output_desc)) def collect(data, sample_rate, plugin_key, output = "", parameters = {}, **kwargs): """Process audio data with a Vamp plugin, and make the results from a @@ -223,7 +220,10 @@ results = vamp.process.process_with_initialised_plugin(ff, sample_rate, step_size, plugin, [output]) shape = deduce_shape(output_desc) - (adjusted_shape, rv) = reshape(results, sample_rate, step_size, output_desc, shape) + return_dict = {} + populate_reshaped_features(results, sample_rate, step_size, output_desc, shape, return_dict) + + print("return_dict now = " + str(return_dict)) plugin.unload() - return { adjusted_shape : rv } + return return_dict