annotate TestOutputs.cpp @ 80:f84e12a1553c tip

Update server certificate fingerprints
author Chris Cannam
date Wed, 14 Aug 2019 14:58:48 +0100
parents fa66ee7dcf08
children
rev   line source
cannam@3 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
cannam@3 2
cannam@3 3 /*
cannam@3 4 Vamp Plugin Tester
cannam@3 5 Chris Cannam, cannam@all-day-breakfast.com
cannam@3 6 Centre for Digital Music, Queen Mary, University of London.
Chris@42 7 Copyright 2009-2014 QMUL.
cannam@3 8
cannam@3 9 This program loads a Vamp plugin and tests its susceptibility to a
cannam@3 10 number of common pitfalls, including handling of extremes of input
cannam@3 11 data. If you can think of any additional useful tests that are
cannam@3 12 easily added, please send them to me.
cannam@3 13
cannam@3 14 Permission is hereby granted, free of charge, to any person
cannam@3 15 obtaining a copy of this software and associated documentation
cannam@3 16 files (the "Software"), to deal in the Software without
cannam@3 17 restriction, including without limitation the rights to use, copy,
cannam@3 18 modify, merge, publish, distribute, sublicense, and/or sell copies
cannam@3 19 of the Software, and to permit persons to whom the Software is
cannam@3 20 furnished to do so, subject to the following conditions:
cannam@3 21
cannam@3 22 The above copyright notice and this permission notice shall be
cannam@3 23 included in all copies or substantial portions of the Software.
cannam@3 24
cannam@3 25 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
cannam@3 26 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
cannam@3 27 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
cannam@3 28 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
cannam@3 29 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
cannam@3 30 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
cannam@3 31 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
cannam@3 32
cannam@3 33 Except as contained in this notice, the names of the Centre for
cannam@3 34 Digital Music; Queen Mary, University of London; and Chris Cannam
cannam@3 35 shall not be used in advertising or otherwise to promote the sale,
cannam@3 36 use or other dealings in this Software without prior written
cannam@3 37 authorization.
cannam@3 38 */
cannam@3 39
cannam@3 40 #include "TestOutputs.h"
cannam@3 41
cannam@3 42 #include <vamp-hostsdk/Plugin.h>
cannam@4 43 #include <vamp-hostsdk/PluginLoader.h>
cannam@3 44 using namespace Vamp;
cannam@4 45 using namespace Vamp::HostExt;
cannam@3 46
cannam@3 47 #include <set>
cannam@3 48 #include <memory>
cannam@3 49 using namespace std;
cannam@3 50
cannam@3 51 #include <cmath>
cannam@3 52
cannam@3 53 Tester::TestRegistrar<TestOutputNumbers>
Chris@39 54 TestOutputNumbers::m_registrar("B1", "Output number mismatching");
cannam@3 55
cannam@3 56 Tester::TestRegistrar<TestTimestamps>
Chris@39 57 TestTimestamps::m_registrar("B2", "Invalid or dubious timestamp usage");
cannam@3 58
cannam@3 59 static const size_t _step = 1000;
cannam@3 60
cannam@3 61 Test::Results
cannam@8 62 TestOutputNumbers::test(string key, Options options)
cannam@3 63 {
cannam@3 64 int rate = 44100;
cannam@3 65 auto_ptr<Plugin> p(load(key, rate));
cannam@3 66 Plugin::FeatureSet f;
cannam@3 67 Results r;
cannam@3 68 float **data = 0;
cannam@3 69 size_t channels = 0;
cannam@3 70 size_t count = 100;
cannam@3 71
cannam@3 72 if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
cannam@3 73 if (!data) data = createTestAudio(channels, _step, count);
cannam@3 74 for (size_t i = 0; i < count; ++i) {
Chris@67 75 float **ptr = new float *[channels];
cannam@3 76 size_t idx = i * _step;
cannam@3 77 for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
cannam@3 78 RealTime timestamp = RealTime::frame2RealTime(idx, rate);
cannam@3 79 Plugin::FeatureSet fs = p->process(ptr, timestamp);
Chris@67 80 delete[] ptr;
cannam@3 81 appendFeatures(f, fs);
cannam@3 82 }
cannam@3 83 Plugin::FeatureSet fs = p->getRemainingFeatures();
cannam@3 84 appendFeatures(f, fs);
cannam@3 85 if (data) destroyTestAudio(data, channels);
cannam@3 86
cannam@3 87 std::set<int> used;
cannam@3 88 Plugin::OutputList outputs = p->getOutputDescriptors();
cannam@5 89 for (Plugin::FeatureSet::const_iterator i = f.begin();
cannam@5 90 i != f.end(); ++i) {
cannam@3 91 int o = i->first;
cannam@3 92 used.insert(o);
cannam@4 93 if (o < 0 || o >= (int)outputs.size()) {
cannam@3 94 r.push_back(error("Data returned on nonexistent output"));
cannam@3 95 }
cannam@3 96 }
cannam@4 97 for (int o = 0; o < (int)outputs.size(); ++o) {
cannam@3 98 if (used.find(o) == used.end()) {
cannam@12 99 r.push_back(note("No results returned for output \"" + outputs[o].identifier + "\""));
cannam@4 100 }
cannam@3 101 }
cannam@3 102
cannam@8 103 if (!r.empty() && (options & Verbose)) dump(f);
cannam@3 104 return r;
cannam@3 105 }
cannam@3 106
cannam@3 107 Test::Results
cannam@8 108 TestTimestamps::test(string key, Options options)
cannam@3 109 {
cannam@3 110 int rate = 44100;
cannam@4 111
cannam@4 112 // we want to be sure that a buffer size adapter is not used:
cannam@4 113 auto_ptr<Plugin> p(PluginLoader::getInstance()->loadPlugin
cannam@4 114 (key, rate, PluginLoader::ADAPT_ALL_SAFE));
cannam@4 115
Chris@60 116 Results r;
cannam@3 117 Plugin::FeatureSet f;
cannam@3 118 float **data = 0;
cannam@3 119 size_t channels = 0;
cannam@3 120 size_t step = 0, block = 0;
cannam@3 121 size_t count = 100;
cannam@3 122
cannam@3 123 if (!initDefaults(p.get(), channels, step, block, r)) return r;
Chris@60 124
Chris@60 125 Plugin::OutputList outputs = p->getOutputDescriptors();
Chris@60 126 for (int i = 0; i < (int)outputs.size(); ++i) {
Chris@60 127 if (outputs[i].sampleType == Plugin::OutputDescriptor::FixedSampleRate &&
Chris@60 128 outputs[i].sampleRate == 0.f) {
Chris@60 129 r.push_back(error("Plugin output \"" + outputs[i].identifier +
Chris@60 130 "\" has FixedSampleRate but gives sample rate as 0"));
Chris@60 131 }
Chris@60 132 }
Chris@60 133
cannam@3 134 if (!data) data = createTestAudio(channels, block, count);
cannam@3 135 for (size_t i = 0; i < count; ++i) {
Chris@67 136 float **ptr = new float *[channels];
cannam@3 137 size_t idx = i * step;
cannam@3 138 for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
cannam@3 139 RealTime timestamp = RealTime::frame2RealTime(idx, rate);
cannam@3 140 Plugin::FeatureSet fs = p->process(ptr, timestamp);
Chris@67 141 delete[] ptr;
cannam@3 142 appendFeatures(f, fs);
cannam@3 143 }
cannam@3 144 Plugin::FeatureSet fs = p->getRemainingFeatures();
cannam@3 145 appendFeatures(f, fs);
cannam@3 146 if (data) destroyTestAudio(data, channels);
cannam@3 147
cannam@5 148 for (Plugin::FeatureSet::const_iterator i = f.begin();
cannam@5 149 i != f.end(); ++i) {
cannam@3 150 const Plugin::OutputDescriptor &o = outputs[i->first];
cannam@3 151 const Plugin::FeatureList &fl = i->second;
cannam@3 152 for (int j = 0; j < (int)fl.size(); ++j) {
cannam@5 153 const Plugin::Feature &fe = fl[j];
cannam@3 154 switch (o.sampleType) {
cannam@3 155 case Plugin::OutputDescriptor::OneSamplePerStep:
cannam@5 156 if (fe.hasTimestamp) {
Chris@31 157 r.push_back(note("Plugin returns features with timestamps on OneSamplePerStep output \"" + o.identifier + "\""));
cannam@3 158 }
cannam@5 159 if (fe.hasDuration) {
Chris@31 160 r.push_back(note("Plugin returns features with durations on OneSamplePerStep output \"" + o.identifier + "\""));
cannam@3 161 }
cannam@3 162 break;
cannam@3 163 case Plugin::OutputDescriptor::FixedSampleRate:
cannam@3 164 break;
cannam@3 165 case Plugin::OutputDescriptor::VariableSampleRate:
cannam@5 166 if (!fe.hasTimestamp) {
Chris@31 167 r.push_back(error("Plugin returns features with no timestamps on VariableSampleRate output \"" + o.identifier + "\""));
cannam@3 168 }
cannam@3 169 break;
cannam@3 170 }
cannam@3 171 }
cannam@3 172 }
cannam@3 173
cannam@8 174 if (!r.empty() && (options & Verbose)) dump(f);
cannam@3 175 return r;
cannam@3 176 }