Mercurial > hg > vampy-host
comparison test/test_process.py @ 76:b2afd385586f
Split out process, processMultipleOutputs
author | Chris Cannam |
---|---|
date | Wed, 21 Jan 2015 12:13:45 +0000 |
parents | 78a4034c3830 |
children | a11b57e9fb0b |
comparison
equal
deleted
inserted
replaced
75:ad08a0fe6673 | 76:b2afd385586f |
---|---|
9 | 9 |
10 # Throughout this file we have the assumption that the plugin gets run with a | 10 # Throughout this file we have the assumption that the plugin gets run with a |
11 # blocksize of 1024, and with a step of 1024 for the time-domain version or 512 | 11 # blocksize of 1024, and with a step of 1024 for the time-domain version or 512 |
12 # for the frequency-domain one. That is certainly expected to be the norm for a | 12 # for the frequency-domain one. That is certainly expected to be the norm for a |
13 # plugin like this that declares no preference, and the Python Vamp module is | 13 # plugin like this that declares no preference, and the Python Vamp module is |
14 # expected to follow the norm | 14 # expected to follow the norm. |
15 | 15 |
16 blocksize = 1024 | 16 blocksize = 1024 |
17 | 17 |
18 def input_data(n): | 18 def input_data(n): |
19 # start at 1, not 0 so that all elts are non-zero | 19 # start at 1, not 0 so that all elts are non-zero |
20 return np.arange(n) + 1 | 20 return np.arange(n) + 1 |
21 | 21 |
22 def test_process_n(): | 22 def test_process_n(): |
23 buf = input_data(blocksize) | 23 buf = input_data(blocksize) |
24 results = list(vamp.process(buf, rate, testPluginKey, {}, [ "input-summary" ])) | 24 results = list(vamp.process(buf, rate, testPluginKey, "input-summary")) |
25 assert len(results) == 1 | 25 assert len(results) == 1 |
26 | 26 |
27 def test_process_freq_n(): | 27 def test_process_freq_n(): |
28 buf = input_data(blocksize) | 28 buf = input_data(blocksize) |
29 results = list(vamp.process(buf, rate, testPluginKeyFreq, {}, [ "input-summary" ])) | 29 results = list(vamp.process(buf, rate, testPluginKeyFreq, "input-summary", {})) |
30 assert len(results) == 2 # one complete block starting at zero, one half-full | 30 assert len(results) == 2 # one complete block starting at zero, one half-full |
31 | 31 |
32 def test_process_default_output(): | 32 def test_process_default_output(): |
33 # If no output is specified, we should get the first one (instants) | 33 # If no output is specified, we should get the first one (instants) |
34 buf = input_data(blocksize) | 34 buf = input_data(blocksize) |
35 results = list(vamp.process(buf, rate, testPluginKey, {}, [])) | 35 results = list(vamp.process(buf, rate, testPluginKey, "", {})) |
36 assert len(results) == 10 | 36 assert len(results) == 10 |
37 for i in range(len(results)): | 37 for i in range(len(results)): |
38 expectedTime = vamp.vampyhost.RealTime('seconds', i * 1.5) | 38 expectedTime = vamp.vampyhost.RealTime('seconds', i * 1.5) |
39 actualTime = results[i]["instants"]["timestamp"] | 39 actualTime = results[i]["timestamp"] |
40 assert expectedTime == actualTime | 40 assert expectedTime == actualTime |
41 | 41 |
42 def test_process_summary_param(): | 42 def test_process_summary_param(): |
43 buf = input_data(blocksize * 10) | 43 buf = input_data(blocksize * 10) |
44 results = list(vamp.process(buf, rate, testPluginKey, { "produce_output": 0 }, [ "input-summary" ])) | 44 results = list(vamp.process(buf, rate, testPluginKey, "input-summary", { "produce_output": 0 })) |
45 assert len(results) == 0 | |
46 | |
47 def test_process_multi_summary_param(): | |
48 buf = input_data(blocksize * 10) | |
49 results = list(vamp.processMultipleOutputs(buf, rate, testPluginKey, [ "input-summary" ], { "produce_output": 0 })) | |
45 assert len(results) == 0 | 50 assert len(results) == 0 |
46 | 51 |
47 def test_process_summary_param_bool(): | 52 def test_process_summary_param_bool(): |
48 buf = input_data(blocksize * 10) | 53 buf = input_data(blocksize * 10) |
49 results = list(vamp.process(buf, rate, testPluginKey, { "produce_output": False }, [ "input-summary" ])) | 54 results = list(vamp.process(buf, rate, testPluginKey, "input-summary", { "produce_output": False })) |
55 assert len(results) == 0 | |
56 | |
57 def test_process_multi_summary_param_bool(): | |
58 buf = input_data(blocksize * 10) | |
59 results = list(vamp.processMultipleOutputs(buf, rate, testPluginKey, [ "input-summary" ], { "produce_output": False })) | |
50 assert len(results) == 0 | 60 assert len(results) == 0 |
51 | 61 |
52 def test_process_summary(): | 62 def test_process_summary(): |
53 buf = input_data(blocksize * 10) | 63 buf = input_data(blocksize * 10) |
54 results = list(vamp.process(buf, rate, testPluginKey, {}, [ "input-summary" ])) | 64 results = list(vamp.process(buf, rate, testPluginKey, "input-summary", {})) |
55 assert len(results) == 10 | 65 assert len(results) == 10 |
56 for i in range(len(results)): | 66 for i in range(len(results)): |
57 # | 67 # |
58 # each feature has a single value, equal to the number of non-zero elts | 68 # each feature has a single value, equal to the number of non-zero elts |
59 # in the input block (which is all of them, i.e. the blocksize) plus | 69 # in the input block (which is all of them, i.e. the blocksize) plus |
60 # the first elt (which is i * blockSize + 1) | 70 # the first elt (which is i * blockSize + 1) |
61 # | 71 # |
62 expected = blocksize + i * blocksize + 1 | 72 expected = blocksize + i * blocksize + 1 |
73 actual = results[i]["values"][0] | |
74 assert actual == expected | |
75 | |
76 def test_process_multi_summary(): | |
77 buf = input_data(blocksize * 10) | |
78 results = list(vamp.processMultipleOutputs(buf, rate, testPluginKey, [ "input-summary" ], {})) | |
79 assert len(results) == 10 | |
80 for i in range(len(results)): | |
81 # | |
82 # each feature has a single value, equal to the number of non-zero elts | |
83 # in the input block (which is all of them, i.e. the blocksize) plus | |
84 # the first elt (which is i * blockSize + 1) | |
85 # | |
86 expected = blocksize + i * blocksize + 1 | |
63 actual = results[i]["input-summary"]["values"][0] | 87 actual = results[i]["input-summary"]["values"][0] |
64 assert actual == expected | 88 assert actual == expected |
65 | 89 |
66 def test_process_freq_summary(): | 90 def test_process_freq_summary(): |
67 buf = input_data(blocksize * 10) | 91 buf = input_data(blocksize * 10) |
68 results = list(vamp.process(buf, rate, testPluginKeyFreq, {}, [ "input-summary" ])) | 92 results = list(vamp.process(buf, rate, testPluginKeyFreq, "input-summary", {})) |
69 assert len(results) == 20 | 93 assert len(results) == 20 |
70 for i in range(len(results)): | 94 for i in range(len(results)): |
71 # | 95 # |
72 # sort of as above, but much much subtler: | 96 # sort of as above, but much much subtler: |
73 # | 97 # |
95 # | 119 # |
96 expected = i * (blocksize/2) + blocksize/2 + 1 # "first" elt | 120 expected = i * (blocksize/2) + blocksize/2 + 1 # "first" elt |
97 if (i == len(results)-1): | 121 if (i == len(results)-1): |
98 expected = 0 | 122 expected = 0 |
99 expected = expected + blocksize - 1 # non-zero elts | 123 expected = expected + blocksize - 1 # non-zero elts |
124 actual = results[i]["values"][0] | |
125 eps = 1e-6 | |
126 assert abs(actual - expected) < eps | |
127 | |
128 def test_process_multi_freq_summary(): | |
129 buf = input_data(blocksize * 10) | |
130 results = list(vamp.processMultipleOutputs(buf, rate, testPluginKeyFreq, [ "input-summary" ], {})) | |
131 assert len(results) == 20 | |
132 for i in range(len(results)): | |
133 expected = i * (blocksize/2) + blocksize/2 + 1 # "first" elt | |
134 if (i == len(results)-1): | |
135 expected = 0 | |
136 expected = expected + blocksize - 1 # non-zero elts | |
100 actual = results[i]["input-summary"]["values"][0] | 137 actual = results[i]["input-summary"]["values"][0] |
101 eps = 1e-6 | 138 eps = 1e-6 |
102 assert abs(actual - expected) < eps | 139 assert abs(actual - expected) < eps |
103 | 140 |
104 def test_process_timestamps(): | 141 def test_process_timestamps(): |
105 buf = input_data(blocksize * 10) | 142 buf = input_data(blocksize * 10) |
106 results = list(vamp.process(buf, rate, testPluginKey, {}, [ "input-timestamp" ])) | 143 results = list(vamp.process(buf, rate, testPluginKey, "input-timestamp", {})) |
144 assert len(results) == 10 | |
145 for i in range(len(results)): | |
146 # The timestamp should be the frame number of the first frame in the | |
147 # input buffer | |
148 expected = i * blocksize | |
149 actual = results[i]["values"][0] | |
150 assert actual == expected | |
151 | |
152 def test_process_multi_timestamps(): | |
153 buf = input_data(blocksize * 10) | |
154 results = list(vamp.processMultipleOutputs(buf, rate, testPluginKey, [ "input-timestamp" ])) | |
107 assert len(results) == 10 | 155 assert len(results) == 10 |
108 for i in range(len(results)): | 156 for i in range(len(results)): |
109 # The timestamp should be the frame number of the first frame in the | 157 # The timestamp should be the frame number of the first frame in the |
110 # input buffer | 158 # input buffer |
111 expected = i * blocksize | 159 expected = i * blocksize |
112 actual = results[i]["input-timestamp"]["values"][0] | 160 actual = results[i]["input-timestamp"]["values"][0] |
113 assert actual == expected | 161 assert actual == expected |
114 | 162 |
115 def test_process_freq_timestamps(): | 163 def test_process_freq_timestamps(): |
116 buf = input_data(blocksize * 10) | 164 buf = input_data(blocksize * 10) |
117 results = list(vamp.process(buf, rate, testPluginKeyFreq, {}, [ "input-timestamp" ])) | 165 results = list(vamp.process(buf, rate, testPluginKeyFreq, "input-timestamp", {})) |
166 assert len(results) == 20 | |
167 for i in range(len(results)): | |
168 # The timestamp should be the frame number of the frame just beyond | |
169 # half-way through the input buffer | |
170 expected = i * (blocksize/2) + blocksize/2 | |
171 actual = results[i]["values"][0] | |
172 assert actual == expected | |
173 | |
174 def test_process_multi_freq_timestamps(): | |
175 buf = input_data(blocksize * 10) | |
176 results = list(vamp.processMultipleOutputs(buf, rate, testPluginKeyFreq, [ "input-timestamp" ], {})) | |
118 assert len(results) == 20 | 177 assert len(results) == 20 |
119 for i in range(len(results)): | 178 for i in range(len(results)): |
120 # The timestamp should be the frame number of the frame just beyond | 179 # The timestamp should be the frame number of the frame just beyond |
121 # half-way through the input buffer | 180 # half-way through the input buffer |
122 expected = i * (blocksize/2) + blocksize/2 | 181 expected = i * (blocksize/2) + blocksize/2 |
123 actual = results[i]["input-timestamp"]["values"][0] | 182 actual = results[i]["input-timestamp"]["values"][0] |
124 assert actual == expected | 183 assert actual == expected |
125 | 184 |
126 def test_process_multiple_outputs(): | 185 def test_process_multiple_outputs(): |
127 buf = input_data(blocksize * 10) | 186 buf = input_data(blocksize * 10) |
128 results = list(vamp.process(buf, rate, testPluginKey, {}, [ "input-summary", "input-timestamp" ])) | 187 results = list(vamp.processMultipleOutputs(buf, rate, testPluginKey, [ "input-summary", "input-timestamp" ], {})) |
129 assert len(results) == 20 | 188 assert len(results) == 20 |
130 si = 0 | 189 si = 0 |
131 ti = 0 | 190 ti = 0 |
132 for r in results: | 191 for r in results: |
133 assert "input-summary" in r or "input-timestamp" in r | 192 assert "input-summary" in r or "input-timestamp" in r |