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