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.
|
cannam@3
|
7 Copyright 2009 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>
|
cannam@4
|
54 TestOutputNumbers::m_registrar("B1 Output number mismatching");
|
cannam@3
|
55
|
cannam@3
|
56 Tester::TestRegistrar<TestTimestamps>
|
cannam@4
|
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) {
|
cannam@3
|
75 float *ptr[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);
|
cannam@3
|
80 appendFeatures(f, fs);
|
cannam@3
|
81 }
|
cannam@3
|
82 Plugin::FeatureSet fs = p->getRemainingFeatures();
|
cannam@3
|
83 appendFeatures(f, fs);
|
cannam@3
|
84 if (data) destroyTestAudio(data, channels);
|
cannam@3
|
85
|
cannam@3
|
86 std::set<int> used;
|
cannam@3
|
87 Plugin::OutputList outputs = p->getOutputDescriptors();
|
cannam@5
|
88 for (Plugin::FeatureSet::const_iterator i = f.begin();
|
cannam@5
|
89 i != f.end(); ++i) {
|
cannam@3
|
90 int o = i->first;
|
cannam@3
|
91 used.insert(o);
|
cannam@4
|
92 if (o < 0 || o >= (int)outputs.size()) {
|
cannam@3
|
93 r.push_back(error("Data returned on nonexistent output"));
|
cannam@3
|
94 }
|
cannam@3
|
95 }
|
cannam@4
|
96 for (int o = 0; o < (int)outputs.size(); ++o) {
|
cannam@3
|
97 if (used.find(o) == used.end()) {
|
cannam@12
|
98 r.push_back(note("No results returned for output \"" + outputs[o].identifier + "\""));
|
cannam@4
|
99 }
|
cannam@3
|
100 }
|
cannam@3
|
101
|
cannam@8
|
102 if (!r.empty() && (options & Verbose)) dump(f);
|
cannam@3
|
103 return r;
|
cannam@3
|
104 }
|
cannam@3
|
105
|
cannam@3
|
106 Test::Results
|
cannam@8
|
107 TestTimestamps::test(string key, Options options)
|
cannam@3
|
108 {
|
cannam@3
|
109 int rate = 44100;
|
cannam@4
|
110
|
cannam@4
|
111 // we want to be sure that a buffer size adapter is not used:
|
cannam@4
|
112 auto_ptr<Plugin> p(PluginLoader::getInstance()->loadPlugin
|
cannam@4
|
113 (key, rate, PluginLoader::ADAPT_ALL_SAFE));
|
cannam@4
|
114
|
cannam@3
|
115 Plugin::FeatureSet f;
|
cannam@3
|
116 Results r;
|
cannam@3
|
117 float **data = 0;
|
cannam@3
|
118 size_t channels = 0;
|
cannam@3
|
119 size_t step = 0, block = 0;
|
cannam@3
|
120 size_t count = 100;
|
cannam@3
|
121
|
cannam@3
|
122 if (!initDefaults(p.get(), channels, step, block, r)) return r;
|
cannam@3
|
123 if (!data) data = createTestAudio(channels, block, count);
|
cannam@3
|
124 for (size_t i = 0; i < count; ++i) {
|
cannam@3
|
125 float *ptr[channels];
|
cannam@3
|
126 size_t idx = i * step;
|
cannam@3
|
127 for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
|
cannam@3
|
128 RealTime timestamp = RealTime::frame2RealTime(idx, rate);
|
cannam@3
|
129 Plugin::FeatureSet fs = p->process(ptr, timestamp);
|
cannam@3
|
130 appendFeatures(f, fs);
|
cannam@3
|
131 }
|
cannam@3
|
132 Plugin::FeatureSet fs = p->getRemainingFeatures();
|
cannam@3
|
133 appendFeatures(f, fs);
|
cannam@3
|
134 if (data) destroyTestAudio(data, channels);
|
cannam@3
|
135
|
cannam@3
|
136 Plugin::OutputList outputs = p->getOutputDescriptors();
|
cannam@5
|
137 for (Plugin::FeatureSet::const_iterator i = f.begin();
|
cannam@5
|
138 i != f.end(); ++i) {
|
cannam@3
|
139 const Plugin::OutputDescriptor &o = outputs[i->first];
|
cannam@3
|
140 const Plugin::FeatureList &fl = i->second;
|
cannam@3
|
141 for (int j = 0; j < (int)fl.size(); ++j) {
|
cannam@5
|
142 const Plugin::Feature &fe = fl[j];
|
cannam@3
|
143 switch (o.sampleType) {
|
cannam@3
|
144 case Plugin::OutputDescriptor::OneSamplePerStep:
|
cannam@5
|
145 if (fe.hasTimestamp) {
|
cannam@3
|
146 r.push_back(note("Plugin returns features with timestamps on OneSamplePerStep output"));
|
cannam@3
|
147 }
|
cannam@5
|
148 if (fe.hasDuration) {
|
cannam@3
|
149 r.push_back(note("Plugin returns features with durations on OneSamplePerStep output"));
|
cannam@3
|
150 }
|
cannam@3
|
151 break;
|
cannam@3
|
152 case Plugin::OutputDescriptor::FixedSampleRate:
|
cannam@3
|
153 break;
|
cannam@3
|
154 case Plugin::OutputDescriptor::VariableSampleRate:
|
cannam@5
|
155 if (!fe.hasTimestamp) {
|
cannam@3
|
156 r.push_back(error("Plugin returns features with no timestamps on VariableSampleRate output"));
|
cannam@3
|
157 }
|
cannam@3
|
158 break;
|
cannam@3
|
159 }
|
cannam@3
|
160 }
|
cannam@3
|
161 }
|
cannam@3
|
162
|
cannam@8
|
163 if (!r.empty() && (options & Verbose)) dump(f);
|
cannam@3
|
164 return r;
|
cannam@3
|
165 }
|