To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / TestMultipleRuns.cpp @ 42:f1e8e14e9c96
History | View | Annotate | Download (8.5 KB)
| 1 | 2:c9a4bd247497 | 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 | 2:c9a4bd247497 | 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 "TestMultipleRuns.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 | |||
| 50 | 28:b1bc4d045a4b | cannam | #ifndef __GNUC__
|
| 51 | #include <alloca.h> |
||
| 52 | #endif
|
||
| 53 | |||
| 54 | 2:c9a4bd247497 | cannam | Tester::TestRegistrar<TestDistinctRuns> |
| 55 | 39:07144cdcbedf | Chris | TestDistinctRuns::m_registrar("D1", "Consecutive runs with separate instances"); |
| 56 | 2:c9a4bd247497 | cannam | |
| 57 | Tester::TestRegistrar<TestReset> |
||
| 58 | 39:07144cdcbedf | Chris | TestReset::m_registrar("D2", "Consecutive runs with a single instance using reset"); |
| 59 | 2:c9a4bd247497 | cannam | |
| 60 | Tester::TestRegistrar<TestInterleavedRuns> |
||
| 61 | 39:07144cdcbedf | Chris | TestInterleavedRuns::m_registrar("D3", "Simultaneous interleaved runs in a single thread"); |
| 62 | 2:c9a4bd247497 | cannam | |
| 63 | 5:6a279da6fdd7 | cannam | Tester::TestRegistrar<TestDifferentStartTimes> |
| 64 | 39:07144cdcbedf | Chris | TestDifferentStartTimes::m_registrar("D4", "Consecutive runs with different start times"); |
| 65 | 5:6a279da6fdd7 | cannam | |
| 66 | 3:0f65bb22172b | cannam | static const size_t _step = 1000; |
| 67 | |||
| 68 | 2:c9a4bd247497 | cannam | Test::Results |
| 69 | 8:3019cb6b538d | cannam | TestDistinctRuns::test(string key, Options options)
|
| 70 | 2:c9a4bd247497 | cannam | {
|
| 71 | Plugin::FeatureSet f[2];
|
||
| 72 | int rate = 44100; |
||
| 73 | Results r; |
||
| 74 | 3:0f65bb22172b | cannam | float **data = 0; |
| 75 | size_t channels = 0;
|
||
| 76 | size_t count = 100;
|
||
| 77 | 2:c9a4bd247497 | cannam | |
| 78 | for (int run = 0; run < 2; ++run) { |
||
| 79 | auto_ptr<Plugin> p(load(key, rate)); |
||
| 80 | 3:0f65bb22172b | cannam | if (!initAdapted(p.get(), channels, _step, _step, r)) return r; |
| 81 | if (!data) data = createTestAudio(channels, _step, count);
|
||
| 82 | for (size_t i = 0; i < count; ++i) { |
||
| 83 | 28:b1bc4d045a4b | cannam | #ifdef __GNUC__
|
| 84 | 3:0f65bb22172b | cannam | float *ptr[channels];
|
| 85 | 28:b1bc4d045a4b | cannam | #else
|
| 86 | float **ptr = (float **)alloca(channels * sizeof(float)); |
||
| 87 | #endif
|
||
| 88 | 3:0f65bb22172b | cannam | size_t idx = i * _step; |
| 89 | for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx; |
||
| 90 | 2:c9a4bd247497 | cannam | RealTime timestamp = RealTime::frame2RealTime(idx, rate); |
| 91 | 3:0f65bb22172b | cannam | Plugin::FeatureSet fs = p->process(ptr, timestamp); |
| 92 | 2:c9a4bd247497 | cannam | appendFeatures(f[run], fs); |
| 93 | } |
||
| 94 | Plugin::FeatureSet fs = p->getRemainingFeatures(); |
||
| 95 | appendFeatures(f[run], fs); |
||
| 96 | } |
||
| 97 | 3:0f65bb22172b | cannam | if (data) destroyTestAudio(data, channels);
|
| 98 | 2:c9a4bd247497 | cannam | |
| 99 | if (!(f[0] == f[1])) { |
||
| 100 | 8:3019cb6b538d | cannam | Result res; |
| 101 | string message = "Consecutive runs with separate instances produce different results"; |
||
| 102 | if (options & NonDeterministic) res = note(message);
|
||
| 103 | else res = error(message);
|
||
| 104 | if (options & Verbose) dump(res, f[0], f[1]); |
||
| 105 | 7:43eb3a4b95c8 | cannam | r.push_back(res); |
| 106 | 2:c9a4bd247497 | cannam | } else {
|
| 107 | r.push_back(success()); |
||
| 108 | } |
||
| 109 | |||
| 110 | return r;
|
||
| 111 | } |
||
| 112 | |||
| 113 | Test::Results |
||
| 114 | 8:3019cb6b538d | cannam | TestReset::test(string key, Options options)
|
| 115 | 2:c9a4bd247497 | cannam | {
|
| 116 | Plugin::FeatureSet f[2];
|
||
| 117 | int rate = 44100; |
||
| 118 | Results r; |
||
| 119 | 3:0f65bb22172b | cannam | float **data = 0; |
| 120 | size_t channels = 0;
|
||
| 121 | size_t count = 100;
|
||
| 122 | 2:c9a4bd247497 | cannam | |
| 123 | auto_ptr<Plugin> p(load(key, rate)); |
||
| 124 | 3:0f65bb22172b | cannam | |
| 125 | 2:c9a4bd247497 | cannam | for (int run = 0; run < 2; ++run) { |
| 126 | if (run == 1) p->reset(); |
||
| 127 | 11:82ef943a1bd2 | cannam | else if (!initAdapted(p.get(), channels, _step, _step, r)) return r; |
| 128 | 3:0f65bb22172b | cannam | if (!data) data = createTestAudio(channels, _step, count);
|
| 129 | for (size_t i = 0; i < count; ++i) { |
||
| 130 | 28:b1bc4d045a4b | cannam | #ifdef __GNUC__
|
| 131 | 3:0f65bb22172b | cannam | float *ptr[channels];
|
| 132 | 28:b1bc4d045a4b | cannam | #else
|
| 133 | float **ptr = (float **)alloca(channels * sizeof(float)); |
||
| 134 | #endif
|
||
| 135 | 3:0f65bb22172b | cannam | size_t idx = i * _step; |
| 136 | for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx; |
||
| 137 | 2:c9a4bd247497 | cannam | RealTime timestamp = RealTime::frame2RealTime(idx, rate); |
| 138 | 3:0f65bb22172b | cannam | Plugin::FeatureSet fs = p->process(ptr, timestamp); |
| 139 | 2:c9a4bd247497 | cannam | appendFeatures(f[run], fs); |
| 140 | } |
||
| 141 | Plugin::FeatureSet fs = p->getRemainingFeatures(); |
||
| 142 | appendFeatures(f[run], fs); |
||
| 143 | } |
||
| 144 | 3:0f65bb22172b | cannam | if (data) destroyTestAudio(data, channels);
|
| 145 | 2:c9a4bd247497 | cannam | |
| 146 | if (!(f[0] == f[1])) { |
||
| 147 | 8:3019cb6b538d | cannam | string message = "Consecutive runs with the same instance (using reset) produce different results"; |
| 148 | Result res; |
||
| 149 | if (options & NonDeterministic) res = note(message);
|
||
| 150 | else res = error(message);
|
||
| 151 | if (options & Verbose) dump(res, f[0], f[1]); |
||
| 152 | 3:0f65bb22172b | cannam | r.push_back(res); |
| 153 | 2:c9a4bd247497 | cannam | } else {
|
| 154 | r.push_back(success()); |
||
| 155 | } |
||
| 156 | |||
| 157 | return r;
|
||
| 158 | } |
||
| 159 | |||
| 160 | Test::Results |
||
| 161 | 8:3019cb6b538d | cannam | TestInterleavedRuns::test(string key, Options options)
|
| 162 | 2:c9a4bd247497 | cannam | {
|
| 163 | Plugin::FeatureSet f[2];
|
||
| 164 | int rate = 44100; |
||
| 165 | Results r; |
||
| 166 | 3:0f65bb22172b | cannam | float **data = 0; |
| 167 | size_t channels = 0;
|
||
| 168 | size_t count = 100;
|
||
| 169 | |||
| 170 | 2:c9a4bd247497 | cannam | Plugin *p[2];
|
| 171 | for (int run = 0; run < 2; ++run) { |
||
| 172 | p[run] = load(key, rate); |
||
| 173 | 3:0f65bb22172b | cannam | if (!initAdapted(p[run], channels, _step, _step, r)) {
|
| 174 | 2:c9a4bd247497 | cannam | delete p[run];
|
| 175 | if (run > 0) delete p[0]; |
||
| 176 | return r;
|
||
| 177 | } |
||
| 178 | 3:0f65bb22172b | cannam | if (!data) data = createTestAudio(channels, _step, count);
|
| 179 | 2:c9a4bd247497 | cannam | } |
| 180 | 3:0f65bb22172b | cannam | for (size_t i = 0; i < count; ++i) { |
| 181 | 28:b1bc4d045a4b | cannam | #ifdef __GNUC__
|
| 182 | 3:0f65bb22172b | cannam | float *ptr[channels];
|
| 183 | 28:b1bc4d045a4b | cannam | #else
|
| 184 | float **ptr = (float **)alloca(channels * sizeof(float)); |
||
| 185 | #endif
|
||
| 186 | 3:0f65bb22172b | cannam | size_t idx = i * _step; |
| 187 | for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx; |
||
| 188 | 2:c9a4bd247497 | cannam | RealTime timestamp = RealTime::frame2RealTime(idx, rate); |
| 189 | for (int run = 0; run < 2; ++run) { |
||
| 190 | 3:0f65bb22172b | cannam | Plugin::FeatureSet fs = p[run]->process(ptr, timestamp); |
| 191 | 2:c9a4bd247497 | cannam | appendFeatures(f[run], fs); |
| 192 | } |
||
| 193 | } |
||
| 194 | for (int run = 0; run < 2; ++run) { |
||
| 195 | Plugin::FeatureSet fs = p[run]->getRemainingFeatures(); |
||
| 196 | appendFeatures(f[run], fs); |
||
| 197 | delete p[run];
|
||
| 198 | } |
||
| 199 | |||
| 200 | 3:0f65bb22172b | cannam | if (data) destroyTestAudio(data, channels);
|
| 201 | 2:c9a4bd247497 | cannam | |
| 202 | if (!(f[0] == f[1])) { |
||
| 203 | 8:3019cb6b538d | cannam | string message = "Simultaneous runs with separate instances produce different results"; |
| 204 | Result res; |
||
| 205 | if (options & NonDeterministic) res = note(message);
|
||
| 206 | else res = error(message);
|
||
| 207 | if (options & Verbose) dump(res, f[0], f[1]); |
||
| 208 | 7:43eb3a4b95c8 | cannam | r.push_back(res); |
| 209 | 2:c9a4bd247497 | cannam | } else {
|
| 210 | r.push_back(success()); |
||
| 211 | } |
||
| 212 | |||
| 213 | return r;
|
||
| 214 | } |
||
| 215 | 5:6a279da6fdd7 | cannam | |
| 216 | Test::Results |
||
| 217 | 8:3019cb6b538d | cannam | TestDifferentStartTimes::test(string key, Options options)
|
| 218 | 5:6a279da6fdd7 | cannam | {
|
| 219 | Plugin::FeatureSet f[2];
|
||
| 220 | int rate = 44100; |
||
| 221 | Results r; |
||
| 222 | float **data = 0; |
||
| 223 | size_t channels = 0;
|
||
| 224 | size_t count = 100;
|
||
| 225 | |||
| 226 | for (int run = 0; run < 2; ++run) { |
||
| 227 | auto_ptr<Plugin> p(load(key, rate)); |
||
| 228 | if (!initAdapted(p.get(), channels, _step, _step, r)) return r; |
||
| 229 | if (!data) data = createTestAudio(channels, _step, count);
|
||
| 230 | for (size_t i = 0; i < count; ++i) { |
||
| 231 | 28:b1bc4d045a4b | cannam | #ifdef __GNUC__
|
| 232 | 5:6a279da6fdd7 | cannam | float *ptr[channels];
|
| 233 | 28:b1bc4d045a4b | cannam | #else
|
| 234 | float **ptr = (float **)alloca(channels * sizeof(float)); |
||
| 235 | #endif
|
||
| 236 | 5:6a279da6fdd7 | cannam | size_t idx = i * _step; |
| 237 | for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx; |
||
| 238 | RealTime timestamp = RealTime::frame2RealTime(idx, rate); |
||
| 239 | if (run == 1) timestamp = timestamp + RealTime::fromSeconds(10); |
||
| 240 | Plugin::FeatureSet fs = p->process(ptr, timestamp); |
||
| 241 | appendFeatures(f[run], fs); |
||
| 242 | } |
||
| 243 | Plugin::FeatureSet fs = p->getRemainingFeatures(); |
||
| 244 | appendFeatures(f[run], fs); |
||
| 245 | } |
||
| 246 | if (data) destroyTestAudio(data, channels);
|
||
| 247 | |||
| 248 | if (f[0] == f[1]) { |
||
| 249 | 8:3019cb6b538d | cannam | string message = "Consecutive runs with different starting timestamps produce the same result"; |
| 250 | Result res; |
||
| 251 | if (options & NonDeterministic) res = note(message);
|
||
| 252 | 13:df121992f23a | cannam | else res = warning(message);
|
| 253 | 8:3019cb6b538d | cannam | if (options & Verbose) dump(res, f[0], f[1]); |
| 254 | 7:43eb3a4b95c8 | cannam | r.push_back(res); |
| 255 | 5:6a279da6fdd7 | cannam | } else {
|
| 256 | r.push_back(success()); |
||
| 257 | } |
||
| 258 | |||
| 259 | return r;
|
||
| 260 | } |