Mercurial > hg > piper-cpp
comparison vamp-client/qt/test.cpp @ 270:60ff32818c30
Extend tests to cover two different ways of handling freq-domain data. Currently failing
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Wed, 17 Oct 2018 11:49:31 +0100 |
parents | c67a0a945b6b |
children | 532a146b5229 |
comparison
equal
deleted
inserted
replaced
269:63e460e69347 | 270:60ff32818c30 |
---|---|
35 | 35 |
36 #include "ProcessQtTransport.h" | 36 #include "ProcessQtTransport.h" |
37 #include "CapnpRRClient.h" | 37 #include "CapnpRRClient.h" |
38 #include "PiperAutoPlugin.h" | 38 #include "PiperAutoPlugin.h" |
39 | 39 |
40 #include <vamp-hostsdk/PluginInputDomainAdapter.h> | |
41 | |
40 #include <stdexcept> | 42 #include <stdexcept> |
41 | 43 |
42 using std::cerr; | 44 using std::cerr; |
43 using std::endl; | 45 using std::endl; |
44 using std::exception; | 46 using std::exception; |
45 using std::vector; | 47 using std::vector; |
48 using std::string; | |
46 | 49 |
47 int main(int argc, char **argv) | 50 int main(int argc, char **argv) |
48 { | 51 { |
49 if (argc != 2) { | 52 if (argc != 2) { |
50 cerr << "Usage: " << argv[0] << " <server-executable-path>" << endl; | 53 cerr << "Usage: " << argv[0] << " <server-executable-path>" << endl; |
51 return 2; | 54 return 2; |
52 } | 55 } |
53 | 56 |
57 string server = argv[1]; | |
58 string format = "capnp"; | |
59 string zeroCrossing = "vamp-example-plugins:zerocrossing"; | |
60 string powerSpectrum = "vamp-example-plugins:powerspectrum"; | |
61 piper_vamp::client::LogCallback *logger = nullptr; | |
62 | |
54 try { | 63 try { |
55 piper_vamp::client::ProcessQtTransport transport(argv[1], "capnp", nullptr); | 64 cerr << endl << "*** Test: starting transport" << endl; |
65 piper_vamp::client::ProcessQtTransport transport(server, format, logger); | |
56 if (!transport.isOK()) { | 66 if (!transport.isOK()) { |
57 cerr << "ERROR: Transport failed to start" << endl; | 67 cerr << "ERROR: Transport failed to start" << endl; |
58 return 1; | 68 return 1; |
59 } | 69 } |
60 | 70 cerr << "OK" << endl; |
61 piper_vamp::client::CapnpRRClient client(&transport, nullptr); | 71 |
62 | 72 cerr << endl << "*** Test: constructing client" << endl; |
73 piper_vamp::client::CapnpRRClient client(&transport, logger); | |
74 cerr << "OK" << endl; | |
75 | |
76 cerr << endl << "*** Test: listing plugins" << endl; | |
63 piper_vamp::ListResponse lr = client.list({}); | 77 piper_vamp::ListResponse lr = client.list({}); |
64 cerr << "Plugins available:" << endl; | 78 cerr << "OK; plugins are:" << endl; |
65 int i = 1; | 79 int i = 1; |
66 for (const auto &p: lr.available) { | 80 for (const auto &p: lr.available) { |
67 cerr << i++ << ". [" << p.pluginKey << "] " << p.basic.name << endl; | 81 cerr << i++ << ". [" << p.pluginKey << "] " << p.basic.name << endl; |
68 } | 82 } |
69 | 83 |
70 piper_vamp::LoadRequest req; | 84 enum { |
71 req.pluginKey = "vamp-example-plugins:zerocrossing"; | 85 explicitServer = 1, |
72 req.inputSampleRate = 16; | 86 autoServer = 2 |
73 piper_vamp::LoadResponse resp = client.load(req); | 87 }; |
74 Vamp::Plugin *plugin = resp.plugin; | 88 enum { |
75 | 89 timeDomain = 1, |
76 if (!plugin->initialise(1, 4, 4)) { | 90 frequencyDomainServerSide = 2, |
77 cerr << "initialisation failed" << endl; | 91 frequencyDomainClientSide = 3 |
78 } else { | 92 }; |
79 vector<float> buf = { 1.0, -1.0, 1.0, -1.0 }; | 93 |
80 float *bd = buf.data(); | 94 for (int domain = timeDomain; |
81 Vamp::Plugin::FeatureSet features = plugin->process | 95 domain <= frequencyDomainClientSide; |
82 (&bd, Vamp::RealTime::zeroTime); | 96 ++domain) { |
83 cerr << "results for output 0:" << endl; | 97 |
84 auto fl(features[0]); | 98 for (int serverSort = explicitServer; |
85 for (const auto &f: fl) { | 99 serverSort <= autoServer; |
86 cerr << f.values[0] << endl; | 100 ++serverSort) { |
101 | |
102 string id = zeroCrossing; | |
103 if (domain == frequencyDomainServerSide || | |
104 domain == frequencyDomainClientSide) { | |
105 id = powerSpectrum; | |
106 } | |
107 | |
108 Vamp::Plugin *plugin = nullptr; | |
109 | |
110 int adapterFlags = 0; | |
111 if (domain == frequencyDomainServerSide) { | |
112 adapterFlags = (int) | |
113 Vamp::HostExt::PluginLoader::ADAPT_INPUT_DOMAIN; | |
114 } | |
115 | |
116 if (serverSort == explicitServer) { | |
117 | |
118 cerr << endl << "*** Test: loading \"" << id | |
119 << "\" with explicit server" << endl; | |
120 | |
121 piper_vamp::LoadRequest req; | |
122 req.pluginKey = id; | |
123 req.inputSampleRate = 16; | |
124 req.adapterFlags = adapterFlags; | |
125 piper_vamp::LoadResponse resp = client.load(req); | |
126 plugin = resp.plugin; | |
127 if (!plugin) { | |
128 cerr << "ERROR: plugin is null" << endl; | |
129 return 1; | |
130 } | |
131 cerr << "OK" << endl; | |
132 | |
133 } else { | |
134 | |
135 cerr << endl << "*** Test: loading \"" << id | |
136 << "\" with auto-plugin" << endl; | |
137 | |
138 piper_vamp::client::PiperAutoPlugin *ap = | |
139 new piper_vamp::client::PiperAutoPlugin | |
140 (server, id, 16, adapterFlags, logger); | |
141 if (!ap->isOK()) { | |
142 cerr << "ERROR: PiperAutoPlugin creation failed" << endl; | |
143 return 1; | |
144 } | |
145 cerr << "OK" << endl; | |
146 | |
147 plugin = ap; | |
148 } | |
149 | |
150 if (domain == frequencyDomainClientSide) { | |
151 cerr << "*** Test: creating input-domain adapter" << endl; | |
152 plugin = new Vamp::HostExt::PluginInputDomainAdapter(plugin); | |
153 cerr << "OK" << endl; | |
154 } | |
155 | |
156 cerr << endl << "*** Test: initialising plugin" << endl; | |
157 if (!plugin->initialise(1, 4, 4)) { | |
158 cerr << "ERROR: initialisation failed" << endl; | |
159 return 1; | |
160 } | |
161 cerr << "OK" << endl; | |
162 | |
163 for (int round = 1; round <= 2; ++round) { | |
164 cerr << endl << "*** Test: processing" | |
165 << " (domain " << domain | |
166 << ", sort " << serverSort | |
167 << ", round " << round << ")" << endl; | |
168 | |
169 vector<float> buf = { 1.0, -1.0, 1.0, -1.0 }; | |
170 float *bd = buf.data(); | |
171 Vamp::Plugin::FeatureSet features = plugin->process | |
172 (&bd, Vamp::RealTime::zeroTime); | |
173 cerr << "OK, process succeeded" << endl; | |
174 if (features[0].size() != 1) { | |
175 cerr << "ERROR: wrong number of features on output 0" | |
176 << " (expected 1, obtained " << features[0].size() << ")" | |
177 << endl; | |
178 return 1; | |
179 } | |
180 vector<float> expected; | |
181 if (domain == timeDomain) { | |
182 expected.push_back(4); | |
183 } else { | |
184 // these would be 0, 0, 16 if we were | |
185 // calculating the power spectrum without | |
186 // windowing - but the input domain adapter | |
187 // does window, and an asymmetrical Hann | |
188 // window gives these results | |
189 expected.push_back(0); | |
190 expected.push_back(1); | |
191 expected.push_back(4); | |
192 } | |
193 | |
194 if (features[0][0].values.size() != expected.size()) { | |
195 cerr << "ERROR: wrong size for feature on output 0" | |
196 << " (expected " << expected.size() | |
197 << ", obtained " | |
198 << features[0][0].values.size() << ")" << endl; | |
199 return 1; | |
200 } | |
201 for (size_t i = 0; i < expected.size(); ++i) { | |
202 if (features[0][0].values[i] != expected[i]) { | |
203 cerr << "ERROR: wrong value for index " << i | |
204 << " of feature on output 0" | |
205 << " (expected " << expected[i] | |
206 << ", obtained " | |
207 << features[0][0].values[i] << ")" << endl; | |
208 cerr << "(All obtained values are:"; | |
209 for (size_t j = 0; j < expected.size(); ++j) { | |
210 cerr << " " << features[0][0].values[j]; | |
211 } | |
212 cerr << ")" << endl; | |
213 return 1; | |
214 } | |
215 } | |
216 cerr << "OK, results are correct" << endl; | |
217 | |
218 (void)plugin->getRemainingFeatures(); | |
219 | |
220 if (round == 1) { | |
221 cerr << endl << "*** Test: resetting plugin for round 2" << endl; | |
222 plugin->reset(); | |
223 cerr << "OK" << endl; | |
224 } | |
225 } | |
226 | |
227 cerr << endl << "*** Test: deleting plugin" << endl; | |
228 delete plugin; | |
229 cerr << "OK" << endl; | |
87 } | 230 } |
88 } | 231 } |
89 | 232 |
90 (void)plugin->getRemainingFeatures(); | |
91 | |
92 cerr << "calling reset..." << endl; | |
93 plugin->reset(); | |
94 cerr << "...round 2!" << endl; | |
95 | |
96 vector<float> buf = { 1.0, -1.0, 1.0, -1.0 }; | |
97 float *bd = buf.data(); | |
98 Vamp::Plugin::FeatureSet features = plugin->process | |
99 (&bd, Vamp::RealTime::zeroTime); | |
100 cerr << "results for output 0:" << endl; | |
101 auto fl(features[0]); | |
102 for (const auto &f: fl) { | |
103 cerr << f.values[0] << endl; | |
104 } | |
105 | |
106 (void)plugin->getRemainingFeatures(); | |
107 | |
108 delete plugin; | |
109 | |
110 // Let's try a crazy PiperAutoPlugin | |
111 | |
112 piper_vamp::client::PiperAutoPlugin ap | |
113 (argv[1], "vamp-example-plugins:zerocrossing", 16, 0, nullptr); | |
114 | |
115 if (!ap.isOK()) { | |
116 cerr << "PiperAutoPlugin creation failed" << endl; | |
117 } else { | |
118 if (!ap.initialise(1, 4, 4)) { | |
119 cerr << "initialisation failed" << endl; | |
120 } else { | |
121 vector<float> buf = { 1.0, -1.0, 1.0, -1.0 }; | |
122 float *bd = buf.data(); | |
123 Vamp::Plugin::FeatureSet features = ap.process | |
124 (&bd, Vamp::RealTime::zeroTime); | |
125 cerr << "results for output 0:" << endl; | |
126 auto fl(features[0]); | |
127 for (const auto &f: fl) { | |
128 cerr << f.values[0] << endl; | |
129 } | |
130 } | |
131 } | |
132 } catch (const exception &e) { | 233 } catch (const exception &e) { |
133 cerr << "ERROR: Exception caught: " << e.what() << endl; | 234 cerr << "ERROR: Exception caught: " << e.what() << endl; |
134 return 1; | 235 return 1; |
135 } | 236 } |
136 | 237 |
238 cerr << endl << "*** All tests succeeded" << endl; | |
239 | |
137 return 0; | 240 return 0; |
138 } | 241 } |
139 | 242 |