annotate test/test_collect.py @ 97:06c4afba4fc5

Fix matrix return
author Chris Cannam
date Tue, 03 Feb 2015 10:29:21 +0000
parents f0e005248b9a
children 0c5a4dc04ed9
rev   line source
Chris@71 1
Chris@71 2 import vamp
Chris@71 3 import numpy as np
Chris@71 4
Chris@82 5 plugin_key = "vamp-test-plugin:vamp-test-plugin"
Chris@82 6 plugin_key_freq = "vamp-test-plugin:vamp-test-plugin-freq"
Chris@71 7
Chris@71 8 rate = 44100
Chris@71 9
Chris@71 10 # Throughout this file we have the assumption that the plugin gets run with a
Chris@71 11 # blocksize of 1024, and with a step of 1024 for the time-domain version or 512
Chris@71 12 # for the frequency-domain one. That is certainly expected to be the norm for a
Chris@71 13 # plugin like this that declares no preference, and the Python Vamp module is
Chris@71 14 # expected to follow the norm
Chris@71 15
Chris@71 16 blocksize = 1024
Chris@92 17 eps = 1e-6
Chris@71 18
Chris@71 19 def input_data(n):
Chris@71 20 # start at 1, not 0 so that all elts are non-zero
Chris@71 21 return np.arange(n) + 1
Chris@71 22
Chris@71 23 def test_collect_runs_at_all():
Chris@88 24 buf = input_data(blocksize * 10)
Chris@94 25 step, results = vamp.collect(buf, rate, plugin_key, "input-timestamp")
Chris@88 26 assert results != []
Chris@88 27
Chris@96 28 ##!!! add test for default output
Chris@96 29
Chris@88 30 def test_collect_one_sample_per_step():
Chris@88 31 buf = input_data(blocksize * 10)
Chris@94 32 step, results = vamp.collect(buf, rate, plugin_key, "input-timestamp")
Chris@94 33 assert abs(float(step) - (1024.0 / rate)) < eps
Chris@88 34 assert len(results) == 10
Chris@93 35 for i in range(len(results)):
Chris@93 36 # The timestamp should be the frame number of the first frame in the
Chris@93 37 # input buffer
Chris@93 38 expected = i * blocksize
Chris@93 39 actual = results[i]
Chris@93 40 assert actual == expected
Chris@88 41
Chris@92 42 def test_collect_fixed_sample_rate():
Chris@92 43 buf = input_data(blocksize * 10)
Chris@94 44 step, results = vamp.collect(buf, rate, plugin_key, "curve-fsr")
Chris@94 45 assert abs(float(step) - 0.4) < eps
Chris@92 46 assert len(results) == 10
Chris@93 47 for i in range(len(results)):
Chris@93 48 assert abs(results[i] - i * 0.1) < eps
Chris@92 49
Chris@92 50 def test_collect_fixed_sample_rate_2():
Chris@92 51 buf = input_data(blocksize * 10)
Chris@94 52 step, results = vamp.collect(buf, rate, plugin_key, "curve-fsr-timed")
Chris@94 53 assert abs(float(step) - 0.4) < eps
Chris@92 54 assert len(results) == 10
Chris@93 55 for i in range(len(results)):
Chris@93 56 assert abs(results[i] - i * 0.1) < eps
Chris@92 57
Chris@92 58 def test_collect_variable_sample_rate():
Chris@92 59 buf = input_data(blocksize * 10)
Chris@94 60 results = vamp.collect(buf, rate, plugin_key, "curve-vsr")
Chris@92 61 assert len(results) == 10
Chris@92 62 i = 0
Chris@92 63 for r in results:
Chris@92 64 assert r["timestamp"] == vamp.vampyhost.RealTime('seconds', i * 0.75)
Chris@92 65 assert abs(r["values"][0] - i * 0.1) < eps
Chris@92 66 i = i + 1
Chris@96 67
Chris@96 68 def test_collect_grid_one_sample_per_step():
Chris@96 69 buf = input_data(blocksize * 10)
Chris@96 70 step, results = vamp.collect(buf, rate, plugin_key, "grid-oss")
Chris@96 71 assert abs(float(step) - (1024.0 / rate)) < eps
Chris@96 72 assert len(results) == 10
Chris@96 73 for i in range(len(results)):
Chris@97 74 expected = np.array([ (j + i + 2.0) / 30.0 for j in range(0, 10) ])
Chris@97 75 assert (abs(results[i] - expected) < eps).all()