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@3
|
43 using namespace Vamp;
|
cannam@3
|
44
|
cannam@3
|
45 #include <set>
|
cannam@3
|
46 #include <memory>
|
cannam@3
|
47 using namespace std;
|
cannam@3
|
48
|
cannam@3
|
49 #include <cmath>
|
cannam@3
|
50
|
cannam@3
|
51 Tester::TestRegistrar<TestOutputNumbers>
|
cannam@3
|
52 TestOutputNumbers::m_registrar("Output number mismatching");
|
cannam@3
|
53
|
cannam@3
|
54 Tester::TestRegistrar<TestTimestamps>
|
cannam@3
|
55 TestTimestamps::m_registrar("Invalid or dubious timestamp usage");
|
cannam@3
|
56
|
cannam@3
|
57 static const size_t _step = 1000;
|
cannam@3
|
58
|
cannam@3
|
59 Test::Results
|
cannam@3
|
60 TestOutputNumbers::test(string key)
|
cannam@3
|
61 {
|
cannam@3
|
62 int rate = 44100;
|
cannam@3
|
63 auto_ptr<Plugin> p(load(key, rate));
|
cannam@3
|
64 Plugin::FeatureSet f;
|
cannam@3
|
65 Results r;
|
cannam@3
|
66 float **data = 0;
|
cannam@3
|
67 size_t channels = 0;
|
cannam@3
|
68 size_t count = 100;
|
cannam@3
|
69
|
cannam@3
|
70 if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
|
cannam@3
|
71 if (!data) data = createTestAudio(channels, _step, count);
|
cannam@3
|
72 for (size_t i = 0; i < count; ++i) {
|
cannam@3
|
73 float *ptr[channels];
|
cannam@3
|
74 size_t idx = i * _step;
|
cannam@3
|
75 for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
|
cannam@3
|
76 RealTime timestamp = RealTime::frame2RealTime(idx, rate);
|
cannam@3
|
77 Plugin::FeatureSet fs = p->process(ptr, timestamp);
|
cannam@3
|
78 appendFeatures(f, fs);
|
cannam@3
|
79 }
|
cannam@3
|
80 Plugin::FeatureSet fs = p->getRemainingFeatures();
|
cannam@3
|
81 appendFeatures(f, fs);
|
cannam@3
|
82 if (data) destroyTestAudio(data, channels);
|
cannam@3
|
83
|
cannam@3
|
84 std::set<int> used;
|
cannam@3
|
85 Plugin::OutputList outputs = p->getOutputDescriptors();
|
cannam@3
|
86 for (Plugin::FeatureSet::const_iterator i = fs.begin();
|
cannam@3
|
87 i != fs.end(); ++i) {
|
cannam@3
|
88 int o = i->first;
|
cannam@3
|
89 used.insert(o);
|
cannam@3
|
90 if (o < 0 || o >= outputs.size()) {
|
cannam@3
|
91 r.push_back(error("Data returned on nonexistent output"));
|
cannam@3
|
92 }
|
cannam@3
|
93 }
|
cannam@3
|
94 for (int o = 0; o < outputs.size(); ++o) {
|
cannam@3
|
95 if (used.find(o) == used.end()) {
|
cannam@3
|
96 r.push_back(note("No results returned for one or more outputs")); }
|
cannam@3
|
97 }
|
cannam@3
|
98
|
cannam@3
|
99 return r;
|
cannam@3
|
100 }
|
cannam@3
|
101
|
cannam@3
|
102 Test::Results
|
cannam@3
|
103 TestTimestamps::test(string key)
|
cannam@3
|
104 {
|
cannam@3
|
105 int rate = 44100;
|
cannam@3
|
106 auto_ptr<Plugin> p(load(key, rate));
|
cannam@3
|
107 Plugin::FeatureSet f;
|
cannam@3
|
108 Results r;
|
cannam@3
|
109 float **data = 0;
|
cannam@3
|
110 size_t channels = 0;
|
cannam@3
|
111 size_t step = 0, block = 0;
|
cannam@3
|
112 size_t count = 100;
|
cannam@3
|
113
|
cannam@3
|
114 //!!! want to ensure buffer size adapter is not used:
|
cannam@3
|
115 if (!initDefaults(p.get(), channels, step, block, r)) return r;
|
cannam@3
|
116 if (!data) data = createTestAudio(channels, block, count);
|
cannam@3
|
117 for (size_t i = 0; i < count; ++i) {
|
cannam@3
|
118 float *ptr[channels];
|
cannam@3
|
119 size_t idx = i * step;
|
cannam@3
|
120 for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
|
cannam@3
|
121 RealTime timestamp = RealTime::frame2RealTime(idx, rate);
|
cannam@3
|
122 Plugin::FeatureSet fs = p->process(ptr, timestamp);
|
cannam@3
|
123 appendFeatures(f, fs);
|
cannam@3
|
124 }
|
cannam@3
|
125 Plugin::FeatureSet fs = p->getRemainingFeatures();
|
cannam@3
|
126 appendFeatures(f, fs);
|
cannam@3
|
127 if (data) destroyTestAudio(data, channels);
|
cannam@3
|
128
|
cannam@3
|
129 Plugin::OutputList outputs = p->getOutputDescriptors();
|
cannam@3
|
130 for (Plugin::FeatureSet::const_iterator i = fs.begin();
|
cannam@3
|
131 i != fs.end(); ++i) {
|
cannam@3
|
132 const Plugin::OutputDescriptor &o = outputs[i->first];
|
cannam@3
|
133 const Plugin::FeatureList &fl = i->second;
|
cannam@3
|
134 for (int j = 0; j < (int)fl.size(); ++j) {
|
cannam@3
|
135 const Plugin::Feature &f = fl[j];
|
cannam@3
|
136 switch (o.sampleType) {
|
cannam@3
|
137 case Plugin::OutputDescriptor::OneSamplePerStep:
|
cannam@3
|
138 if (f.hasTimestamp) {
|
cannam@3
|
139 r.push_back(note("Plugin returns features with timestamps on OneSamplePerStep output"));
|
cannam@3
|
140 }
|
cannam@3
|
141 if (f.hasDuration) {
|
cannam@3
|
142 r.push_back(note("Plugin returns features with durations on OneSamplePerStep output"));
|
cannam@3
|
143 }
|
cannam@3
|
144 break;
|
cannam@3
|
145 case Plugin::OutputDescriptor::FixedSampleRate:
|
cannam@3
|
146 break;
|
cannam@3
|
147 case Plugin::OutputDescriptor::VariableSampleRate:
|
cannam@3
|
148 if (!f.hasTimestamp) {
|
cannam@3
|
149 r.push_back(error("Plugin returns features with no timestamps on VariableSampleRate output"));
|
cannam@3
|
150 }
|
cannam@3
|
151 break;
|
cannam@3
|
152 }
|
cannam@3
|
153 }
|
cannam@3
|
154 }
|
cannam@3
|
155
|
cannam@3
|
156 return r;
|
cannam@3
|
157 }
|