cannam@2
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
cannam@2
|
2
|
cannam@2
|
3 /*
|
cannam@2
|
4 Vamp Plugin Tester
|
cannam@2
|
5 Chris Cannam, cannam@all-day-breakfast.com
|
cannam@2
|
6 Centre for Digital Music, Queen Mary, University of London.
|
cannam@2
|
7 Copyright 2009 QMUL.
|
cannam@2
|
8
|
cannam@2
|
9 This program loads a Vamp plugin and tests its susceptibility to a
|
cannam@2
|
10 number of common pitfalls, including handling of extremes of input
|
cannam@2
|
11 data. If you can think of any additional useful tests that are
|
cannam@2
|
12 easily added, please send them to me.
|
cannam@2
|
13
|
cannam@2
|
14 Permission is hereby granted, free of charge, to any person
|
cannam@2
|
15 obtaining a copy of this software and associated documentation
|
cannam@2
|
16 files (the "Software"), to deal in the Software without
|
cannam@2
|
17 restriction, including without limitation the rights to use, copy,
|
cannam@2
|
18 modify, merge, publish, distribute, sublicense, and/or sell copies
|
cannam@2
|
19 of the Software, and to permit persons to whom the Software is
|
cannam@2
|
20 furnished to do so, subject to the following conditions:
|
cannam@2
|
21
|
cannam@2
|
22 The above copyright notice and this permission notice shall be
|
cannam@2
|
23 included in all copies or substantial portions of the Software.
|
cannam@2
|
24
|
cannam@2
|
25 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
cannam@2
|
26 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
cannam@2
|
27 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
cannam@2
|
28 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
cannam@2
|
29 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
cannam@2
|
30 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
cannam@2
|
31 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
cannam@2
|
32
|
cannam@2
|
33 Except as contained in this notice, the names of the Centre for
|
cannam@2
|
34 Digital Music; Queen Mary, University of London; and Chris Cannam
|
cannam@2
|
35 shall not be used in advertising or otherwise to promote the sale,
|
cannam@2
|
36 use or other dealings in this Software without prior written
|
cannam@2
|
37 authorization.
|
cannam@2
|
38 */
|
cannam@2
|
39
|
cannam@2
|
40 #include "TestMultipleRuns.h"
|
cannam@2
|
41
|
cannam@2
|
42 #include <vamp-hostsdk/Plugin.h>
|
cannam@2
|
43 using namespace Vamp;
|
cannam@2
|
44
|
cannam@2
|
45 #include <memory>
|
cannam@2
|
46 using namespace std;
|
cannam@2
|
47
|
cannam@2
|
48 #include <cmath>
|
cannam@2
|
49
|
cannam@2
|
50 Tester::TestRegistrar<TestDistinctRuns>
|
cannam@2
|
51 TestDistinctRuns::m_registrar("Consecutive runs with separate instances");
|
cannam@2
|
52
|
cannam@2
|
53 Tester::TestRegistrar<TestReset>
|
cannam@2
|
54 TestReset::m_registrar("Consecutive runs with a single instance using reset");
|
cannam@2
|
55
|
cannam@2
|
56 Tester::TestRegistrar<TestInterleavedRuns>
|
cannam@2
|
57 TestInterleavedRuns::m_registrar("Simultaneous interleaved runs in a single thread");
|
cannam@2
|
58
|
cannam@3
|
59 static const size_t _step = 1000;
|
cannam@3
|
60
|
cannam@2
|
61 Test::Results
|
cannam@2
|
62 TestDistinctRuns::test(string key)
|
cannam@2
|
63 {
|
cannam@2
|
64 Plugin::FeatureSet f[2];
|
cannam@2
|
65 int rate = 44100;
|
cannam@2
|
66 Results r;
|
cannam@3
|
67 float **data = 0;
|
cannam@3
|
68 size_t channels = 0;
|
cannam@3
|
69 size_t count = 100;
|
cannam@2
|
70
|
cannam@2
|
71 for (int run = 0; run < 2; ++run) {
|
cannam@2
|
72 auto_ptr<Plugin> p(load(key, rate));
|
cannam@3
|
73 if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
|
cannam@3
|
74 if (!data) data = createTestAudio(channels, _step, count);
|
cannam@3
|
75 for (size_t i = 0; i < count; ++i) {
|
cannam@3
|
76 float *ptr[channels];
|
cannam@3
|
77 size_t idx = i * _step;
|
cannam@3
|
78 for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
|
cannam@2
|
79 RealTime timestamp = RealTime::frame2RealTime(idx, rate);
|
cannam@3
|
80 Plugin::FeatureSet fs = p->process(ptr, timestamp);
|
cannam@2
|
81 appendFeatures(f[run], fs);
|
cannam@2
|
82 }
|
cannam@2
|
83 Plugin::FeatureSet fs = p->getRemainingFeatures();
|
cannam@2
|
84 appendFeatures(f[run], fs);
|
cannam@2
|
85 }
|
cannam@3
|
86 if (data) destroyTestAudio(data, channels);
|
cannam@2
|
87
|
cannam@2
|
88 if (!(f[0] == f[1])) {
|
cannam@2
|
89 r.push_back(warning("Consecutive runs with separate instances produce different results"));
|
cannam@2
|
90 } else {
|
cannam@2
|
91 r.push_back(success());
|
cannam@2
|
92 }
|
cannam@2
|
93
|
cannam@2
|
94 return r;
|
cannam@2
|
95 }
|
cannam@2
|
96
|
cannam@2
|
97 Test::Results
|
cannam@2
|
98 TestReset::test(string key)
|
cannam@2
|
99 {
|
cannam@2
|
100 Plugin::FeatureSet f[2];
|
cannam@2
|
101 int rate = 44100;
|
cannam@2
|
102 Results r;
|
cannam@3
|
103 float **data = 0;
|
cannam@3
|
104 size_t channels = 0;
|
cannam@3
|
105 size_t count = 100;
|
cannam@2
|
106
|
cannam@2
|
107 auto_ptr<Plugin> p(load(key, rate));
|
cannam@3
|
108
|
cannam@2
|
109 for (int run = 0; run < 2; ++run) {
|
cannam@2
|
110 if (run == 1) p->reset();
|
cannam@3
|
111 if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
|
cannam@3
|
112 if (!data) data = createTestAudio(channels, _step, count);
|
cannam@3
|
113 for (size_t i = 0; i < count; ++i) {
|
cannam@3
|
114 float *ptr[channels];
|
cannam@3
|
115 size_t idx = i * _step;
|
cannam@3
|
116 for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
|
cannam@2
|
117 RealTime timestamp = RealTime::frame2RealTime(idx, rate);
|
cannam@3
|
118 Plugin::FeatureSet fs = p->process(ptr, timestamp);
|
cannam@2
|
119 appendFeatures(f[run], fs);
|
cannam@2
|
120 }
|
cannam@2
|
121 Plugin::FeatureSet fs = p->getRemainingFeatures();
|
cannam@2
|
122 appendFeatures(f[run], fs);
|
cannam@2
|
123 }
|
cannam@3
|
124 if (data) destroyTestAudio(data, channels);
|
cannam@2
|
125
|
cannam@2
|
126 if (!(f[0] == f[1])) {
|
cannam@3
|
127 Result res = warning("Consecutive runs with the same instance (using reset) produce different results");
|
cannam@3
|
128 dump(res, f[0], f[1]);
|
cannam@3
|
129 r.push_back(res);
|
cannam@2
|
130 } else {
|
cannam@2
|
131 r.push_back(success());
|
cannam@2
|
132 }
|
cannam@2
|
133
|
cannam@2
|
134 return r;
|
cannam@2
|
135 }
|
cannam@2
|
136
|
cannam@2
|
137 Test::Results
|
cannam@2
|
138 TestInterleavedRuns::test(string key)
|
cannam@2
|
139 {
|
cannam@2
|
140 Plugin::FeatureSet f[2];
|
cannam@2
|
141 int rate = 44100;
|
cannam@2
|
142 Results r;
|
cannam@3
|
143 float **data = 0;
|
cannam@3
|
144 size_t channels = 0;
|
cannam@3
|
145 size_t count = 100;
|
cannam@3
|
146
|
cannam@2
|
147 Plugin *p[2];
|
cannam@2
|
148 for (int run = 0; run < 2; ++run) {
|
cannam@2
|
149 p[run] = load(key, rate);
|
cannam@3
|
150 if (!initAdapted(p[run], channels, _step, _step, r)) {
|
cannam@2
|
151 delete p[run];
|
cannam@2
|
152 if (run > 0) delete p[0];
|
cannam@2
|
153 return r;
|
cannam@2
|
154 }
|
cannam@3
|
155 if (!data) data = createTestAudio(channels, _step, count);
|
cannam@2
|
156 }
|
cannam@3
|
157 for (size_t i = 0; i < count; ++i) {
|
cannam@3
|
158 float *ptr[channels];
|
cannam@3
|
159 size_t idx = i * _step;
|
cannam@3
|
160 for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
|
cannam@2
|
161 RealTime timestamp = RealTime::frame2RealTime(idx, rate);
|
cannam@2
|
162 for (int run = 0; run < 2; ++run) {
|
cannam@3
|
163 Plugin::FeatureSet fs = p[run]->process(ptr, timestamp);
|
cannam@2
|
164 appendFeatures(f[run], fs);
|
cannam@2
|
165 }
|
cannam@2
|
166 }
|
cannam@2
|
167 for (int run = 0; run < 2; ++run) {
|
cannam@2
|
168 Plugin::FeatureSet fs = p[run]->getRemainingFeatures();
|
cannam@2
|
169 appendFeatures(f[run], fs);
|
cannam@2
|
170 delete p[run];
|
cannam@2
|
171 }
|
cannam@2
|
172
|
cannam@3
|
173 if (data) destroyTestAudio(data, channels);
|
cannam@2
|
174
|
cannam@2
|
175 if (!(f[0] == f[1])) {
|
cannam@3
|
176 r.push_back(warning("Simultaneous runs with separate instances produce different results"));
|
cannam@2
|
177 } else {
|
cannam@2
|
178 r.push_back(success());
|
cannam@2
|
179 }
|
cannam@2
|
180
|
cannam@2
|
181 return r;
|
cannam@2
|
182 }
|