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@28
|
53 #ifndef __GNUC__
|
cannam@28
|
54 #include <alloca.h>
|
cannam@28
|
55 #endif
|
cannam@28
|
56
|
cannam@3
|
57 Tester::TestRegistrar<TestOutputNumbers>
|
Chris@39
|
58 TestOutputNumbers::m_registrar("B1", "Output number mismatching");
|
cannam@3
|
59
|
cannam@3
|
60 Tester::TestRegistrar<TestTimestamps>
|
Chris@39
|
61 TestTimestamps::m_registrar("B2", "Invalid or dubious timestamp usage");
|
cannam@3
|
62
|
cannam@3
|
63 static const size_t _step = 1000;
|
cannam@3
|
64
|
cannam@3
|
65 Test::Results
|
cannam@8
|
66 TestOutputNumbers::test(string key, Options options)
|
cannam@3
|
67 {
|
cannam@3
|
68 int rate = 44100;
|
cannam@3
|
69 auto_ptr<Plugin> p(load(key, rate));
|
cannam@3
|
70 Plugin::FeatureSet f;
|
cannam@3
|
71 Results r;
|
cannam@3
|
72 float **data = 0;
|
cannam@3
|
73 size_t channels = 0;
|
cannam@3
|
74 size_t count = 100;
|
cannam@3
|
75
|
cannam@3
|
76 if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
|
cannam@3
|
77 if (!data) data = createTestAudio(channels, _step, count);
|
cannam@3
|
78 for (size_t i = 0; i < count; ++i) {
|
cannam@28
|
79 #ifdef __GNUC__
|
cannam@3
|
80 float *ptr[channels];
|
cannam@28
|
81 #else
|
cannam@28
|
82 float **ptr = (float **)alloca(channels * sizeof(float));
|
cannam@28
|
83 #endif
|
cannam@3
|
84 size_t idx = i * _step;
|
cannam@3
|
85 for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
|
cannam@3
|
86 RealTime timestamp = RealTime::frame2RealTime(idx, rate);
|
cannam@3
|
87 Plugin::FeatureSet fs = p->process(ptr, timestamp);
|
cannam@3
|
88 appendFeatures(f, fs);
|
cannam@3
|
89 }
|
cannam@3
|
90 Plugin::FeatureSet fs = p->getRemainingFeatures();
|
cannam@3
|
91 appendFeatures(f, fs);
|
cannam@3
|
92 if (data) destroyTestAudio(data, channels);
|
cannam@3
|
93
|
cannam@3
|
94 std::set<int> used;
|
cannam@3
|
95 Plugin::OutputList outputs = p->getOutputDescriptors();
|
cannam@5
|
96 for (Plugin::FeatureSet::const_iterator i = f.begin();
|
cannam@5
|
97 i != f.end(); ++i) {
|
cannam@3
|
98 int o = i->first;
|
cannam@3
|
99 used.insert(o);
|
cannam@4
|
100 if (o < 0 || o >= (int)outputs.size()) {
|
cannam@3
|
101 r.push_back(error("Data returned on nonexistent output"));
|
cannam@3
|
102 }
|
cannam@3
|
103 }
|
cannam@4
|
104 for (int o = 0; o < (int)outputs.size(); ++o) {
|
cannam@3
|
105 if (used.find(o) == used.end()) {
|
cannam@12
|
106 r.push_back(note("No results returned for output \"" + outputs[o].identifier + "\""));
|
cannam@4
|
107 }
|
cannam@3
|
108 }
|
cannam@3
|
109
|
cannam@8
|
110 if (!r.empty() && (options & Verbose)) dump(f);
|
cannam@3
|
111 return r;
|
cannam@3
|
112 }
|
cannam@3
|
113
|
cannam@3
|
114 Test::Results
|
cannam@8
|
115 TestTimestamps::test(string key, Options options)
|
cannam@3
|
116 {
|
cannam@3
|
117 int rate = 44100;
|
cannam@4
|
118
|
cannam@4
|
119 // we want to be sure that a buffer size adapter is not used:
|
cannam@4
|
120 auto_ptr<Plugin> p(PluginLoader::getInstance()->loadPlugin
|
cannam@4
|
121 (key, rate, PluginLoader::ADAPT_ALL_SAFE));
|
cannam@4
|
122
|
cannam@3
|
123 Plugin::FeatureSet f;
|
cannam@3
|
124 Results r;
|
cannam@3
|
125 float **data = 0;
|
cannam@3
|
126 size_t channels = 0;
|
cannam@3
|
127 size_t step = 0, block = 0;
|
cannam@3
|
128 size_t count = 100;
|
cannam@3
|
129
|
cannam@3
|
130 if (!initDefaults(p.get(), channels, step, block, r)) return r;
|
cannam@3
|
131 if (!data) data = createTestAudio(channels, block, count);
|
cannam@3
|
132 for (size_t i = 0; i < count; ++i) {
|
cannam@28
|
133 #ifdef __GNUC__
|
cannam@3
|
134 float *ptr[channels];
|
cannam@28
|
135 #else
|
cannam@28
|
136 float **ptr = (float **)alloca(channels * sizeof(float));
|
cannam@28
|
137 #endif
|
cannam@3
|
138 size_t idx = i * step;
|
cannam@3
|
139 for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
|
cannam@3
|
140 RealTime timestamp = RealTime::frame2RealTime(idx, rate);
|
cannam@3
|
141 Plugin::FeatureSet fs = p->process(ptr, timestamp);
|
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@3
|
148 Plugin::OutputList outputs = p->getOutputDescriptors();
|
cannam@5
|
149 for (Plugin::FeatureSet::const_iterator i = f.begin();
|
cannam@5
|
150 i != f.end(); ++i) {
|
cannam@3
|
151 const Plugin::OutputDescriptor &o = outputs[i->first];
|
cannam@3
|
152 const Plugin::FeatureList &fl = i->second;
|
cannam@3
|
153 for (int j = 0; j < (int)fl.size(); ++j) {
|
cannam@5
|
154 const Plugin::Feature &fe = fl[j];
|
cannam@3
|
155 switch (o.sampleType) {
|
cannam@3
|
156 case Plugin::OutputDescriptor::OneSamplePerStep:
|
cannam@5
|
157 if (fe.hasTimestamp) {
|
Chris@31
|
158 r.push_back(note("Plugin returns features with timestamps on OneSamplePerStep output \"" + o.identifier + "\""));
|
cannam@3
|
159 }
|
cannam@5
|
160 if (fe.hasDuration) {
|
Chris@31
|
161 r.push_back(note("Plugin returns features with durations on OneSamplePerStep output \"" + o.identifier + "\""));
|
cannam@3
|
162 }
|
cannam@3
|
163 break;
|
cannam@3
|
164 case Plugin::OutputDescriptor::FixedSampleRate:
|
cannam@3
|
165 break;
|
cannam@3
|
166 case Plugin::OutputDescriptor::VariableSampleRate:
|
cannam@5
|
167 if (!fe.hasTimestamp) {
|
Chris@31
|
168 r.push_back(error("Plugin returns features with no timestamps on VariableSampleRate output \"" + o.identifier + "\""));
|
cannam@3
|
169 }
|
cannam@3
|
170 break;
|
cannam@3
|
171 }
|
cannam@3
|
172 }
|
cannam@3
|
173 }
|
cannam@3
|
174
|
cannam@8
|
175 if (!r.empty() && (options & Verbose)) dump(f);
|
cannam@3
|
176 return r;
|
cannam@3
|
177 }
|