comparison test/test_process.py @ 112:9343eee50605

Update to Python 3. Currently crashes during tests (and also, two tests are now failing, even with Py2).
author Chris Cannam
date Wed, 17 Jun 2015 12:35:41 +0100
parents 0c5a4dc04ed9
children 3489986a044c 2370b942cd32
comparison
equal deleted inserted replaced
111:4f590fc46ace 112:9343eee50605
20 # start at 1, not 0 so that all elts are non-zero 20 # start at 1, not 0 so that all elts are non-zero
21 return np.arange(n) + 1 21 return np.arange(n) + 1
22 22
23 def test_process_n(): 23 def test_process_n():
24 buf = input_data(blocksize) 24 buf = input_data(blocksize)
25 results = list(vamp.process(buf, rate, plugin_key, "input-summary")) 25 results = list(vamp.process_audio(buf, rate, plugin_key, "input-summary"))
26 assert len(results) == 1 26 assert len(results) == 1
27 27
28 def test_process_freq_n(): 28 def test_process_freq_n():
29 buf = input_data(blocksize) 29 buf = input_data(blocksize)
30 results = list(vamp.process(buf, rate, plugin_key_freq, "input-summary", {})) 30 results = list(vamp.process_audio(buf, rate, plugin_key_freq, "input-summary", {}))
31 assert len(results) == 2 # one complete block starting at zero, one half-full 31 assert len(results) == 2 # one complete block starting at zero, one half-full
32 32
33 def test_process_default_output(): 33 def test_process_default_output():
34 # If no output is specified, we should get the first one (instants) 34 # If no output is specified, we should get the first one (instants)
35 buf = input_data(blocksize) 35 buf = input_data(blocksize)
36 results = list(vamp.process(buf, rate, plugin_key, "", {})) 36 results = list(vamp.process_audio(buf, rate, plugin_key, "", {}))
37 assert len(results) == 10 37 assert len(results) == 10
38 for i in range(len(results)): 38 for i in range(len(results)):
39 expectedTime = vamp.vampyhost.RealTime('seconds', i * 1.5) 39 expectedTime = vamp.vampyhost.RealTime('seconds', i * 1.5)
40 actualTime = results[i]["timestamp"] 40 actualTime = results[i]["timestamp"]
41 assert expectedTime == actualTime 41 assert expectedTime == actualTime
42 42
43 def test_process_summary_param(): 43 def test_process_summary_param():
44 buf = input_data(blocksize * 10) 44 buf = input_data(blocksize * 10)
45 results = list(vamp.process(buf, rate, plugin_key, "input-summary", { "produce_output": 0 })) 45 results = list(vamp.process_audio(buf, rate, plugin_key, "input-summary", { "produce_output": 0 }))
46 assert len(results) == 0 46 assert len(results) == 0
47 47
48 def test_process_multi_summary_param(): 48 def test_process_multi_summary_param():
49 buf = input_data(blocksize * 10) 49 buf = input_data(blocksize * 10)
50 results = list(vamp.process_multiple_outputs(buf, rate, plugin_key, [ "input-summary" ], { "produce_output": 0 })) 50 results = list(vamp.process_multiple_outputs(buf, rate, plugin_key, [ "input-summary" ], { "produce_output": 0 }))
51 assert len(results) == 0 51 assert len(results) == 0
52 52
53 def test_process_summary_param_bool(): 53 def test_process_summary_param_bool():
54 buf = input_data(blocksize * 10) 54 buf = input_data(blocksize * 10)
55 results = list(vamp.process(buf, rate, plugin_key, "input-summary", { "produce_output": False })) 55 results = list(vamp.process_audio(buf, rate, plugin_key, "input-summary", { "produce_output": False }))
56 assert len(results) == 0 56 assert len(results) == 0
57 57
58 def test_process_multi_summary_param_bool(): 58 def test_process_multi_summary_param_bool():
59 buf = input_data(blocksize * 10) 59 buf = input_data(blocksize * 10)
60 results = list(vamp.process_multiple_outputs(buf, rate, plugin_key, [ "input-summary" ], { "produce_output": False })) 60 results = list(vamp.process_multiple_outputs(buf, rate, plugin_key, [ "input-summary" ], { "produce_output": False }))
61 assert len(results) == 0 61 assert len(results) == 0
62 62
63 def test_process_summary(): 63 def test_process_summary():
64 buf = input_data(blocksize * 10) 64 buf = input_data(blocksize * 10)
65 results = list(vamp.process(buf, rate, plugin_key, "input-summary", {})) 65 results = list(vamp.process_audio(buf, rate, plugin_key, "input-summary", {}))
66 assert len(results) == 10 66 assert len(results) == 10
67 for i in range(len(results)): 67 for i in range(len(results)):
68 # 68 #
69 # each feature has a single value, equal to the number of non-zero elts 69 # each feature has a single value, equal to the number of non-zero elts
70 # in the input block (which is all of them, i.e. the blocksize) plus 70 # in the input block (which is all of them, i.e. the blocksize) plus
118 actual = results[i]["input-summary"]["values"][0] 118 actual = results[i]["input-summary"]["values"][0]
119 assert actual == expected 119 assert actual == expected
120 120
121 def test_process_freq_summary(): 121 def test_process_freq_summary():
122 buf = input_data(blocksize * 10) 122 buf = input_data(blocksize * 10)
123 results = list(vamp.process(buf, rate, plugin_key_freq, "input-summary", {})) 123 results = list(vamp.process_audio(buf, rate, plugin_key_freq, "input-summary", {}))
124 assert len(results) == 20 124 assert len(results) == 20
125 for i in range(len(results)): 125 for i in range(len(results)):
126 # 126 #
127 # sort of as above, but much much subtler: 127 # sort of as above, but much much subtler:
128 # 128 #
169 eps = 1e-6 169 eps = 1e-6
170 assert abs(actual - expected) < eps 170 assert abs(actual - expected) < eps
171 171
172 def test_process_timestamps(): 172 def test_process_timestamps():
173 buf = input_data(blocksize * 10) 173 buf = input_data(blocksize * 10)
174 results = list(vamp.process(buf, rate, plugin_key, "input-timestamp", {})) 174 results = list(vamp.process_audio(buf, rate, plugin_key, "input-timestamp", {}))
175 assert len(results) == 10 175 assert len(results) == 10
176 for i in range(len(results)): 176 for i in range(len(results)):
177 # The timestamp should be the frame number of the first frame in the 177 # The timestamp should be the frame number of the first frame in the
178 # input buffer 178 # input buffer
179 expected = i * blocksize 179 expected = i * blocksize
191 actual = results[i]["input-timestamp"]["values"][0] 191 actual = results[i]["input-timestamp"]["values"][0]
192 assert actual == expected 192 assert actual == expected
193 193
194 def test_process_freq_timestamps(): 194 def test_process_freq_timestamps():
195 buf = input_data(blocksize * 10) 195 buf = input_data(blocksize * 10)
196 results = list(vamp.process(buf, rate, plugin_key_freq, "input-timestamp", {})) 196 results = list(vamp.process_audio(buf, rate, plugin_key_freq, "input-timestamp", {}))
197 assert len(results) == 20 197 assert len(results) == 20
198 for i in range(len(results)): 198 for i in range(len(results)):
199 # The timestamp should be the frame number of the frame just beyond 199 # The timestamp should be the frame number of the frame just beyond
200 # half-way through the input buffer 200 # half-way through the input buffer
201 expected = i * (blocksize/2) + blocksize/2 201 expected = i * (blocksize/2) + blocksize/2