cannam@5
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
cannam@5
|
2
|
cannam@5
|
3 /*
|
cannam@5
|
4 Vamp Plugin Tester
|
cannam@5
|
5 Chris Cannam, cannam@all-day-breakfast.com
|
cannam@5
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@42
|
7 Copyright 2009-2014 QMUL.
|
cannam@5
|
8
|
cannam@5
|
9 This program loads a Vamp plugin and tests its susceptibility to a
|
cannam@5
|
10 number of common pitfalls, including handling of extremes of input
|
cannam@5
|
11 data. If you can think of any additional useful tests that are
|
cannam@5
|
12 easily added, please send them to me.
|
cannam@5
|
13
|
cannam@5
|
14 Permission is hereby granted, free of charge, to any person
|
cannam@5
|
15 obtaining a copy of this software and associated documentation
|
cannam@5
|
16 files (the "Software"), to deal in the Software without
|
cannam@5
|
17 restriction, including without limitation the rights to use, copy,
|
cannam@5
|
18 modify, merge, publish, distribute, sublicense, and/or sell copies
|
cannam@5
|
19 of the Software, and to permit persons to whom the Software is
|
cannam@5
|
20 furnished to do so, subject to the following conditions:
|
cannam@5
|
21
|
cannam@5
|
22 The above copyright notice and this permission notice shall be
|
cannam@5
|
23 included in all copies or substantial portions of the Software.
|
cannam@5
|
24
|
cannam@5
|
25 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
cannam@5
|
26 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
cannam@5
|
27 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
cannam@5
|
28 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
cannam@5
|
29 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
cannam@5
|
30 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
cannam@5
|
31 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
cannam@5
|
32
|
cannam@5
|
33 Except as contained in this notice, the names of the Centre for
|
cannam@5
|
34 Digital Music; Queen Mary, University of London; and Chris Cannam
|
cannam@5
|
35 shall not be used in advertising or otherwise to promote the sale,
|
cannam@5
|
36 use or other dealings in this Software without prior written
|
cannam@5
|
37 authorization.
|
cannam@5
|
38 */
|
cannam@5
|
39
|
cannam@5
|
40 #include "TestDefaults.h"
|
cannam@5
|
41
|
cannam@5
|
42 #include <vamp-hostsdk/Plugin.h>
|
cannam@5
|
43 using namespace Vamp;
|
cannam@5
|
44
|
cannam@5
|
45 #include <memory>
|
cannam@5
|
46 using namespace std;
|
cannam@5
|
47
|
cannam@5
|
48 #include <cmath>
|
cannam@6
|
49 #include <time.h>
|
cannam@5
|
50
|
cannam@5
|
51 Tester::TestRegistrar<TestDefaultProgram>
|
Chris@39
|
52 TestDefaultProgram::m_registrar("E1", "Inconsistent default program");
|
cannam@5
|
53
|
cannam@5
|
54 Tester::TestRegistrar<TestDefaultParameters>
|
Chris@39
|
55 TestDefaultParameters::m_registrar("E2", "Inconsistent default parameters");
|
cannam@5
|
56
|
Chris@34
|
57 Tester::TestRegistrar<TestParametersOnReset>
|
Chris@39
|
58 TestParametersOnReset::m_registrar("E3", "Parameter retention through reset");
|
Chris@34
|
59
|
cannam@5
|
60 static const size_t _step = 1000;
|
cannam@5
|
61
|
cannam@5
|
62 Test::Results
|
cannam@8
|
63 TestDefaultProgram::test(string key, Options options)
|
cannam@5
|
64 {
|
cannam@5
|
65 Plugin::FeatureSet f[2];
|
cannam@5
|
66 int rate = 44100;
|
cannam@5
|
67 Results r;
|
cannam@5
|
68 float **data = 0;
|
cannam@5
|
69 size_t channels = 0;
|
cannam@5
|
70 size_t count = 100;
|
cannam@5
|
71
|
cannam@5
|
72 for (int run = 0; run < 2; ++run) {
|
cannam@5
|
73 auto_ptr<Plugin> p(load(key, rate));
|
cannam@5
|
74 if (p->getPrograms().empty()) return r;
|
cannam@5
|
75 if (run == 1) {
|
cannam@5
|
76 p->selectProgram(p->getCurrentProgram());
|
cannam@5
|
77 }
|
cannam@5
|
78 if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
|
cannam@5
|
79 if (!data) data = createTestAudio(channels, _step, count);
|
cannam@5
|
80 for (size_t i = 0; i < count; ++i) {
|
Chris@67
|
81 float **ptr = new float *[channels];
|
cannam@5
|
82 size_t idx = i * _step;
|
cannam@5
|
83 for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
|
cannam@5
|
84 RealTime timestamp = RealTime::frame2RealTime(idx, rate);
|
cannam@5
|
85 Plugin::FeatureSet fs = p->process(ptr, timestamp);
|
Chris@67
|
86 delete[] ptr;
|
cannam@5
|
87 appendFeatures(f[run], fs);
|
cannam@5
|
88 }
|
cannam@5
|
89 Plugin::FeatureSet fs = p->getRemainingFeatures();
|
cannam@5
|
90 appendFeatures(f[run], fs);
|
cannam@5
|
91 }
|
cannam@5
|
92 if (data) destroyTestAudio(data, channels);
|
cannam@5
|
93
|
cannam@5
|
94 if (!(f[0] == f[1])) {
|
cannam@8
|
95 string message = "Explicitly setting current program to its supposed current value changes the results";
|
cannam@8
|
96 Result res;
|
cannam@8
|
97 if (options & NonDeterministic) res = note(message);
|
cannam@8
|
98 else res = error(message);
|
Chris@52
|
99 if (options & Verbose) dumpDiff(res, f[0], f[1]);
|
cannam@7
|
100 r.push_back(res);
|
cannam@5
|
101 } else {
|
cannam@5
|
102 r.push_back(success());
|
cannam@5
|
103 }
|
cannam@5
|
104
|
cannam@5
|
105 return r;
|
cannam@5
|
106 }
|
cannam@5
|
107
|
cannam@5
|
108 Test::Results
|
cannam@8
|
109 TestDefaultParameters::test(string key, Options options)
|
cannam@5
|
110 {
|
cannam@5
|
111 Plugin::FeatureSet f[2];
|
cannam@5
|
112 int rate = 44100;
|
cannam@5
|
113 Results r;
|
cannam@5
|
114 float **data = 0;
|
cannam@5
|
115 size_t channels = 0;
|
cannam@5
|
116 size_t count = 100;
|
cannam@5
|
117
|
cannam@5
|
118 for (int run = 0; run < 2; ++run) {
|
cannam@5
|
119 auto_ptr<Plugin> p(load(key, rate));
|
cannam@5
|
120 if (p->getParameterDescriptors().empty()) return r;
|
cannam@5
|
121 if (run == 1) {
|
cannam@5
|
122 Plugin::ParameterList pl = p->getParameterDescriptors();
|
cannam@5
|
123 for (int i = 0; i < (int)pl.size(); ++i) {
|
cannam@5
|
124 if (p->getParameter(pl[i].identifier) != pl[i].defaultValue) {
|
cannam@23
|
125 if (options & Verbose) {
|
cannam@23
|
126 cout << "Parameter: " << pl[i].identifier << endl;
|
cannam@23
|
127 cout << "Expected: " << pl[i].defaultValue << endl;
|
cannam@23
|
128 cout << "Actual: " << p->getParameter(pl[i].identifier) << endl;
|
cannam@23
|
129 }
|
cannam@5
|
130 r.push_back(error("Not all parameters have their default values when queried directly after construction"));
|
cannam@5
|
131 }
|
cannam@5
|
132 p->setParameter(pl[i].identifier, pl[i].defaultValue);
|
cannam@5
|
133 }
|
cannam@5
|
134 }
|
cannam@5
|
135 if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
|
cannam@5
|
136 if (!data) data = createTestAudio(channels, _step, count);
|
cannam@5
|
137 for (size_t i = 0; i < count; ++i) {
|
Chris@67
|
138 float **ptr = new float *[channels];
|
cannam@5
|
139 size_t idx = i * _step;
|
cannam@5
|
140 for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
|
cannam@5
|
141 RealTime timestamp = RealTime::frame2RealTime(idx, rate);
|
cannam@5
|
142 Plugin::FeatureSet fs = p->process(ptr, timestamp);
|
Chris@67
|
143 delete[] ptr;
|
cannam@5
|
144 appendFeatures(f[run], fs);
|
cannam@5
|
145 }
|
cannam@5
|
146 Plugin::FeatureSet fs = p->getRemainingFeatures();
|
cannam@5
|
147 appendFeatures(f[run], fs);
|
cannam@5
|
148 }
|
cannam@5
|
149 if (data) destroyTestAudio(data, channels);
|
cannam@5
|
150
|
cannam@5
|
151 if (!(f[0] == f[1])) {
|
cannam@8
|
152 string message = "Explicitly setting parameters to their supposed default values changes the results";
|
cannam@8
|
153 Result res;
|
cannam@8
|
154 if (options & NonDeterministic) res = note(message);
|
cannam@8
|
155 else res = error(message);
|
Chris@52
|
156 if (options & Verbose) dumpDiff(res, f[0], f[1]);
|
cannam@7
|
157 r.push_back(res);
|
cannam@5
|
158 } else {
|
cannam@5
|
159 r.push_back(success());
|
cannam@5
|
160 }
|
cannam@5
|
161
|
cannam@5
|
162 return r;
|
cannam@5
|
163 }
|
Chris@34
|
164
|
Chris@34
|
165 Test::Results
|
Chris@34
|
166 TestParametersOnReset::test(string key, Options options)
|
Chris@34
|
167 {
|
Chris@34
|
168 Plugin::FeatureSet f[2];
|
Chris@34
|
169 int rate = 44100;
|
Chris@34
|
170 Results r;
|
Chris@34
|
171 float **data = 0;
|
Chris@34
|
172 size_t channels = 0;
|
Chris@34
|
173 size_t count = 100;
|
Chris@34
|
174
|
Chris@34
|
175 for (int run = 0; run < 2; ++run) {
|
Chris@34
|
176 auto_ptr<Plugin> p(load(key, rate));
|
Chris@34
|
177 if (p->getParameterDescriptors().empty()) return r;
|
Chris@34
|
178
|
Chris@34
|
179 // Set all parameters to non-default values
|
Chris@36
|
180
|
Chris@34
|
181 Plugin::ParameterList pl = p->getParameterDescriptors();
|
Chris@36
|
182
|
Chris@34
|
183 for (int i = 0; i < (int)pl.size(); ++i) {
|
Chris@36
|
184
|
Chris@36
|
185 // Half-way between default and max value, seems a
|
Chris@36
|
186 // reasonable guess for something to set it to. We want to
|
Chris@36
|
187 // avoid the real extremes because they can sometimes be
|
Chris@36
|
188 // very slow, and we want to avoid setting everything to
|
Chris@36
|
189 // the same values (e.g. min) because plugins will
|
Chris@36
|
190 // sometimes legitimately reject that.
|
Chris@36
|
191
|
Chris@36
|
192 // Remember to take into account quantization
|
Chris@36
|
193
|
Chris@36
|
194 float value = (pl[i].defaultValue + pl[i].maxValue) / 2;
|
Chris@36
|
195
|
Chris@36
|
196 if (pl[i].isQuantized) {
|
Chris@36
|
197 value = round(value / pl[i].quantizeStep) * pl[i].quantizeStep;
|
Chris@34
|
198 }
|
Chris@36
|
199
|
Chris@36
|
200 if (value > pl[i].maxValue) {
|
Chris@36
|
201 value = pl[i].maxValue;
|
Chris@36
|
202 }
|
Chris@36
|
203 if (value < pl[i].minValue) {
|
Chris@36
|
204 value = pl[i].minValue;
|
Chris@36
|
205 }
|
Chris@36
|
206 if (value == pl[i].defaultValue) {
|
Chris@36
|
207 if (pl[i].defaultValue == pl[i].minValue) {
|
Chris@36
|
208 value = pl[i].maxValue;
|
Chris@36
|
209 } else {
|
Chris@36
|
210 value = pl[i].minValue;
|
Chris@36
|
211 }
|
Chris@36
|
212 }
|
Chris@36
|
213
|
Chris@36
|
214 p->setParameter(pl[i].identifier, value);
|
Chris@34
|
215 }
|
Chris@34
|
216
|
Chris@52
|
217 if (!initAdapted(p.get(), channels, _step, _step, r)) {
|
Chris@52
|
218
|
Chris@52
|
219 // OK, plugin didn't like that. Let's try a different tack
|
Chris@52
|
220 // -- set everything to min except those parameters whose
|
Chris@52
|
221 // default is min, and set those to half way instead
|
Chris@52
|
222
|
Chris@52
|
223 for (int i = 0; i < (int)pl.size(); ++i) {
|
Chris@52
|
224 float value = pl[i].minValue;
|
Chris@52
|
225 if (value == pl[i].defaultValue) {
|
Chris@52
|
226 value = (pl[i].maxValue + pl[i].minValue) / 2;
|
Chris@52
|
227 value = ceil(value / pl[i].quantizeStep) * pl[i].quantizeStep;
|
Chris@52
|
228 if (value > pl[i].maxValue) {
|
Chris@52
|
229 value = pl[i].maxValue;
|
Chris@52
|
230 }
|
Chris@52
|
231 }
|
Chris@52
|
232 p->setParameter(pl[i].identifier, value);
|
Chris@52
|
233 }
|
Chris@52
|
234
|
Chris@52
|
235 r = Results();
|
Chris@52
|
236 if (!initAdapted(p.get(), channels, _step, _step, r)) {
|
Chris@52
|
237 // Still didn't work, give up
|
Chris@52
|
238 return r;
|
Chris@52
|
239 }
|
Chris@52
|
240 }
|
Chris@34
|
241
|
Chris@34
|
242 // First run: construct, set params, init, process
|
Chris@34
|
243 // Second run: construct, set params, init, reset, process
|
Chris@34
|
244 // We expect these to produce the same results
|
Chris@34
|
245 if (run == 1) p->reset();
|
Chris@34
|
246
|
Chris@34
|
247 if (!data) data = createTestAudio(channels, _step, count);
|
Chris@34
|
248 for (size_t i = 0; i < count; ++i) {
|
Chris@67
|
249 float **ptr = new float *[channels];
|
Chris@34
|
250 size_t idx = i * _step;
|
Chris@34
|
251 for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
|
Chris@34
|
252 RealTime timestamp = RealTime::frame2RealTime(idx, rate);
|
Chris@34
|
253 Plugin::FeatureSet fs = p->process(ptr, timestamp);
|
Chris@67
|
254 delete[] ptr;
|
Chris@34
|
255 appendFeatures(f[run], fs);
|
Chris@34
|
256 }
|
Chris@34
|
257 Plugin::FeatureSet fs = p->getRemainingFeatures();
|
Chris@34
|
258 appendFeatures(f[run], fs);
|
Chris@34
|
259 }
|
Chris@34
|
260 if (data) destroyTestAudio(data, channels);
|
Chris@34
|
261
|
Chris@34
|
262 if (!(f[0] == f[1])) {
|
Chris@34
|
263 string message = "Call to reset after setting parameters, but before processing, changes the results (parameter values not retained through reset?)";
|
Chris@34
|
264 Result res;
|
Chris@34
|
265 if (options & NonDeterministic) res = note(message);
|
Chris@34
|
266 else res = error(message);
|
Chris@52
|
267 if (options & Verbose) dumpDiff(res, f[0], f[1]);
|
Chris@34
|
268 r.push_back(res);
|
Chris@34
|
269 } else {
|
Chris@34
|
270 r.push_back(success());
|
Chris@34
|
271 }
|
Chris@34
|
272
|
Chris@34
|
273 return r;
|
Chris@34
|
274 }
|