To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / TestOutputs.cpp @ 12:7dd6a549b2f9
History | View | Annotate | Download (5.97 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 "TestOutputs.h" |
| 41 |
|
| 42 |
#include <vamp-hostsdk/Plugin.h> |
| 43 |
#include <vamp-hostsdk/PluginLoader.h> |
| 44 |
using namespace Vamp; |
| 45 |
using namespace Vamp::HostExt; |
| 46 |
|
| 47 |
#include <set> |
| 48 |
#include <memory> |
| 49 |
using namespace std; |
| 50 |
|
| 51 |
#include <cmath> |
| 52 |
|
| 53 |
Tester::TestRegistrar<TestOutputNumbers> |
| 54 |
TestOutputNumbers::m_registrar("B1 Output number mismatching");
|
| 55 |
|
| 56 |
Tester::TestRegistrar<TestTimestamps> |
| 57 |
TestTimestamps::m_registrar("B2 Invalid or dubious timestamp usage");
|
| 58 |
|
| 59 |
static const size_t _step = 1000; |
| 60 |
|
| 61 |
Test::Results |
| 62 |
TestOutputNumbers::test(string key, Options options)
|
| 63 |
{
|
| 64 |
int rate = 44100; |
| 65 |
auto_ptr<Plugin> p(load(key, rate)); |
| 66 |
Plugin::FeatureSet f; |
| 67 |
Results r; |
| 68 |
float **data = 0; |
| 69 |
size_t channels = 0;
|
| 70 |
size_t count = 100;
|
| 71 |
|
| 72 |
if (!initAdapted(p.get(), channels, _step, _step, r)) return r; |
| 73 |
if (!data) data = createTestAudio(channels, _step, count);
|
| 74 |
for (size_t i = 0; i < count; ++i) { |
| 75 |
float *ptr[channels];
|
| 76 |
size_t idx = i * _step; |
| 77 |
for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx; |
| 78 |
RealTime timestamp = RealTime::frame2RealTime(idx, rate); |
| 79 |
Plugin::FeatureSet fs = p->process(ptr, timestamp); |
| 80 |
appendFeatures(f, fs); |
| 81 |
} |
| 82 |
Plugin::FeatureSet fs = p->getRemainingFeatures(); |
| 83 |
appendFeatures(f, fs); |
| 84 |
if (data) destroyTestAudio(data, channels);
|
| 85 |
|
| 86 |
std::set<int> used;
|
| 87 |
Plugin::OutputList outputs = p->getOutputDescriptors(); |
| 88 |
for (Plugin::FeatureSet::const_iterator i = f.begin();
|
| 89 |
i != f.end(); ++i) {
|
| 90 |
int o = i->first;
|
| 91 |
used.insert(o); |
| 92 |
if (o < 0 || o >= (int)outputs.size()) { |
| 93 |
r.push_back(error("Data returned on nonexistent output"));
|
| 94 |
} |
| 95 |
} |
| 96 |
for (int o = 0; o < (int)outputs.size(); ++o) { |
| 97 |
if (used.find(o) == used.end()) {
|
| 98 |
r.push_back(note("No results returned for output \"" + outputs[o].identifier + "\"")); |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
if (!r.empty() && (options & Verbose)) dump(f);
|
| 103 |
return r;
|
| 104 |
} |
| 105 |
|
| 106 |
Test::Results |
| 107 |
TestTimestamps::test(string key, Options options)
|
| 108 |
{
|
| 109 |
int rate = 44100; |
| 110 |
|
| 111 |
// we want to be sure that a buffer size adapter is not used:
|
| 112 |
auto_ptr<Plugin> p(PluginLoader::getInstance()->loadPlugin |
| 113 |
(key, rate, PluginLoader::ADAPT_ALL_SAFE)); |
| 114 |
|
| 115 |
Plugin::FeatureSet f; |
| 116 |
Results r; |
| 117 |
float **data = 0; |
| 118 |
size_t channels = 0;
|
| 119 |
size_t step = 0, block = 0; |
| 120 |
size_t count = 100;
|
| 121 |
|
| 122 |
if (!initDefaults(p.get(), channels, step, block, r)) return r; |
| 123 |
if (!data) data = createTestAudio(channels, block, count);
|
| 124 |
for (size_t i = 0; i < count; ++i) { |
| 125 |
float *ptr[channels];
|
| 126 |
size_t idx = i * step; |
| 127 |
for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx; |
| 128 |
RealTime timestamp = RealTime::frame2RealTime(idx, rate); |
| 129 |
Plugin::FeatureSet fs = p->process(ptr, timestamp); |
| 130 |
appendFeatures(f, fs); |
| 131 |
} |
| 132 |
Plugin::FeatureSet fs = p->getRemainingFeatures(); |
| 133 |
appendFeatures(f, fs); |
| 134 |
if (data) destroyTestAudio(data, channels);
|
| 135 |
|
| 136 |
Plugin::OutputList outputs = p->getOutputDescriptors(); |
| 137 |
for (Plugin::FeatureSet::const_iterator i = f.begin();
|
| 138 |
i != f.end(); ++i) {
|
| 139 |
const Plugin::OutputDescriptor &o = outputs[i->first];
|
| 140 |
const Plugin::FeatureList &fl = i->second;
|
| 141 |
for (int j = 0; j < (int)fl.size(); ++j) { |
| 142 |
const Plugin::Feature &fe = fl[j];
|
| 143 |
switch (o.sampleType) {
|
| 144 |
case Plugin::OutputDescriptor::OneSamplePerStep:
|
| 145 |
if (fe.hasTimestamp) {
|
| 146 |
r.push_back(note("Plugin returns features with timestamps on OneSamplePerStep output"));
|
| 147 |
} |
| 148 |
if (fe.hasDuration) {
|
| 149 |
r.push_back(note("Plugin returns features with durations on OneSamplePerStep output"));
|
| 150 |
} |
| 151 |
break;
|
| 152 |
case Plugin::OutputDescriptor::FixedSampleRate:
|
| 153 |
break;
|
| 154 |
case Plugin::OutputDescriptor::VariableSampleRate:
|
| 155 |
if (!fe.hasTimestamp) {
|
| 156 |
r.push_back(error("Plugin returns features with no timestamps on VariableSampleRate output"));
|
| 157 |
} |
| 158 |
break;
|
| 159 |
} |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
if (!r.empty() && (options & Verbose)) dump(f);
|
| 164 |
return r;
|
| 165 |
} |