To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / TestInputExtremes.cpp @ 14:e48fdc8de790
History | View | Annotate | Download (8.06 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 "TestInputExtremes.h" |
| 41 |
|
| 42 |
#include <vamp-hostsdk/Plugin.h> |
| 43 |
using namespace Vamp; |
| 44 |
|
| 45 |
#include <memory> |
| 46 |
using namespace std; |
| 47 |
|
| 48 |
#include <cstdlib> |
| 49 |
#include <cmath> |
| 50 |
|
| 51 |
Tester::TestRegistrar<TestNormalInput> |
| 52 |
TestNormalInput::m_registrar("C1 Normal input");
|
| 53 |
|
| 54 |
Tester::TestRegistrar<TestNoInput> |
| 55 |
TestNoInput::m_registrar("C2 Empty input");
|
| 56 |
|
| 57 |
Tester::TestRegistrar<TestShortInput> |
| 58 |
TestShortInput::m_registrar("C3 Short input");
|
| 59 |
|
| 60 |
Tester::TestRegistrar<TestSilentInput> |
| 61 |
TestSilentInput::m_registrar("C4 Absolutely silent input");
|
| 62 |
|
| 63 |
Tester::TestRegistrar<TestTooLoudInput> |
| 64 |
TestTooLoudInput::m_registrar("C5 Input beyond traditional +/-1 range");
|
| 65 |
|
| 66 |
Tester::TestRegistrar<TestRandomInput> |
| 67 |
TestRandomInput::m_registrar("C6 Random input");
|
| 68 |
|
| 69 |
Test::Results |
| 70 |
TestNormalInput::test(string key, Options options)
|
| 71 |
{
|
| 72 |
Plugin::FeatureSet f; |
| 73 |
int rate = 44100; |
| 74 |
auto_ptr<Plugin> p(load(key, rate)); |
| 75 |
Results r; |
| 76 |
size_t channels, step, blocksize; |
| 77 |
if (!initDefaults(p.get(), channels, step, blocksize, r)) return r; |
| 78 |
float **block = createBlock(channels, blocksize);
|
| 79 |
int idx = 0; |
| 80 |
for (int i = 0; i < 200; ++i) { |
| 81 |
for (size_t j = 0; j < blocksize; ++j) { |
| 82 |
for (size_t c = 0; c < channels; ++c) { |
| 83 |
block[c][j] = sinf(float(idx) / 10.f); |
| 84 |
} |
| 85 |
++idx; |
| 86 |
} |
| 87 |
RealTime timestamp = RealTime::frame2RealTime(idx, rate); |
| 88 |
Plugin::FeatureSet fs = p->process(block, timestamp); |
| 89 |
appendFeatures(f, fs); |
| 90 |
} |
| 91 |
destroyBlock(block, channels); |
| 92 |
Plugin::FeatureSet fs = p->getRemainingFeatures(); |
| 93 |
appendFeatures(f, fs); |
| 94 |
if (allFeaturesValid(f)) {
|
| 95 |
r.push_back(success()); |
| 96 |
} else {
|
| 97 |
r.push_back(warning("plugin returned one or more NaN/inf values"));
|
| 98 |
if (options & Verbose) dump(f);
|
| 99 |
} |
| 100 |
return r;
|
| 101 |
} |
| 102 |
|
| 103 |
Test::Results |
| 104 |
TestNoInput::test(string key, Options options)
|
| 105 |
{
|
| 106 |
auto_ptr<Plugin> p(load(key)); |
| 107 |
Results r; |
| 108 |
size_t channels, step, block; |
| 109 |
if (!initDefaults(p.get(), channels, step, block, r)) return r; |
| 110 |
Plugin::FeatureSet fs = p->getRemainingFeatures(); |
| 111 |
if (allFeaturesValid(fs)) {
|
| 112 |
r.push_back(success()); |
| 113 |
} else {
|
| 114 |
r.push_back(warning("plugin returned one or more NaN/inf values"));
|
| 115 |
} |
| 116 |
return r;
|
| 117 |
} |
| 118 |
|
| 119 |
Test::Results |
| 120 |
TestShortInput::test(string key, Options options)
|
| 121 |
{
|
| 122 |
Plugin::FeatureSet f; |
| 123 |
int rate = 44100; |
| 124 |
auto_ptr<Plugin> p(load(key, rate)); |
| 125 |
Results r; |
| 126 |
size_t channels, step, blocksize; |
| 127 |
if (!initDefaults(p.get(), channels, step, blocksize, r)) return r; |
| 128 |
float **block = createBlock(channels, blocksize);
|
| 129 |
int idx = 0; |
| 130 |
for (size_t j = 0; j < blocksize; ++j) { |
| 131 |
for (size_t c = 0; c < channels; ++c) { |
| 132 |
block[c][j] = sinf(float(idx) / 10.f); |
| 133 |
} |
| 134 |
++idx; |
| 135 |
} |
| 136 |
Plugin::FeatureSet fs = p->process(block, RealTime::zeroTime); |
| 137 |
appendFeatures(f, fs); |
| 138 |
destroyBlock(block, channels); |
| 139 |
fs = p->getRemainingFeatures(); |
| 140 |
appendFeatures(f, fs); |
| 141 |
if (allFeaturesValid(f)) {
|
| 142 |
r.push_back(success()); |
| 143 |
} else {
|
| 144 |
r.push_back(warning("plugin returned one or more NaN/inf values"));
|
| 145 |
if (options & Verbose) dump(f);
|
| 146 |
} |
| 147 |
return r;
|
| 148 |
} |
| 149 |
|
| 150 |
Test::Results |
| 151 |
TestSilentInput::test(string key, Options options)
|
| 152 |
{
|
| 153 |
Plugin::FeatureSet f; |
| 154 |
int rate = 44100; |
| 155 |
auto_ptr<Plugin> p(load(key, rate)); |
| 156 |
Results r; |
| 157 |
size_t channels, step, blocksize; |
| 158 |
if (!initDefaults(p.get(), channels, step, blocksize, r)) return r; |
| 159 |
float **block = createBlock(channels, blocksize);
|
| 160 |
for (size_t j = 0; j < blocksize; ++j) { |
| 161 |
for (size_t c = 0; c < channels; ++c) { |
| 162 |
block[c][j] = 0.f;
|
| 163 |
} |
| 164 |
} |
| 165 |
for (int i = 0; i < 200; ++i) { |
| 166 |
RealTime timestamp = RealTime::frame2RealTime(i * blocksize, rate); |
| 167 |
Plugin::FeatureSet fs = p->process(block, timestamp); |
| 168 |
appendFeatures(f, fs); |
| 169 |
} |
| 170 |
destroyBlock(block, channels); |
| 171 |
Plugin::FeatureSet fs = p->getRemainingFeatures(); |
| 172 |
appendFeatures(f, fs); |
| 173 |
if (allFeaturesValid(f)) {
|
| 174 |
r.push_back(success()); |
| 175 |
} else {
|
| 176 |
r.push_back(warning("plugin returned one or more NaN/inf values"));
|
| 177 |
if (options & Verbose) dump(f);
|
| 178 |
} |
| 179 |
return r;
|
| 180 |
} |
| 181 |
|
| 182 |
Test::Results |
| 183 |
TestTooLoudInput::test(string key, Options options)
|
| 184 |
{
|
| 185 |
Plugin::FeatureSet f; |
| 186 |
int rate = 44100; |
| 187 |
auto_ptr<Plugin> p(load(key, rate)); |
| 188 |
Results r; |
| 189 |
size_t channels, step, blocksize; |
| 190 |
if (!initDefaults(p.get(), channels, step, blocksize, r)) return r; |
| 191 |
float **block = createBlock(channels, blocksize);
|
| 192 |
int idx = 0; |
| 193 |
for (int i = 0; i < 200; ++i) { |
| 194 |
for (size_t j = 0; j < blocksize; ++j) { |
| 195 |
for (size_t c = 0; c < channels; ++c) { |
| 196 |
block[c][j] = 1000.f * sinf(float(idx) / 10.f); |
| 197 |
} |
| 198 |
++idx; |
| 199 |
} |
| 200 |
RealTime timestamp = RealTime::frame2RealTime(idx, rate); |
| 201 |
Plugin::FeatureSet fs = p->process(block, timestamp); |
| 202 |
appendFeatures(f, fs); |
| 203 |
} |
| 204 |
destroyBlock(block, channels); |
| 205 |
Plugin::FeatureSet fs = p->getRemainingFeatures(); |
| 206 |
appendFeatures(f, fs); |
| 207 |
if (allFeaturesValid(f)) {
|
| 208 |
r.push_back(success()); |
| 209 |
} else {
|
| 210 |
r.push_back(warning("plugin returned one or more NaN/inf values"));
|
| 211 |
if (options & Verbose) dump(f);
|
| 212 |
} |
| 213 |
return r;
|
| 214 |
} |
| 215 |
|
| 216 |
Test::Results |
| 217 |
TestRandomInput::test(string key, Options options)
|
| 218 |
{
|
| 219 |
Plugin::FeatureSet f; |
| 220 |
int rate = 44100; |
| 221 |
auto_ptr<Plugin> p(load(key, rate)); |
| 222 |
Results r; |
| 223 |
size_t channels, step, blocksize; |
| 224 |
if (!initDefaults(p.get(), channels, step, blocksize, r)) return r; |
| 225 |
float **block = createBlock(channels, blocksize);
|
| 226 |
int idx = 0; |
| 227 |
for (int i = 0; i < 100; ++i) { |
| 228 |
for (size_t j = 0; j < blocksize; ++j) { |
| 229 |
for (size_t c = 0; c < channels; ++c) { |
| 230 |
block[c][j] = float(drand48() * 2.0 - 1.0); |
| 231 |
} |
| 232 |
++idx; |
| 233 |
} |
| 234 |
RealTime timestamp = RealTime::frame2RealTime(idx, rate); |
| 235 |
Plugin::FeatureSet fs = p->process(block, timestamp); |
| 236 |
appendFeatures(f, fs); |
| 237 |
} |
| 238 |
destroyBlock(block, channels); |
| 239 |
Plugin::FeatureSet fs = p->getRemainingFeatures(); |
| 240 |
appendFeatures(f, fs); |
| 241 |
if (allFeaturesValid(f)) {
|
| 242 |
r.push_back(success()); |
| 243 |
} else {
|
| 244 |
r.push_back(warning("plugin returned one or more NaN/inf values"));
|
| 245 |
if (options & Verbose) dump(f);
|
| 246 |
} |
| 247 |
return r;
|
| 248 |
} |
| 249 |
|