Revision 3:0f65bb22172b
| Makefile | ||
|---|---|---|
| 2 | 2 |
LDFLAGS += -lvamp-hostsdk -ldl |
| 3 | 3 |
CXXFLAGS += -Wall -Wextra |
| 4 | 4 |
|
| 5 |
OBJECTS := vamp-plugin-tester.o Tester.o Test.o TestStaticData.o TestInputExtremes.o TestMultipleRuns.o |
|
| 5 |
OBJECTS := vamp-plugin-tester.o Tester.o Test.o TestStaticData.o TestInputExtremes.o TestMultipleRuns.o TestOutputs.o
|
|
| 6 | 6 |
|
| 7 | 7 |
vamp-plugin-tester: $(OBJECTS) |
| 8 | 8 |
|
| ... | ... | |
| 18 | 18 |
# DO NOT DELETE |
| 19 | 19 |
|
| 20 | 20 |
Test.o: Test.h |
| 21 |
TestInputExtremes.o: TestInputExtremes.h |
|
| 21 |
TestInputExtremes.o: TestInputExtremes.h Test.h Tester.h |
|
| 22 |
TestMultipleRuns.o: TestMultipleRuns.h Test.h Tester.h |
|
| 23 |
TestOutputs.o: TestOutputs.h Test.h Tester.h |
|
| 22 | 24 |
TestStaticData.o: TestStaticData.h Test.h Tester.h |
| 23 | 25 |
Tester.o: Tester.h Test.h |
| 24 | 26 |
vamp-plugin-tester.o: Tester.h Test.h |
| 27 |
TestInputExtremes.o: Test.h Tester.h |
|
| 28 |
TestMultipleRuns.o: Test.h Tester.h |
|
| 29 |
TestOutputs.o: Test.h Tester.h |
|
| 25 | 30 |
TestStaticData.o: Test.h Tester.h |
| 26 | 31 |
Tester.o: Test.h |
| Test.cpp | ||
|---|---|---|
| 75 | 75 |
delete[] blocks; |
| 76 | 76 |
} |
| 77 | 77 |
|
| 78 |
float ** |
|
| 79 |
Test::createTestAudio(size_t channels, size_t blocksize, size_t blocks) |
|
| 80 |
{
|
|
| 81 |
float **b = new float *[channels]; |
|
| 82 |
for (size_t c = 0; c < channels; ++c) {
|
|
| 83 |
b[c] = new float[blocksize * blocks]; |
|
| 84 |
for (int i = 0; i < int(blocksize * blocks); ++i) {
|
|
| 85 |
b[c][i] = sinf(float(i) / 10.f); |
|
| 86 |
if (i == 5005 || i == 20002) {
|
|
| 87 |
b[c][i-2] = 0; |
|
| 88 |
b[c][i-1] = -1; |
|
| 89 |
b[c][i] = 1; |
|
| 90 |
} |
|
| 91 |
} |
|
| 92 |
} |
|
| 93 |
return b; |
|
| 94 |
} |
|
| 95 |
|
|
| 96 |
void |
|
| 97 |
Test::destroyTestAudio(float **b, size_t channels) |
|
| 98 |
{
|
|
| 99 |
for (size_t c = 0; c < channels; ++c) {
|
|
| 100 |
delete[] b[c]; |
|
| 101 |
} |
|
| 102 |
delete[] b; |
|
| 103 |
} |
|
| 104 |
|
|
| 78 | 105 |
bool |
| 79 | 106 |
Test::initDefaults(Plugin *p, size_t &channels, size_t &step, size_t &block, |
| 80 | 107 |
Results &r) |
| ... | ... | |
| 94 | 121 |
return true; |
| 95 | 122 |
} |
| 96 | 123 |
|
| 124 |
bool |
|
| 125 |
Test::initAdapted(Plugin *p, size_t &channels, size_t step, size_t block, |
|
| 126 |
Results &r) |
|
| 127 |
{
|
|
| 128 |
channels = p->getMinChannelCount(); |
|
| 129 |
if (!p->initialise(channels, step, block)) {
|
|
| 130 |
r.push_back(error("initialisation failed"));
|
|
| 131 |
return false; |
|
| 132 |
} |
|
| 133 |
return true; |
|
| 134 |
} |
|
| 135 |
|
|
| 97 | 136 |
void |
| 98 | 137 |
Test::appendFeatures(Plugin::FeatureSet &a, const Plugin::FeatureSet &b) |
| 99 | 138 |
{
|
| ... | ... | |
| 124 | 163 |
return true; |
| 125 | 164 |
} |
| 126 | 165 |
|
| 166 |
void |
|
| 167 |
Test::dump(const Plugin::FeatureSet &fs) |
|
| 168 |
{
|
|
| 169 |
for (Plugin::FeatureSet::const_iterator fsi = fs.begin(); |
|
| 170 |
fsi != fs.end(); ++fsi) {
|
|
| 171 |
int output = fsi->first; |
|
| 172 |
std::cerr << "Output " << output << ":" << std::endl; |
|
| 173 |
const Plugin::FeatureList &fl = fsi->second; |
|
| 174 |
for (int i = 0; i < (int)fl.size(); ++i) {
|
|
| 175 |
std::cerr << " Feature " << i << ":" << std::endl; |
|
| 176 |
const Plugin::Feature &f = fl[i]; |
|
| 177 |
std::cerr << " Timestamp: " << (f.hasTimestamp ? "(none)" : f.timestamp.toText()) << std::endl; |
|
| 178 |
std::cerr << " Duration: " << (f.hasDuration ? "(none)" : f.duration.toText()) << std::endl; |
|
| 179 |
std::cerr << " Label: " << (f.label == "" ? "(none)" : f.label) << std::endl; |
|
| 180 |
std::cerr << " Value: " << (f.values.empty() ? "(none)" : ""); |
|
| 181 |
for (int j = 0; j < (int)f.values.size(); ++j) {
|
|
| 182 |
std::cerr << f.values[j] << " "; |
|
| 183 |
} |
|
| 184 |
std::cerr << std::endl; |
|
| 185 |
} |
|
| 186 |
} |
|
| 187 |
} |
|
| 188 |
|
|
| 189 |
void |
|
| 190 |
Test::dump(const Result &r, |
|
| 191 |
const Plugin::FeatureSet &a, |
|
| 192 |
const Plugin::FeatureSet &b) |
|
| 193 |
{
|
|
| 194 |
std::cerr << r.message() << std::endl; |
|
| 195 |
std::cerr << "\nFirst result set:" << std::endl; |
|
| 196 |
dump(a); |
|
| 197 |
std::cerr << "\nSecond result set:" << std::endl; |
|
| 198 |
dump(b); |
|
| 199 |
std::cerr << std::endl; |
|
| 200 |
} |
|
| 201 |
|
|
| 127 | 202 |
bool |
| 128 | 203 |
operator==(const Plugin::FeatureSet &a, const Plugin::FeatureSet &b) |
| 129 | 204 |
{
|
| Test.h | ||
|---|---|---|
| 52 | 52 |
class Result {
|
| 53 | 53 |
|
| 54 | 54 |
public: |
| 55 |
enum Code { Success, Warning, Error };
|
|
| 55 |
enum Code { Success, Note, Warning, Error };
|
|
| 56 | 56 |
|
| 57 | 57 |
Result(Code c, std::string m) : m_code(c), m_message(m) { }
|
| 58 | 58 |
|
| 59 |
Code code() { return m_code; }
|
|
| 60 |
std::string message() { return m_message; }
|
|
| 59 |
Code code() const { return m_code; }
|
|
| 60 |
std::string message() const { return m_message; }
|
|
| 61 | 61 |
|
| 62 | 62 |
protected: |
| 63 | 63 |
Code m_code; |
| ... | ... | |
| 65 | 65 |
}; |
| 66 | 66 |
|
| 67 | 67 |
static Result success() { return Result(Result::Success, ""); }
|
| 68 |
static Result note(std::string m) { return Result(Result::Note, m); }
|
|
| 68 | 69 |
static Result warning(std::string m) { return Result(Result::Warning, m); }
|
| 69 | 70 |
static Result error(std::string m) { return Result(Result::Error, m); }
|
| 70 | 71 |
|
| ... | ... | |
| 84 | 85 |
float **createBlock(size_t channels, size_t blocksize); |
| 85 | 86 |
void destroyBlock(float **blocks, size_t channels); |
| 86 | 87 |
|
| 88 |
float **createTestAudio(size_t channels, size_t blocksize, size_t blocks); |
|
| 89 |
void destroyTestAudio(float **audio, size_t channels); |
|
| 90 |
|
|
| 87 | 91 |
bool initDefaults(Vamp::Plugin *, size_t &channels, |
| 88 | 92 |
size_t &step, size_t &block, Results &r); |
| 89 | 93 |
|
| 94 |
bool initAdapted(Vamp::Plugin *, size_t &channels, |
|
| 95 |
size_t step, size_t block, Results &r); |
|
| 96 |
|
|
| 90 | 97 |
void appendFeatures(Vamp::Plugin::FeatureSet &a, |
| 91 | 98 |
const Vamp::Plugin::FeatureSet &b); |
| 92 | 99 |
|
| 93 | 100 |
bool allFeaturesValid(const Vamp::Plugin::FeatureSet &); // i.e. no NaN/inf |
| 101 |
|
|
| 102 |
void dump(const Vamp::Plugin::FeatureSet &); |
|
| 103 |
void dump(const Result &r, |
|
| 104 |
const Vamp::Plugin::FeatureSet &, |
|
| 105 |
const Vamp::Plugin::FeatureSet &); |
|
| 94 | 106 |
}; |
| 95 | 107 |
|
| 96 | 108 |
extern bool operator==(const Vamp::Plugin::FeatureSet &a, |
| TestMultipleRuns.cpp | ||
|---|---|---|
| 56 | 56 |
Tester::TestRegistrar<TestInterleavedRuns> |
| 57 | 57 |
TestInterleavedRuns::m_registrar("Simultaneous interleaved runs in a single thread");
|
| 58 | 58 |
|
| 59 |
static const size_t _step = 1000; |
|
| 60 |
|
|
| 59 | 61 |
Test::Results |
| 60 | 62 |
TestDistinctRuns::test(string key) |
| 61 | 63 |
{
|
| 62 | 64 |
Plugin::FeatureSet f[2]; |
| 63 | 65 |
int rate = 44100; |
| 64 | 66 |
Results r; |
| 65 |
float **block = 0; |
|
| 66 |
size_t channels = 0, step = 0, blocksize = 0; |
|
| 67 |
float **data = 0; |
|
| 68 |
size_t channels = 0; |
|
| 69 |
size_t count = 100; |
|
| 67 | 70 |
|
| 68 | 71 |
for (int run = 0; run < 2; ++run) {
|
| 69 | 72 |
auto_ptr<Plugin> p(load(key, rate)); |
| 70 |
if (!initDefaults(p.get(), channels, step, blocksize, r)) return r; |
|
| 71 |
if (!block) block = createBlock(channels, blocksize); |
|
| 72 |
int idx = 0; |
|
| 73 |
for (int i = 0; i < 100; ++i) {
|
|
| 74 |
for (size_t j = 0; j < blocksize; ++j) {
|
|
| 75 |
for (size_t c = 0; c < channels; ++c) {
|
|
| 76 |
block[c][j] = sinf(float(idx) / 10.f); |
|
| 77 |
if ((i == 20 || i == 80) && (j < 2)) {
|
|
| 78 |
block[c][j] = float(j) - 1.f; |
|
| 79 |
} |
|
| 80 |
} |
|
| 81 |
++idx; |
|
| 82 |
} |
|
| 73 |
if (!initAdapted(p.get(), channels, _step, _step, r)) return r; |
|
| 74 |
if (!data) data = createTestAudio(channels, _step, count); |
|
| 75 |
for (size_t i = 0; i < count; ++i) {
|
|
| 76 |
float *ptr[channels]; |
|
| 77 |
size_t idx = i * _step; |
|
| 78 |
for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx; |
|
| 83 | 79 |
RealTime timestamp = RealTime::frame2RealTime(idx, rate); |
| 84 |
Plugin::FeatureSet fs = p->process(block, timestamp);
|
|
| 80 |
Plugin::FeatureSet fs = p->process(ptr, timestamp);
|
|
| 85 | 81 |
appendFeatures(f[run], fs); |
| 86 | 82 |
} |
| 87 | 83 |
Plugin::FeatureSet fs = p->getRemainingFeatures(); |
| 88 | 84 |
appendFeatures(f[run], fs); |
| 89 | 85 |
} |
| 90 |
if (block) destroyBlock(block, channels);
|
|
| 86 |
if (data) destroyTestAudio(data, channels);
|
|
| 91 | 87 |
|
| 92 | 88 |
if (!(f[0] == f[1])) {
|
| 93 | 89 |
r.push_back(warning("Consecutive runs with separate instances produce different results"));
|
| ... | ... | |
| 104 | 100 |
Plugin::FeatureSet f[2]; |
| 105 | 101 |
int rate = 44100; |
| 106 | 102 |
Results r; |
| 107 |
float **block = 0; |
|
| 108 |
size_t channels = 0, step = 0, blocksize = 0; |
|
| 103 |
float **data = 0; |
|
| 104 |
size_t channels = 0; |
|
| 105 |
size_t count = 100; |
|
| 109 | 106 |
|
| 110 | 107 |
auto_ptr<Plugin> p(load(key, rate)); |
| 108 |
|
|
| 111 | 109 |
for (int run = 0; run < 2; ++run) {
|
| 112 | 110 |
if (run == 1) p->reset(); |
| 113 |
if (!initDefaults(p.get(), channels, step, blocksize, r)) return r; |
|
| 114 |
if (!block) block = createBlock(channels, blocksize); |
|
| 115 |
int idx = 0; |
|
| 116 |
for (int i = 0; i < 100; ++i) {
|
|
| 117 |
for (size_t j = 0; j < blocksize; ++j) {
|
|
| 118 |
for (size_t c = 0; c < channels; ++c) {
|
|
| 119 |
block[c][j] = sinf(float(idx) / 10.f); |
|
| 120 |
if ((i == 20 || i == 80) && (j < 2)) {
|
|
| 121 |
block[c][j] = float(j) - 1.f; |
|
| 122 |
} |
|
| 123 |
} |
|
| 124 |
++idx; |
|
| 125 |
} |
|
| 111 |
if (!initAdapted(p.get(), channels, _step, _step, r)) return r; |
|
| 112 |
if (!data) data = createTestAudio(channels, _step, count); |
|
| 113 |
for (size_t i = 0; i < count; ++i) {
|
|
| 114 |
float *ptr[channels]; |
|
| 115 |
size_t idx = i * _step; |
|
| 116 |
for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx; |
|
| 126 | 117 |
RealTime timestamp = RealTime::frame2RealTime(idx, rate); |
| 127 |
Plugin::FeatureSet fs = p->process(block, timestamp);
|
|
| 118 |
Plugin::FeatureSet fs = p->process(ptr, timestamp);
|
|
| 128 | 119 |
appendFeatures(f[run], fs); |
| 129 | 120 |
} |
| 130 | 121 |
Plugin::FeatureSet fs = p->getRemainingFeatures(); |
| 131 | 122 |
appendFeatures(f[run], fs); |
| 132 | 123 |
} |
| 133 |
if (block) destroyBlock(block, channels);
|
|
| 124 |
if (data) destroyTestAudio(data, channels);
|
|
| 134 | 125 |
|
| 135 | 126 |
if (!(f[0] == f[1])) {
|
| 136 |
r.push_back(warning("Consecutive runs with the same instance (using reset) produce different results"));
|
|
| 127 |
Result res = warning("Consecutive runs with the same instance (using reset) produce different results");
|
|
| 128 |
dump(res, f[0], f[1]); |
|
| 129 |
r.push_back(res); |
|
| 137 | 130 |
} else {
|
| 138 | 131 |
r.push_back(success()); |
| 139 | 132 |
} |
| ... | ... | |
| 147 | 140 |
Plugin::FeatureSet f[2]; |
| 148 | 141 |
int rate = 44100; |
| 149 | 142 |
Results r; |
| 150 |
float **block = 0; |
|
| 151 |
size_t channels = 0, step = 0, blocksize = 0; |
|
| 143 |
float **data = 0; |
|
| 144 |
size_t channels = 0; |
|
| 145 |
size_t count = 100; |
|
| 146 |
|
|
| 152 | 147 |
Plugin *p[2]; |
| 153 | 148 |
for (int run = 0; run < 2; ++run) {
|
| 154 | 149 |
p[run] = load(key, rate); |
| 155 |
if (!initDefaults(p[run], channels, step, blocksize, r)) {
|
|
| 150 |
if (!initAdapted(p[run], channels, _step, _step, r)) {
|
|
| 156 | 151 |
delete p[run]; |
| 157 | 152 |
if (run > 0) delete p[0]; |
| 158 | 153 |
return r; |
| 159 | 154 |
} |
| 160 |
if (!block) block = createBlock(channels, blocksize);
|
|
| 155 |
if (!data) data = createTestAudio(channels, _step, count);
|
|
| 161 | 156 |
} |
| 162 |
int idx = 0; |
|
| 163 |
for (int i = 0; i < 100; ++i) {
|
|
| 164 |
for (size_t j = 0; j < blocksize; ++j) {
|
|
| 165 |
for (size_t c = 0; c < channels; ++c) {
|
|
| 166 |
block[c][j] = sinf(float(idx) / 10.f); |
|
| 167 |
if ((i == 20 || i == 80) && (j < 2)) {
|
|
| 168 |
block[c][j] = float(j) - 1.f; |
|
| 169 |
} |
|
| 170 |
} |
|
| 171 |
++idx; |
|
| 172 |
} |
|
| 157 |
for (size_t i = 0; i < count; ++i) {
|
|
| 158 |
float *ptr[channels]; |
|
| 159 |
size_t idx = i * _step; |
|
| 160 |
for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx; |
|
| 173 | 161 |
RealTime timestamp = RealTime::frame2RealTime(idx, rate); |
| 174 | 162 |
for (int run = 0; run < 2; ++run) {
|
| 175 |
Plugin::FeatureSet fs = p[run]->process(block, timestamp);
|
|
| 163 |
Plugin::FeatureSet fs = p[run]->process(ptr, timestamp);
|
|
| 176 | 164 |
appendFeatures(f[run], fs); |
| 177 | 165 |
} |
| 178 | 166 |
} |
| ... | ... | |
| 182 | 170 |
delete p[run]; |
| 183 | 171 |
} |
| 184 | 172 |
|
| 185 |
if (block) destroyBlock(block, channels);
|
|
| 173 |
if (data) destroyTestAudio(data, channels);
|
|
| 186 | 174 |
|
| 187 | 175 |
if (!(f[0] == f[1])) {
|
| 188 |
r.push_back(warning("Consecutive runs with the same instance (using reset) produce different results"));
|
|
| 176 |
r.push_back(warning("Simultaneous runs with separate instances produce different results"));
|
|
| 189 | 177 |
} else {
|
| 190 | 178 |
r.push_back(success()); |
| 191 | 179 |
} |
| TestOutputs.cpp | ||
|---|---|---|
| 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 "TestOutputs.h" |
|
| 41 |
|
|
| 42 |
#include <vamp-hostsdk/Plugin.h> |
|
| 43 |
using namespace Vamp; |
|
| 44 |
|
|
| 45 |
#include <set> |
|
| 46 |
#include <memory> |
|
| 47 |
using namespace std; |
|
| 48 |
|
|
| 49 |
#include <cmath> |
|
| 50 |
|
|
| 51 |
Tester::TestRegistrar<TestOutputNumbers> |
|
| 52 |
TestOutputNumbers::m_registrar("Output number mismatching");
|
|
| 53 |
|
|
| 54 |
Tester::TestRegistrar<TestTimestamps> |
|
| 55 |
TestTimestamps::m_registrar("Invalid or dubious timestamp usage");
|
|
| 56 |
|
|
| 57 |
static const size_t _step = 1000; |
|
| 58 |
|
|
| 59 |
Test::Results |
|
| 60 |
TestOutputNumbers::test(string key) |
|
| 61 |
{
|
|
| 62 |
int rate = 44100; |
|
| 63 |
auto_ptr<Plugin> p(load(key, rate)); |
|
| 64 |
Plugin::FeatureSet f; |
|
| 65 |
Results r; |
|
| 66 |
float **data = 0; |
|
| 67 |
size_t channels = 0; |
|
| 68 |
size_t count = 100; |
|
| 69 |
|
|
| 70 |
if (!initAdapted(p.get(), channels, _step, _step, r)) return r; |
|
| 71 |
if (!data) data = createTestAudio(channels, _step, count); |
|
| 72 |
for (size_t i = 0; i < count; ++i) {
|
|
| 73 |
float *ptr[channels]; |
|
| 74 |
size_t idx = i * _step; |
|
| 75 |
for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx; |
|
| 76 |
RealTime timestamp = RealTime::frame2RealTime(idx, rate); |
|
| 77 |
Plugin::FeatureSet fs = p->process(ptr, timestamp); |
|
| 78 |
appendFeatures(f, fs); |
|
| 79 |
} |
|
| 80 |
Plugin::FeatureSet fs = p->getRemainingFeatures(); |
|
| 81 |
appendFeatures(f, fs); |
|
| 82 |
if (data) destroyTestAudio(data, channels); |
|
| 83 |
|
|
| 84 |
std::set<int> used; |
|
| 85 |
Plugin::OutputList outputs = p->getOutputDescriptors(); |
|
| 86 |
for (Plugin::FeatureSet::const_iterator i = fs.begin(); |
|
| 87 |
i != fs.end(); ++i) {
|
|
| 88 |
int o = i->first; |
|
| 89 |
used.insert(o); |
|
| 90 |
if (o < 0 || o >= outputs.size()) {
|
|
| 91 |
r.push_back(error("Data returned on nonexistent output"));
|
|
| 92 |
} |
|
| 93 |
} |
|
| 94 |
for (int o = 0; o < outputs.size(); ++o) {
|
|
| 95 |
if (used.find(o) == used.end()) {
|
|
| 96 |
r.push_back(note("No results returned for one or more outputs")); }
|
|
| 97 |
} |
|
| 98 |
|
|
| 99 |
return r; |
|
| 100 |
} |
|
| 101 |
|
|
| 102 |
Test::Results |
|
| 103 |
TestTimestamps::test(string key) |
|
| 104 |
{
|
|
| 105 |
int rate = 44100; |
|
| 106 |
auto_ptr<Plugin> p(load(key, rate)); |
|
| 107 |
Plugin::FeatureSet f; |
|
| 108 |
Results r; |
|
| 109 |
float **data = 0; |
|
| 110 |
size_t channels = 0; |
|
| 111 |
size_t step = 0, block = 0; |
|
| 112 |
size_t count = 100; |
|
| 113 |
|
|
| 114 |
//!!! want to ensure buffer size adapter is not used: |
|
| 115 |
if (!initDefaults(p.get(), channels, step, block, r)) return r; |
|
| 116 |
if (!data) data = createTestAudio(channels, block, count); |
|
| 117 |
for (size_t i = 0; i < count; ++i) {
|
|
| 118 |
float *ptr[channels]; |
|
| 119 |
size_t idx = i * step; |
|
| 120 |
for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx; |
|
| 121 |
RealTime timestamp = RealTime::frame2RealTime(idx, rate); |
|
| 122 |
Plugin::FeatureSet fs = p->process(ptr, timestamp); |
|
| 123 |
appendFeatures(f, fs); |
|
| 124 |
} |
|
| 125 |
Plugin::FeatureSet fs = p->getRemainingFeatures(); |
|
| 126 |
appendFeatures(f, fs); |
|
| 127 |
if (data) destroyTestAudio(data, channels); |
|
| 128 |
|
|
| 129 |
Plugin::OutputList outputs = p->getOutputDescriptors(); |
|
| 130 |
for (Plugin::FeatureSet::const_iterator i = fs.begin(); |
|
| 131 |
i != fs.end(); ++i) {
|
|
| 132 |
const Plugin::OutputDescriptor &o = outputs[i->first]; |
|
| 133 |
const Plugin::FeatureList &fl = i->second; |
|
| 134 |
for (int j = 0; j < (int)fl.size(); ++j) {
|
|
| 135 |
const Plugin::Feature &f = fl[j]; |
|
| 136 |
switch (o.sampleType) {
|
|
| 137 |
case Plugin::OutputDescriptor::OneSamplePerStep: |
|
| 138 |
if (f.hasTimestamp) {
|
|
| 139 |
r.push_back(note("Plugin returns features with timestamps on OneSamplePerStep output"));
|
|
| 140 |
} |
|
| 141 |
if (f.hasDuration) {
|
|
| 142 |
r.push_back(note("Plugin returns features with durations on OneSamplePerStep output"));
|
|
| 143 |
} |
|
| 144 |
break; |
|
| 145 |
case Plugin::OutputDescriptor::FixedSampleRate: |
|
| 146 |
break; |
|
| 147 |
case Plugin::OutputDescriptor::VariableSampleRate: |
|
| 148 |
if (!f.hasTimestamp) {
|
|
| 149 |
r.push_back(error("Plugin returns features with no timestamps on VariableSampleRate output"));
|
|
| 150 |
} |
|
| 151 |
break; |
|
| 152 |
} |
|
| 153 |
} |
|
| 154 |
} |
|
| 155 |
|
|
| 156 |
return r; |
|
| 157 |
} |
|
| TestOutputs.h | ||
|---|---|---|
| 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 |
#ifndef _TEST_OUTPUTS_H_ |
|
| 41 |
#define _TEST_OUTPUTS_H_ |
|
| 42 |
|
|
| 43 |
#include "Test.h" |
|
| 44 |
#include "Tester.h" |
|
| 45 |
|
|
| 46 |
class TestOutputNumbers : public Test |
|
| 47 |
{
|
|
| 48 |
public: |
|
| 49 |
TestOutputNumbers() : Test() { }
|
|
| 50 |
Results test(std::string key); |
|
| 51 |
|
|
| 52 |
protected: |
|
| 53 |
static Tester::TestRegistrar<TestOutputNumbers> m_registrar; |
|
| 54 |
}; |
|
| 55 |
|
|
| 56 |
class TestTimestamps : public Test |
|
| 57 |
{
|
|
| 58 |
public: |
|
| 59 |
TestTimestamps() : Test() { }
|
|
| 60 |
Results test(std::string key); |
|
| 61 |
|
|
| 62 |
protected: |
|
| 63 |
static Tester::TestRegistrar<TestTimestamps> m_registrar; |
|
| 64 |
}; |
|
| 65 |
|
|
| 66 |
|
|
| 67 |
#endif |
|
| Tester.cpp | ||
|---|---|---|
| 100 | 100 |
* Plugin fails when given "normal" random input (just in case!) - DONE |
| 101 | 101 |
|
| 102 | 102 |
* Plugin returns different results if another instance is |
| 103 |
constructed and run "interleaved" with it (from same thread) |
|
| 103 |
constructed and run "interleaved" with it (from same thread) - DONE
|
|
| 104 | 104 |
|
| 105 | 105 |
* Plugin's returned timestamps do not change as expected when |
| 106 | 106 |
run with a different base timestamp for input (though there |
| 107 | 107 |
could be legitimate reasons for this) |
| 108 | 108 |
|
| 109 | 109 |
* Plugin produces different results on second run, after reset |
| 110 |
called |
|
| 110 |
called - DONE
|
|
| 111 | 111 |
|
| 112 | 112 |
* Initial value of a parameter on plugin construction differs |
| 113 | 113 |
from its default value (i.e. plugin produces different |
| ... | ... | |
| 147 | 147 |
for (Registry::const_iterator i = registry().begin(); |
| 148 | 148 |
i != registry().end(); ++i) {
|
| 149 | 149 |
|
| 150 |
std::cerr << " -- Performing test: " << i->first << std::endl;
|
|
| 150 |
std::cout << " -- Performing test: " << i->first << std::endl;
|
|
| 151 | 151 |
|
| 152 | 152 |
Test *test = i->second->makeTest(); |
| 153 | 153 |
Test::Results results = test->test(m_key); |
| ... | ... | |
| 157 | 157 |
switch (results[j].code()) {
|
| 158 | 158 |
case Test::Result::Success: |
| 159 | 159 |
break; |
| 160 |
case Test::Result::Note: |
|
| 161 |
std::cout << " ** NOTE: " << results[j].message() << std::endl; |
|
| 162 |
break; |
|
| 160 | 163 |
case Test::Result::Warning: |
| 161 |
std::cerr << " ** WARNING: " << results[j].message() << std::endl;
|
|
| 164 |
std::cout << " ** WARNING: " << results[j].message() << std::endl;
|
|
| 162 | 165 |
break; |
| 163 | 166 |
case Test::Result::Error: |
| 164 |
std::cerr << " ** ERROR: " << results[j].message() << std::endl;
|
|
| 167 |
std::cout << " ** ERROR: " << results[j].message() << std::endl;
|
|
| 165 | 168 |
good = false; |
| 166 | 169 |
break; |
| 167 | 170 |
} |
| 168 | 171 |
} |
| 169 | 172 |
} |
| 170 | 173 |
} catch (Test::FailedToLoadPlugin) {
|
| 171 |
std::cerr << "ERROR: Failed to load plugin (key = \"" << m_key
|
|
| 174 |
std::cout << "ERROR: Failed to load plugin (key = \"" << m_key
|
|
| 172 | 175 |
<< "\")" << std::endl; |
| 173 | 176 |
} |
| 174 | 177 |
|
| vamp-plugin-tester.cpp | ||
|---|---|---|
| 87 | 87 |
Vamp::HostExt::PluginLoader::PluginKeyList keys = |
| 88 | 88 |
Vamp::HostExt::PluginLoader::getInstance()->listPlugins(); |
| 89 | 89 |
for (int i = 0; i < (int)keys.size(); ++i) {
|
| 90 |
cerr << "Testing plugin: " << keys[i] << endl;
|
|
| 90 |
cout << "Testing plugin: " << keys[i] << endl;
|
|
| 91 | 91 |
Tester tester(keys[i]); |
| 92 | 92 |
if (tester.test()) {
|
| 93 |
cerr << name << ": All tests succeeded for this plugin" << endl;
|
|
| 93 |
cout << name << ": All tests succeeded for this plugin" << endl;
|
|
| 94 | 94 |
} else {
|
| 95 |
cerr << name << ": Some tests failed for this plugin" << endl;
|
|
| 95 |
cout << name << ": Some tests failed for this plugin" << endl;
|
|
| 96 | 96 |
good = false; |
| 97 | 97 |
} |
| 98 |
cerr << endl;
|
|
| 98 |
cout << endl;
|
|
| 99 | 99 |
} |
| 100 | 100 |
if (good) {
|
| 101 |
cerr << name << ": All tests succeeded" << endl;
|
|
| 101 |
cout << name << ": All tests succeeded" << endl;
|
|
| 102 | 102 |
return 0; |
| 103 | 103 |
} else {
|
| 104 |
cerr << name << ": Some tests failed" << endl;
|
|
| 104 |
cout << name << ": Some tests failed" << endl;
|
|
| 105 | 105 |
return 1; |
| 106 | 106 |
} |
| 107 | 107 |
} else {
|
| 108 | 108 |
string key = argv[1]; |
| 109 | 109 |
Tester tester(key); |
| 110 | 110 |
if (tester.test()) {
|
| 111 |
cerr << name << ": All tests succeeded" << endl;
|
|
| 111 |
cout << name << ": All tests succeeded" << endl;
|
|
| 112 | 112 |
return 0; |
| 113 | 113 |
} else {
|
| 114 |
cerr << name << ": Some tests failed" << endl;
|
|
| 114 |
cout << name << ": Some tests failed" << endl;
|
|
| 115 | 115 |
return 1; |
| 116 | 116 |
} |
| 117 | 117 |
} |
Also available in: Unified diff