Mercurial > hg > vampy-host
comparison test/test_process.py @ 68:e15e684d2af4
Some tricky tests for returned values from the test plugin
author | Chris Cannam |
---|---|
date | Wed, 14 Jan 2015 14:31:01 +0000 |
parents | f0e2a8421797 |
children | b34d3b58da98 |
comparison
equal
deleted
inserted
replaced
67:6f6a54963ce8 | 68:e15e684d2af4 |
---|---|
5 testPluginKey = "vamp-test-plugin:vamp-test-plugin" | 5 testPluginKey = "vamp-test-plugin:vamp-test-plugin" |
6 testPluginKeyFreq = "vamp-test-plugin:vamp-test-plugin-freq" | 6 testPluginKeyFreq = "vamp-test-plugin:vamp-test-plugin-freq" |
7 | 7 |
8 rate = 44100 | 8 rate = 44100 |
9 | 9 |
10 def test_process(): | 10 # Throughout this file we have the assumption that the plugin gets run with a |
11 buf = np.zeros(10240) | 11 # blocksize of 1024, and with a step of 1024 for the time-domain version or 512 |
12 results = vamp.process(buf, rate, testPluginKey, {}, [ "input-timestamp" ]) | 12 # for the frequency-domain one. That is certainly expected to be the norm for a |
13 print("results = " + str(list(results))) | 13 # plugin like this that declares no preference, and the Python Vamp module is |
14 return True | 14 # expected to follow the norm |
15 | 15 |
16 def test_process_freq(): | 16 blocksize = 1024 |
17 buf = np.zeros(10240) | 17 |
18 results = vamp.process(buf, rate, testPluginKeyFreq, {}, [ "input-timestamp" ]) | 18 def input_data(n): |
19 print("results = " + str(list(results))) | 19 # start at 1, not 0 so that all elts are non-zero |
20 return True | 20 return np.arange(n) + 1 |
21 | |
22 def test_process_n(): | |
23 buf = input_data(blocksize) | |
24 results = list(vamp.process(buf, rate, testPluginKey, {}, [ "input-summary" ])) | |
25 assert len(results) == 1 | |
26 | |
27 def test_process_freq_n(): | |
28 buf = input_data(blocksize) | |
29 results = list(vamp.process(buf, rate, testPluginKeyFreq, {}, [ "input-summary" ])) | |
30 assert len(results) == 2 # one complete block starting at zero, one half-full | |
31 | |
32 def test_process_summary_param(): | |
33 buf = input_data(blocksize * 10) | |
34 results = list(vamp.process(buf, rate, testPluginKey, { "produce_output": 0 }, [ "input-summary" ])) | |
35 assert len(results) == 0 | |
36 | |
37 def test_process_summary_param_bool(): | |
38 buf = input_data(blocksize * 10) | |
39 results = list(vamp.process(buf, rate, testPluginKey, { "produce_output": False }, [ "input-summary" ])) | |
40 assert len(results) == 0 | |
41 | |
42 def test_process_summary(): | |
43 buf = input_data(blocksize * 10) | |
44 results = list(vamp.process(buf, rate, testPluginKey, {}, [ "input-summary" ])) | |
45 assert len(results) == 10 | |
46 # the input-summary output contains, for each process block, the value of | |
47 # the first sample in the process block input plus the number of samples | |
48 # above some epsilon | |
49 for i in range(len(results)): | |
50 # each feature has a single value, equal to the number of non-zero elts | |
51 # in the input block (which is all of them, i.e. the blocksize) plus | |
52 # the first elt (which is i * blockSize + 1) | |
53 expected = blocksize + i * blocksize + 1 | |
54 actual = results[i]["values"][0] | |
55 assert actual == expected | |
56 | |
57 def test_process_freq_summary(): | |
58 buf = input_data(blocksize * 10) | |
59 results = list(vamp.process(buf, rate, testPluginKeyFreq, {}, [ "input-summary" ])) | |
60 assert len(results) == 20 | |
61 for i in range(len(results)): | |
62 # | |
63 # sort of as above, but much much subtler: | |
64 # | |
65 # * the input block is converted to frequency domain but then converted | |
66 # back within the plugin, so the values being reported are time-domain | |
67 # ones but with windowing and FFT shift | |
68 # | |
69 # * the effect of FFT shift is that the first element in the | |
70 # re-converted frame is actually the one that was at the start of the | |
71 # second half of the original frame | |
72 # | |
73 # * and the last block is only half-full, so the "first" elt in that | |
74 # one, which actually comes from just after the middle of the block, | |
75 # will be zero | |
76 # | |
77 # * windowing does not affect the value of the first elt, because | |
78 # (before fft shift) it came from the peak of the window shape where | |
79 # the window value is 1 | |
80 # | |
81 # * but windowing does affect the number of non-zero elts, because the | |
82 # asymmetric window used has one value very close to zero in it | |
83 # | |
84 # * the step size (the increment in input value from one block to the | |
85 # next) is only half the block size | |
86 # | |
87 expected = i * (blocksize/2) + blocksize/2 + 1 # "first" elt | |
88 if (i == len(results)-1): | |
89 expected = 0 | |
90 expected = expected + blocksize - 1 # non-zero elts | |
91 actual = results[i]["values"][0] | |
92 eps = 1e-6 | |
93 assert abs(actual - expected) < eps | |
94 |