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 @ 5:6a279da6fdd7
History | View | Annotate | Download (7.29 KB)
| 1 |
/* -*- 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 |
Copyright 2009 QMUL.
|
| 8 |
|
| 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 |
Tester::TestRegistrar<TestDistinctRuns> |
| 51 |
TestDistinctRuns::m_registrar("D1 Consecutive runs with separate instances");
|
| 52 |
|
| 53 |
Tester::TestRegistrar<TestReset> |
| 54 |
TestReset::m_registrar("D2 Consecutive runs with a single instance using reset");
|
| 55 |
|
| 56 |
Tester::TestRegistrar<TestInterleavedRuns> |
| 57 |
TestInterleavedRuns::m_registrar("D3 Simultaneous interleaved runs in a single thread");
|
| 58 |
|
| 59 |
Tester::TestRegistrar<TestDifferentStartTimes> |
| 60 |
TestDifferentStartTimes::m_registrar("D4 Consecutive runs with different start times");
|
| 61 |
|
| 62 |
static const size_t _step = 1000; |
| 63 |
|
| 64 |
Test::Results |
| 65 |
TestDistinctRuns::test(string key)
|
| 66 |
{
|
| 67 |
Plugin::FeatureSet f[2];
|
| 68 |
int rate = 44100; |
| 69 |
Results r; |
| 70 |
float **data = 0; |
| 71 |
size_t channels = 0;
|
| 72 |
size_t count = 100;
|
| 73 |
|
| 74 |
for (int run = 0; run < 2; ++run) { |
| 75 |
auto_ptr<Plugin> p(load(key, rate)); |
| 76 |
if (!initAdapted(p.get(), channels, _step, _step, r)) return r; |
| 77 |
if (!data) data = createTestAudio(channels, _step, count);
|
| 78 |
for (size_t i = 0; i < count; ++i) { |
| 79 |
float *ptr[channels];
|
| 80 |
size_t idx = i * _step; |
| 81 |
for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx; |
| 82 |
RealTime timestamp = RealTime::frame2RealTime(idx, rate); |
| 83 |
Plugin::FeatureSet fs = p->process(ptr, timestamp); |
| 84 |
appendFeatures(f[run], fs); |
| 85 |
} |
| 86 |
Plugin::FeatureSet fs = p->getRemainingFeatures(); |
| 87 |
appendFeatures(f[run], fs); |
| 88 |
} |
| 89 |
if (data) destroyTestAudio(data, channels);
|
| 90 |
|
| 91 |
if (!(f[0] == f[1])) { |
| 92 |
r.push_back(warning("Consecutive runs with separate instances produce different results"));
|
| 93 |
} else {
|
| 94 |
r.push_back(success()); |
| 95 |
} |
| 96 |
|
| 97 |
return r;
|
| 98 |
} |
| 99 |
|
| 100 |
Test::Results |
| 101 |
TestReset::test(string key)
|
| 102 |
{
|
| 103 |
Plugin::FeatureSet f[2];
|
| 104 |
int rate = 44100; |
| 105 |
Results r; |
| 106 |
float **data = 0; |
| 107 |
size_t channels = 0;
|
| 108 |
size_t count = 100;
|
| 109 |
|
| 110 |
auto_ptr<Plugin> p(load(key, rate)); |
| 111 |
|
| 112 |
for (int run = 0; run < 2; ++run) { |
| 113 |
if (run == 1) p->reset(); |
| 114 |
if (!initAdapted(p.get(), channels, _step, _step, r)) return r; |
| 115 |
if (!data) data = createTestAudio(channels, _step, count);
|
| 116 |
for (size_t i = 0; i < count; ++i) { |
| 117 |
float *ptr[channels];
|
| 118 |
size_t idx = i * _step; |
| 119 |
for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx; |
| 120 |
RealTime timestamp = RealTime::frame2RealTime(idx, rate); |
| 121 |
Plugin::FeatureSet fs = p->process(ptr, timestamp); |
| 122 |
appendFeatures(f[run], fs); |
| 123 |
} |
| 124 |
Plugin::FeatureSet fs = p->getRemainingFeatures(); |
| 125 |
appendFeatures(f[run], fs); |
| 126 |
} |
| 127 |
if (data) destroyTestAudio(data, channels);
|
| 128 |
|
| 129 |
if (!(f[0] == f[1])) { |
| 130 |
Result res = warning("Consecutive runs with the same instance (using reset) produce different results");
|
| 131 |
dump(res, f[0], f[1]); |
| 132 |
r.push_back(res); |
| 133 |
} else {
|
| 134 |
r.push_back(success()); |
| 135 |
} |
| 136 |
|
| 137 |
return r;
|
| 138 |
} |
| 139 |
|
| 140 |
Test::Results |
| 141 |
TestInterleavedRuns::test(string key)
|
| 142 |
{
|
| 143 |
Plugin::FeatureSet f[2];
|
| 144 |
int rate = 44100; |
| 145 |
Results r; |
| 146 |
float **data = 0; |
| 147 |
size_t channels = 0;
|
| 148 |
size_t count = 100;
|
| 149 |
|
| 150 |
Plugin *p[2];
|
| 151 |
for (int run = 0; run < 2; ++run) { |
| 152 |
p[run] = load(key, rate); |
| 153 |
if (!initAdapted(p[run], channels, _step, _step, r)) {
|
| 154 |
delete p[run];
|
| 155 |
if (run > 0) delete p[0]; |
| 156 |
return r;
|
| 157 |
} |
| 158 |
if (!data) data = createTestAudio(channels, _step, count);
|
| 159 |
} |
| 160 |
for (size_t i = 0; i < count; ++i) { |
| 161 |
float *ptr[channels];
|
| 162 |
size_t idx = i * _step; |
| 163 |
for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx; |
| 164 |
RealTime timestamp = RealTime::frame2RealTime(idx, rate); |
| 165 |
for (int run = 0; run < 2; ++run) { |
| 166 |
Plugin::FeatureSet fs = p[run]->process(ptr, timestamp); |
| 167 |
appendFeatures(f[run], fs); |
| 168 |
} |
| 169 |
} |
| 170 |
for (int run = 0; run < 2; ++run) { |
| 171 |
Plugin::FeatureSet fs = p[run]->getRemainingFeatures(); |
| 172 |
appendFeatures(f[run], fs); |
| 173 |
delete p[run];
|
| 174 |
} |
| 175 |
|
| 176 |
if (data) destroyTestAudio(data, channels);
|
| 177 |
|
| 178 |
if (!(f[0] == f[1])) { |
| 179 |
r.push_back(warning("Simultaneous runs with separate instances produce different results"));
|
| 180 |
} else {
|
| 181 |
r.push_back(success()); |
| 182 |
} |
| 183 |
|
| 184 |
return r;
|
| 185 |
} |
| 186 |
|
| 187 |
Test::Results |
| 188 |
TestDifferentStartTimes::test(string key)
|
| 189 |
{
|
| 190 |
Plugin::FeatureSet f[2];
|
| 191 |
int rate = 44100; |
| 192 |
Results r; |
| 193 |
float **data = 0; |
| 194 |
size_t channels = 0;
|
| 195 |
size_t count = 100;
|
| 196 |
|
| 197 |
for (int run = 0; run < 2; ++run) { |
| 198 |
auto_ptr<Plugin> p(load(key, rate)); |
| 199 |
if (!initAdapted(p.get(), channels, _step, _step, r)) return r; |
| 200 |
if (!data) data = createTestAudio(channels, _step, count);
|
| 201 |
for (size_t i = 0; i < count; ++i) { |
| 202 |
float *ptr[channels];
|
| 203 |
size_t idx = i * _step; |
| 204 |
for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx; |
| 205 |
RealTime timestamp = RealTime::frame2RealTime(idx, rate); |
| 206 |
if (run == 1) timestamp = timestamp + RealTime::fromSeconds(10); |
| 207 |
Plugin::FeatureSet fs = p->process(ptr, timestamp); |
| 208 |
appendFeatures(f[run], fs); |
| 209 |
} |
| 210 |
Plugin::FeatureSet fs = p->getRemainingFeatures(); |
| 211 |
appendFeatures(f[run], fs); |
| 212 |
} |
| 213 |
if (data) destroyTestAudio(data, channels);
|
| 214 |
|
| 215 |
if (f[0] == f[1]) { |
| 216 |
r.push_back(warning("Consecutive runs with different starting timestamps produce the same result"));
|
| 217 |
} else {
|
| 218 |
r.push_back(success()); |
| 219 |
} |
| 220 |
|
| 221 |
return r;
|
| 222 |
} |