cannam@1
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
cannam@1
|
2
|
cannam@1
|
3 /*
|
cannam@1
|
4 Vamp
|
cannam@1
|
5
|
cannam@1
|
6 An API for audio analysis and feature extraction plugins.
|
cannam@1
|
7
|
cannam@1
|
8 Centre for Digital Music, Queen Mary, University of London.
|
cannam@1
|
9 Copyright 2006 Chris Cannam.
|
cannam@16
|
10 FFT code from Don Cross's public domain FFT implementation.
|
cannam@1
|
11
|
cannam@1
|
12 Permission is hereby granted, free of charge, to any person
|
cannam@1
|
13 obtaining a copy of this software and associated documentation
|
cannam@1
|
14 files (the "Software"), to deal in the Software without
|
cannam@1
|
15 restriction, including without limitation the rights to use, copy,
|
cannam@1
|
16 modify, merge, publish, distribute, sublicense, and/or sell copies
|
cannam@1
|
17 of the Software, and to permit persons to whom the Software is
|
cannam@1
|
18 furnished to do so, subject to the following conditions:
|
cannam@1
|
19
|
cannam@1
|
20 The above copyright notice and this permission notice shall be
|
cannam@1
|
21 included in all copies or substantial portions of the Software.
|
cannam@1
|
22
|
cannam@1
|
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
cannam@1
|
24 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
cannam@1
|
25 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
cannam@6
|
26 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
cannam@1
|
27 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
cannam@1
|
28 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
cannam@1
|
29 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
cannam@1
|
30
|
cannam@1
|
31 Except as contained in this notice, the names of the Centre for
|
cannam@1
|
32 Digital Music; Queen Mary, University of London; and Chris Cannam
|
cannam@1
|
33 shall not be used in advertising or otherwise to promote the sale,
|
cannam@1
|
34 use or other dealings in this Software without prior written
|
cannam@1
|
35 authorization.
|
cannam@1
|
36 */
|
cannam@1
|
37
|
cannam@230
|
38 #include <vamp-hostsdk/PluginHostAdapter.h>
|
cannam@230
|
39 #include <vamp-hostsdk/hostext/PluginInputDomainAdapter.h>
|
cannam@230
|
40 #include <vamp-hostsdk/hostext/PluginLoader.h>
|
cannam@1
|
41
|
cannam@16
|
42 #include <iostream>
|
cannam@88
|
43 #include <fstream>
|
cannam@99
|
44 #include <set>
|
cannam@16
|
45 #include <sndfile.h>
|
cannam@1
|
46
|
cannam@130
|
47 #include <cstring>
|
cannam@130
|
48 #include <cstdlib>
|
cannam@130
|
49
|
cannam@1
|
50 #include "system.h"
|
cannam@1
|
51
|
cannam@19
|
52 #include <cmath>
|
cannam@19
|
53
|
cannam@99
|
54 using namespace std;
|
cannam@16
|
55
|
cannam@99
|
56 using Vamp::Plugin;
|
cannam@99
|
57 using Vamp::PluginHostAdapter;
|
cannam@99
|
58 using Vamp::RealTime;
|
cannam@64
|
59 using Vamp::HostExt::PluginLoader;
|
cannam@190
|
60 using Vamp::HostExt::PluginWrapper;
|
cannam@190
|
61 using Vamp::HostExt::PluginInputDomainAdapter;
|
cannam@64
|
62
|
cannam@190
|
63 #define HOST_VERSION "1.3"
|
cannam@40
|
64
|
cannam@95
|
65 enum Verbosity {
|
cannam@95
|
66 PluginIds,
|
cannam@95
|
67 PluginOutputIds,
|
cannam@95
|
68 PluginInformation
|
cannam@95
|
69 };
|
cannam@95
|
70
|
cannam@109
|
71 void printFeatures(int, int, int, Plugin::FeatureSet, ofstream *, bool frames);
|
cannam@16
|
72 void transformInput(float *, size_t);
|
cannam@16
|
73 void fft(unsigned int, bool, double *, double *, double *, double *);
|
cannam@64
|
74 void printPluginPath(bool verbose);
|
cannam@99
|
75 void printPluginCategoryList();
|
cannam@95
|
76 void enumeratePlugins(Verbosity);
|
cannam@64
|
77 void listPluginsInLibrary(string soname);
|
cannam@64
|
78 int runPlugin(string myname, string soname, string id, string output,
|
cannam@109
|
79 int outputNo, string inputFile, string outfilename, bool frames);
|
cannam@40
|
80
|
cannam@64
|
81 void usage(const char *name)
|
cannam@64
|
82 {
|
cannam@64
|
83 cerr << "\n"
|
cannam@64
|
84 << name << ": A simple Vamp plugin host.\n\n"
|
cannam@64
|
85 "Centre for Digital Music, Queen Mary, University of London.\n"
|
cannam@64
|
86 "Copyright 2006-2007 Chris Cannam and QMUL.\n"
|
cannam@64
|
87 "Freely redistributable; published under a BSD-style license.\n\n"
|
cannam@64
|
88 "Usage:\n\n"
|
cannam@109
|
89 " " << name << " [-s] pluginlibrary[." << PLUGIN_SUFFIX << "]:plugin[:output] file.wav [-o out.txt]\n"
|
cannam@109
|
90 " " << name << " [-s] pluginlibrary[." << PLUGIN_SUFFIX << "]:plugin file.wav [outputno] [-o out.txt]\n\n"
|
cannam@64
|
91 " -- Load plugin id \"plugin\" from \"pluginlibrary\" and run it on the\n"
|
cannam@73
|
92 " audio data in \"file.wav\", retrieving the named \"output\", or output\n"
|
cannam@73
|
93 " number \"outputno\" (the first output by default) and dumping it to\n"
|
cannam@95
|
94 " standard output, or to \"out.txt\" if the -o option is given.\n\n"
|
cannam@73
|
95 " \"pluginlibrary\" should be a library name, not a file path; the\n"
|
cannam@73
|
96 " standard Vamp library search path will be used to locate it. If\n"
|
cannam@73
|
97 " a file path is supplied, the directory part(s) will be ignored.\n\n"
|
cannam@109
|
98 " If the -s option is given, results will be labelled with the audio\n"
|
cannam@109
|
99 " sample frame at which they occur. Otherwise, they will be labelled\n"
|
cannam@109
|
100 " with time in seconds.\n\n"
|
cannam@64
|
101 " " << name << " -l\n\n"
|
cannam@95
|
102 " -- List the plugin libraries and Vamp plugins in the library search path\n"
|
cannam@95
|
103 " in a verbose human-readable format.\n\n"
|
cannam@95
|
104 " " << name << " --list-ids\n\n"
|
cannam@95
|
105 " -- List the plugins in the search path in a terse machine-readable format,\n"
|
cannam@95
|
106 " in the form vamp:soname:identifier.\n\n"
|
cannam@95
|
107 " " << name << " --list-outputs\n\n"
|
cannam@95
|
108 " -- List the outputs for plugins in the search path in a machine-readable\n"
|
cannam@95
|
109 " format, in the form vamp:soname:identifier:output.\n\n"
|
cannam@99
|
110 " " << name << " --list-by-category\n\n"
|
cannam@99
|
111 " -- List the plugins as a plugin index by category, in a machine-readable\n"
|
cannam@99
|
112 " format. The format may change in future releases.\n\n"
|
cannam@64
|
113 " " << name << " -p\n\n"
|
cannam@73
|
114 " -- Print out the Vamp library search path.\n\n"
|
cannam@64
|
115 " " << name << " -v\n\n"
|
cannam@95
|
116 " -- Display version information only.\n"
|
cannam@64
|
117 << endl;
|
cannam@64
|
118 exit(2);
|
cannam@64
|
119 }
|
cannam@1
|
120
|
cannam@1
|
121 int main(int argc, char **argv)
|
cannam@1
|
122 {
|
cannam@64
|
123 char *scooter = argv[0];
|
cannam@64
|
124 char *name = 0;
|
cannam@64
|
125 while (scooter && *scooter) {
|
cannam@64
|
126 if (*scooter == '/' || *scooter == '\\') name = ++scooter;
|
cannam@64
|
127 else ++scooter;
|
cannam@1
|
128 }
|
cannam@64
|
129 if (!name || !*name) name = argv[0];
|
cannam@43
|
130
|
cannam@88
|
131 if (argc < 2) usage(name);
|
cannam@64
|
132
|
cannam@88
|
133 if (argc == 2) {
|
cannam@88
|
134
|
cannam@88
|
135 if (!strcmp(argv[1], "-v")) {
|
cannam@88
|
136
|
cannam@88
|
137 cout << "Simple Vamp plugin host version: " << HOST_VERSION << endl
|
cannam@88
|
138 << "Vamp API version: " << VAMP_API_VERSION << endl
|
cannam@88
|
139 << "Vamp SDK version: " << VAMP_SDK_VERSION << endl;
|
cannam@88
|
140 return 0;
|
cannam@88
|
141
|
cannam@88
|
142 } else if (!strcmp(argv[1], "-l")) {
|
cannam@88
|
143
|
cannam@88
|
144 printPluginPath(true);
|
cannam@95
|
145 enumeratePlugins(PluginInformation);
|
cannam@88
|
146 return 0;
|
cannam@88
|
147
|
cannam@88
|
148 } else if (!strcmp(argv[1], "-p")) {
|
cannam@88
|
149
|
cannam@88
|
150 printPluginPath(false);
|
cannam@88
|
151 return 0;
|
cannam@88
|
152
|
cannam@95
|
153 } else if (!strcmp(argv[1], "--list-ids")) {
|
cannam@95
|
154
|
cannam@95
|
155 enumeratePlugins(PluginIds);
|
cannam@95
|
156 return 0;
|
cannam@95
|
157
|
cannam@95
|
158 } else if (!strcmp(argv[1], "--list-outputs")) {
|
cannam@95
|
159
|
cannam@95
|
160 enumeratePlugins(PluginOutputIds);
|
cannam@95
|
161 return 0;
|
cannam@95
|
162
|
cannam@99
|
163 } else if (!strcmp(argv[1], "--list-by-category")) {
|
cannam@99
|
164
|
cannam@99
|
165 printPluginCategoryList();
|
cannam@99
|
166 return 0;
|
cannam@99
|
167
|
cannam@88
|
168 } else usage(name);
|
cannam@64
|
169 }
|
cannam@64
|
170
|
cannam@88
|
171 if (argc < 3) usage(name);
|
cannam@88
|
172
|
cannam@109
|
173 bool useFrames = false;
|
cannam@109
|
174
|
cannam@109
|
175 int base = 1;
|
cannam@109
|
176 if (!strcmp(argv[1], "-s")) {
|
cannam@109
|
177 useFrames = true;
|
cannam@109
|
178 base = 2;
|
cannam@109
|
179 }
|
cannam@109
|
180
|
cannam@109
|
181 string soname = argv[base];
|
cannam@109
|
182 string wavname = argv[base+1];
|
cannam@88
|
183 string plugid = "";
|
cannam@88
|
184 string output = "";
|
cannam@88
|
185 int outputNo = -1;
|
cannam@88
|
186 string outfilename;
|
cannam@88
|
187
|
cannam@109
|
188 if (argc >= base+3) {
|
cannam@88
|
189
|
cannam@109
|
190 int idx = base+2;
|
cannam@88
|
191
|
cannam@88
|
192 if (isdigit(*argv[idx])) {
|
cannam@88
|
193 outputNo = atoi(argv[idx++]);
|
cannam@88
|
194 }
|
cannam@88
|
195
|
cannam@88
|
196 if (argc == idx + 2) {
|
cannam@88
|
197 if (!strcmp(argv[idx], "-o")) {
|
cannam@88
|
198 outfilename = argv[idx+1];
|
cannam@88
|
199 } else usage(name);
|
cannam@88
|
200 } else if (argc != idx) {
|
cannam@88
|
201 (usage(name));
|
cannam@88
|
202 }
|
cannam@40
|
203 }
|
cannam@40
|
204
|
cannam@64
|
205 cerr << endl << name << ": Running..." << endl;
|
cannam@1
|
206
|
cannam@88
|
207 cerr << "Reading file: \"" << wavname << "\", writing to ";
|
cannam@88
|
208 if (outfilename == "") {
|
cannam@88
|
209 cerr << "standard output" << endl;
|
cannam@88
|
210 } else {
|
cannam@88
|
211 cerr << "\"" << outfilename << "\"" << endl;
|
cannam@88
|
212 }
|
cannam@16
|
213
|
cannam@64
|
214 string::size_type sep = soname.find(':');
|
cannam@64
|
215
|
cannam@64
|
216 if (sep != string::npos) {
|
cannam@49
|
217 plugid = soname.substr(sep + 1);
|
cannam@20
|
218 soname = soname.substr(0, sep);
|
cannam@1
|
219
|
cannam@64
|
220 sep = plugid.find(':');
|
cannam@64
|
221 if (sep != string::npos) {
|
cannam@64
|
222 output = plugid.substr(sep + 1);
|
cannam@64
|
223 plugid = plugid.substr(0, sep);
|
cannam@16
|
224 }
|
cannam@16
|
225 }
|
cannam@16
|
226
|
cannam@64
|
227 if (plugid == "") {
|
cannam@64
|
228 usage(name);
|
cannam@16
|
229 }
|
cannam@64
|
230
|
cannam@64
|
231 if (output != "" && outputNo != -1) {
|
cannam@64
|
232 usage(name);
|
cannam@64
|
233 }
|
cannam@64
|
234
|
cannam@84
|
235 if (output == "" && outputNo == -1) {
|
cannam@84
|
236 outputNo = 0;
|
cannam@84
|
237 }
|
cannam@84
|
238
|
cannam@88
|
239 return runPlugin(name, soname, plugid, output, outputNo,
|
cannam@109
|
240 wavname, outfilename, useFrames);
|
cannam@64
|
241 }
|
cannam@64
|
242
|
cannam@64
|
243
|
cannam@64
|
244 int runPlugin(string myname, string soname, string id,
|
cannam@88
|
245 string output, int outputNo, string wavname,
|
cannam@109
|
246 string outfilename, bool useFrames)
|
cannam@64
|
247 {
|
cannam@64
|
248 PluginLoader *loader = PluginLoader::getInstance();
|
cannam@64
|
249
|
cannam@64
|
250 PluginLoader::PluginKey key = loader->composePluginKey(soname, id);
|
cannam@16
|
251
|
cannam@16
|
252 SNDFILE *sndfile;
|
cannam@16
|
253 SF_INFO sfinfo;
|
cannam@16
|
254 memset(&sfinfo, 0, sizeof(SF_INFO));
|
cannam@16
|
255
|
cannam@16
|
256 sndfile = sf_open(wavname.c_str(), SFM_READ, &sfinfo);
|
cannam@16
|
257 if (!sndfile) {
|
cannam@64
|
258 cerr << myname << ": ERROR: Failed to open input file \""
|
cannam@64
|
259 << wavname << "\": " << sf_strerror(sndfile) << endl;
|
cannam@16
|
260 return 1;
|
cannam@16
|
261 }
|
cannam@16
|
262
|
cannam@88
|
263 ofstream *out = 0;
|
cannam@88
|
264 if (outfilename != "") {
|
cannam@88
|
265 out = new ofstream(outfilename.c_str(), ios::out);
|
cannam@88
|
266 if (!*out) {
|
cannam@88
|
267 cerr << myname << ": ERROR: Failed to open output file \""
|
cannam@88
|
268 << outfilename << "\" for writing" << endl;
|
cannam@88
|
269 delete out;
|
cannam@88
|
270 return 1;
|
cannam@88
|
271 }
|
cannam@88
|
272 }
|
cannam@88
|
273
|
cannam@99
|
274 Plugin *plugin = loader->loadPlugin
|
cannam@92
|
275 (key, sfinfo.samplerate, PluginLoader::ADAPT_ALL_SAFE);
|
cannam@64
|
276 if (!plugin) {
|
cannam@64
|
277 cerr << myname << ": ERROR: Failed to load plugin \"" << id
|
cannam@64
|
278 << "\" from library \"" << soname << "\"" << endl;
|
cannam@64
|
279 sf_close(sndfile);
|
cannam@88
|
280 if (out) {
|
cannam@88
|
281 out->close();
|
cannam@88
|
282 delete out;
|
cannam@88
|
283 }
|
cannam@64
|
284 return 1;
|
cannam@64
|
285 }
|
cannam@16
|
286
|
cannam@64
|
287 cerr << "Running plugin: \"" << plugin->getIdentifier() << "\"..." << endl;
|
cannam@16
|
288
|
cannam@16
|
289 int blockSize = plugin->getPreferredBlockSize();
|
cannam@16
|
290 int stepSize = plugin->getPreferredStepSize();
|
cannam@16
|
291
|
cannam@91
|
292 if (blockSize == 0) {
|
cannam@91
|
293 blockSize = 1024;
|
cannam@91
|
294 }
|
cannam@83
|
295 if (stepSize == 0) {
|
cannam@99
|
296 if (plugin->getInputDomain() == Plugin::FrequencyDomain) {
|
cannam@83
|
297 stepSize = blockSize/2;
|
cannam@83
|
298 } else {
|
cannam@83
|
299 stepSize = blockSize;
|
cannam@83
|
300 }
|
cannam@91
|
301 } else if (stepSize > blockSize) {
|
cannam@91
|
302 cerr << "WARNING: stepSize " << stepSize << " > blockSize " << blockSize << ", resetting blockSize to ";
|
cannam@99
|
303 if (plugin->getInputDomain() == Plugin::FrequencyDomain) {
|
cannam@91
|
304 blockSize = stepSize * 2;
|
cannam@91
|
305 } else {
|
cannam@91
|
306 blockSize = stepSize;
|
cannam@91
|
307 }
|
cannam@91
|
308 cerr << blockSize << endl;
|
cannam@83
|
309 }
|
cannam@83
|
310
|
cannam@16
|
311 int channels = sfinfo.channels;
|
cannam@16
|
312
|
cannam@16
|
313 float *filebuf = new float[blockSize * channels];
|
cannam@16
|
314 float **plugbuf = new float*[channels];
|
cannam@47
|
315 for (int c = 0; c < channels; ++c) plugbuf[c] = new float[blockSize + 2];
|
cannam@16
|
316
|
cannam@16
|
317 cerr << "Using block size = " << blockSize << ", step size = "
|
cannam@16
|
318 << stepSize << endl;
|
cannam@16
|
319
|
cannam@16
|
320 int minch = plugin->getMinChannelCount();
|
cannam@16
|
321 int maxch = plugin->getMaxChannelCount();
|
cannam@16
|
322 cerr << "Plugin accepts " << minch << " -> " << maxch << " channel(s)" << endl;
|
cannam@64
|
323 cerr << "Sound file has " << channels << " (will mix/augment if necessary)" << endl;
|
cannam@16
|
324
|
cannam@99
|
325 Plugin::OutputList outputs = plugin->getOutputDescriptors();
|
cannam@99
|
326 Plugin::OutputDescriptor od;
|
cannam@16
|
327
|
cannam@29
|
328 int returnValue = 1;
|
cannam@88
|
329 int progress = 0;
|
cannam@29
|
330
|
cannam@190
|
331 RealTime rt;
|
cannam@190
|
332 PluginWrapper *wrapper = 0;
|
cannam@190
|
333 RealTime adjustment = RealTime::zeroTime;
|
cannam@190
|
334
|
cannam@16
|
335 if (outputs.empty()) {
|
cannam@64
|
336 cerr << "ERROR: Plugin has no outputs!" << endl;
|
cannam@16
|
337 goto done;
|
cannam@16
|
338 }
|
cannam@16
|
339
|
cannam@64
|
340 if (outputNo < 0) {
|
cannam@16
|
341
|
cannam@64
|
342 for (size_t oi = 0; oi < outputs.size(); ++oi) {
|
cannam@64
|
343 if (outputs[oi].identifier == output) {
|
cannam@64
|
344 outputNo = oi;
|
cannam@64
|
345 break;
|
cannam@64
|
346 }
|
cannam@64
|
347 }
|
cannam@64
|
348
|
cannam@64
|
349 if (outputNo < 0) {
|
cannam@64
|
350 cerr << "ERROR: Non-existent output \"" << output << "\" requested" << endl;
|
cannam@64
|
351 goto done;
|
cannam@64
|
352 }
|
cannam@64
|
353
|
cannam@64
|
354 } else {
|
cannam@64
|
355
|
cannam@64
|
356 if (int(outputs.size()) <= outputNo) {
|
cannam@64
|
357 cerr << "ERROR: Output " << outputNo << " requested, but plugin has only " << outputs.size() << " output(s)" << endl;
|
cannam@64
|
358 goto done;
|
cannam@64
|
359 }
|
cannam@64
|
360 }
|
cannam@64
|
361
|
cannam@64
|
362 od = outputs[outputNo];
|
cannam@64
|
363 cerr << "Output is: \"" << od.identifier << "\"" << endl;
|
cannam@16
|
364
|
cannam@29
|
365 if (!plugin->initialise(channels, stepSize, blockSize)) {
|
cannam@29
|
366 cerr << "ERROR: Plugin initialise (channels = " << channels
|
cannam@29
|
367 << ", stepSize = " << stepSize << ", blockSize = "
|
cannam@29
|
368 << blockSize << ") failed." << endl;
|
cannam@29
|
369 goto done;
|
cannam@29
|
370 }
|
cannam@16
|
371
|
cannam@190
|
372 wrapper = dynamic_cast<PluginWrapper *>(plugin);
|
cannam@190
|
373 if (wrapper) {
|
cannam@190
|
374 PluginInputDomainAdapter *ida =
|
cannam@190
|
375 wrapper->getWrapper<PluginInputDomainAdapter>();
|
cannam@190
|
376 if (ida) adjustment = ida->getTimestampAdjustment();
|
cannam@190
|
377 }
|
cannam@190
|
378
|
cannam@16
|
379 for (size_t i = 0; i < sfinfo.frames; i += stepSize) {
|
cannam@16
|
380
|
cannam@16
|
381 int count;
|
cannam@16
|
382
|
cannam@16
|
383 if (sf_seek(sndfile, i, SEEK_SET) < 0) {
|
cannam@16
|
384 cerr << "ERROR: sf_seek failed: " << sf_strerror(sndfile) << endl;
|
cannam@16
|
385 break;
|
cannam@16
|
386 }
|
cannam@16
|
387
|
cannam@16
|
388 if ((count = sf_readf_float(sndfile, filebuf, blockSize)) < 0) {
|
cannam@16
|
389 cerr << "ERROR: sf_readf_float failed: " << sf_strerror(sndfile) << endl;
|
cannam@16
|
390 break;
|
cannam@16
|
391 }
|
cannam@16
|
392
|
cannam@16
|
393 for (int c = 0; c < channels; ++c) {
|
cannam@64
|
394 int j = 0;
|
cannam@64
|
395 while (j < count) {
|
cannam@64
|
396 plugbuf[c][j] = filebuf[j * sfinfo.channels + c];
|
cannam@64
|
397 ++j;
|
cannam@64
|
398 }
|
cannam@64
|
399 while (j < blockSize) {
|
cannam@16
|
400 plugbuf[c][j] = 0.0f;
|
cannam@64
|
401 ++j;
|
cannam@16
|
402 }
|
cannam@16
|
403 }
|
cannam@16
|
404
|
cannam@190
|
405 rt = RealTime::frame2RealTime(i, sfinfo.samplerate);
|
cannam@190
|
406
|
cannam@16
|
407 printFeatures
|
cannam@190
|
408 (RealTime::realTime2Frame(rt + adjustment, sfinfo.samplerate),
|
cannam@190
|
409 sfinfo.samplerate, outputNo, plugin->process(plugbuf, rt),
|
cannam@109
|
410 out, useFrames);
|
cannam@88
|
411
|
cannam@88
|
412 int pp = progress;
|
cannam@88
|
413 progress = lrintf((float(i) / sfinfo.frames) * 100.f);
|
cannam@88
|
414 if (progress != pp && out) {
|
cannam@88
|
415 cerr << "\r" << progress << "%";
|
cannam@88
|
416 }
|
cannam@16
|
417 }
|
cannam@88
|
418 if (out) cerr << "\rDone" << endl;
|
cannam@16
|
419
|
cannam@190
|
420 rt = RealTime::frame2RealTime(sfinfo.frames, sfinfo.samplerate);
|
cannam@190
|
421
|
cannam@190
|
422 printFeatures(RealTime::realTime2Frame(rt + adjustment, sfinfo.samplerate),
|
cannam@190
|
423 sfinfo.samplerate, outputNo,
|
cannam@109
|
424 plugin->getRemainingFeatures(), out, useFrames);
|
cannam@16
|
425
|
cannam@29
|
426 returnValue = 0;
|
cannam@29
|
427
|
cannam@16
|
428 done:
|
cannam@16
|
429 delete plugin;
|
cannam@88
|
430 if (out) {
|
cannam@88
|
431 out->close();
|
cannam@88
|
432 delete out;
|
cannam@88
|
433 }
|
cannam@16
|
434 sf_close(sndfile);
|
cannam@29
|
435 return returnValue;
|
cannam@1
|
436 }
|
cannam@1
|
437
|
cannam@16
|
438 void
|
cannam@99
|
439 printFeatures(int frame, int sr, int output,
|
cannam@109
|
440 Plugin::FeatureSet features, ofstream *out, bool useFrames)
|
cannam@99
|
441 {
|
cannam@99
|
442 for (unsigned int i = 0; i < features[output].size(); ++i) {
|
cannam@99
|
443
|
cannam@109
|
444 if (useFrames) {
|
cannam@99
|
445
|
cannam@109
|
446 int displayFrame = frame;
|
cannam@109
|
447
|
cannam@109
|
448 if (features[output][i].hasTimestamp) {
|
cannam@109
|
449 displayFrame = RealTime::realTime2Frame
|
cannam@109
|
450 (features[output][i].timestamp, sr);
|
cannam@109
|
451 }
|
cannam@109
|
452
|
cannam@167
|
453 (out ? *out : cout) << displayFrame;
|
cannam@167
|
454
|
cannam@167
|
455 if (features[output][i].hasDuration) {
|
cannam@167
|
456 displayFrame = RealTime::realTime2Frame
|
cannam@167
|
457 (features[output][i].duration, sr);
|
cannam@167
|
458 (out ? *out : cout) << "," << displayFrame;
|
cannam@167
|
459 }
|
cannam@167
|
460
|
cannam@167
|
461 (out ? *out : cout) << ":";
|
cannam@109
|
462
|
cannam@109
|
463 } else {
|
cannam@109
|
464
|
cannam@109
|
465 RealTime rt = RealTime::frame2RealTime(frame, sr);
|
cannam@109
|
466
|
cannam@109
|
467 if (features[output][i].hasTimestamp) {
|
cannam@109
|
468 rt = features[output][i].timestamp;
|
cannam@109
|
469 }
|
cannam@109
|
470
|
cannam@167
|
471 (out ? *out : cout) << rt.toString();
|
cannam@167
|
472
|
cannam@167
|
473 if (features[output][i].hasDuration) {
|
cannam@167
|
474 rt = features[output][i].duration;
|
cannam@167
|
475 (out ? *out : cout) << "," << rt.toString();
|
cannam@167
|
476 }
|
cannam@167
|
477
|
cannam@167
|
478 (out ? *out : cout) << ":";
|
cannam@99
|
479 }
|
cannam@99
|
480
|
cannam@99
|
481 for (unsigned int j = 0; j < features[output][i].values.size(); ++j) {
|
cannam@99
|
482 (out ? *out : cout) << " " << features[output][i].values[j];
|
cannam@99
|
483 }
|
cannam@99
|
484
|
cannam@99
|
485 (out ? *out : cout) << endl;
|
cannam@99
|
486 }
|
cannam@99
|
487 }
|
cannam@99
|
488
|
cannam@99
|
489 void
|
cannam@64
|
490 printPluginPath(bool verbose)
|
cannam@40
|
491 {
|
cannam@64
|
492 if (verbose) {
|
cannam@64
|
493 cout << "\nVamp plugin search path: ";
|
cannam@64
|
494 }
|
cannam@64
|
495
|
cannam@99
|
496 vector<string> path = PluginHostAdapter::getPluginPath();
|
cannam@40
|
497 for (size_t i = 0; i < path.size(); ++i) {
|
cannam@64
|
498 if (verbose) {
|
cannam@64
|
499 cout << "[" << path[i] << "]";
|
cannam@64
|
500 } else {
|
cannam@64
|
501 cout << path[i] << endl;
|
cannam@64
|
502 }
|
cannam@40
|
503 }
|
cannam@64
|
504
|
cannam@64
|
505 if (verbose) cout << endl;
|
cannam@40
|
506 }
|
cannam@40
|
507
|
cannam@40
|
508 void
|
cannam@95
|
509 enumeratePlugins(Verbosity verbosity)
|
cannam@40
|
510 {
|
cannam@64
|
511 PluginLoader *loader = PluginLoader::getInstance();
|
cannam@64
|
512
|
cannam@95
|
513 if (verbosity == PluginInformation) {
|
cannam@95
|
514 cout << "\nVamp plugin libraries found in search path:" << endl;
|
cannam@95
|
515 }
|
cannam@64
|
516
|
cannam@99
|
517 vector<PluginLoader::PluginKey> plugins = loader->listPlugins();
|
cannam@99
|
518 typedef multimap<string, PluginLoader::PluginKey>
|
cannam@64
|
519 LibraryMap;
|
cannam@64
|
520 LibraryMap libraryMap;
|
cannam@64
|
521
|
cannam@64
|
522 for (size_t i = 0; i < plugins.size(); ++i) {
|
cannam@99
|
523 string path = loader->getLibraryPathForPlugin(plugins[i]);
|
cannam@64
|
524 libraryMap.insert(LibraryMap::value_type(path, plugins[i]));
|
cannam@64
|
525 }
|
cannam@64
|
526
|
cannam@99
|
527 string prevPath = "";
|
cannam@64
|
528 int index = 0;
|
cannam@64
|
529
|
cannam@64
|
530 for (LibraryMap::iterator i = libraryMap.begin();
|
cannam@64
|
531 i != libraryMap.end(); ++i) {
|
cannam@64
|
532
|
cannam@99
|
533 string path = i->first;
|
cannam@64
|
534 PluginLoader::PluginKey key = i->second;
|
cannam@64
|
535
|
cannam@64
|
536 if (path != prevPath) {
|
cannam@64
|
537 prevPath = path;
|
cannam@64
|
538 index = 0;
|
cannam@95
|
539 if (verbosity == PluginInformation) {
|
cannam@95
|
540 cout << "\n " << path << ":" << endl;
|
cannam@95
|
541 }
|
cannam@40
|
542 }
|
cannam@64
|
543
|
cannam@99
|
544 Plugin *plugin = loader->loadPlugin(key, 48000);
|
cannam@64
|
545 if (plugin) {
|
cannam@64
|
546
|
cannam@64
|
547 char c = char('A' + index);
|
cannam@64
|
548 if (c > 'Z') c = char('a' + (index - 26));
|
cannam@64
|
549
|
cannam@95
|
550 if (verbosity == PluginInformation) {
|
cannam@64
|
551
|
cannam@95
|
552 cout << " [" << c << "] [v"
|
cannam@95
|
553 << plugin->getVampApiVersion() << "] "
|
cannam@95
|
554 << plugin->getName() << ", \""
|
cannam@95
|
555 << plugin->getIdentifier() << "\"" << " ["
|
cannam@95
|
556 << plugin->getMaker() << "]" << endl;
|
cannam@95
|
557
|
cannam@95
|
558 PluginLoader::PluginCategoryHierarchy category =
|
cannam@95
|
559 loader->getPluginCategory(key);
|
cannam@95
|
560
|
cannam@95
|
561 if (!category.empty()) {
|
cannam@95
|
562 cout << " ";
|
cannam@95
|
563 for (size_t ci = 0; ci < category.size(); ++ci) {
|
cannam@95
|
564 cout << " > " << category[ci];
|
cannam@95
|
565 }
|
cannam@95
|
566 cout << endl;
|
cannam@64
|
567 }
|
cannam@95
|
568
|
cannam@95
|
569 if (plugin->getDescription() != "") {
|
cannam@95
|
570 cout << " - " << plugin->getDescription() << endl;
|
cannam@95
|
571 }
|
cannam@95
|
572
|
cannam@95
|
573 } else if (verbosity == PluginIds) {
|
cannam@95
|
574 cout << "vamp:" << key << endl;
|
cannam@47
|
575 }
|
cannam@95
|
576
|
cannam@99
|
577 Plugin::OutputList outputs =
|
cannam@64
|
578 plugin->getOutputDescriptors();
|
cannam@64
|
579
|
cannam@95
|
580 if (outputs.size() > 1 || verbosity == PluginOutputIds) {
|
cannam@64
|
581 for (size_t j = 0; j < outputs.size(); ++j) {
|
cannam@95
|
582 if (verbosity == PluginInformation) {
|
cannam@95
|
583 cout << " (" << j << ") "
|
cannam@95
|
584 << outputs[j].name << ", \""
|
cannam@95
|
585 << outputs[j].identifier << "\"" << endl;
|
cannam@95
|
586 if (outputs[j].description != "") {
|
cannam@95
|
587 cout << " - "
|
cannam@95
|
588 << outputs[j].description << endl;
|
cannam@95
|
589 }
|
cannam@95
|
590 } else if (verbosity == PluginOutputIds) {
|
cannam@95
|
591 cout << "vamp:" << key << ":" << outputs[j].identifier << endl;
|
cannam@40
|
592 }
|
cannam@40
|
593 }
|
cannam@64
|
594 }
|
cannam@64
|
595
|
cannam@64
|
596 ++index;
|
cannam@64
|
597
|
cannam@64
|
598 delete plugin;
|
cannam@40
|
599 }
|
cannam@40
|
600 }
|
cannam@64
|
601
|
cannam@95
|
602 if (verbosity == PluginInformation) {
|
cannam@95
|
603 cout << endl;
|
cannam@95
|
604 }
|
cannam@40
|
605 }
|
cannam@40
|
606
|
cannam@40
|
607 void
|
cannam@99
|
608 printPluginCategoryList()
|
cannam@16
|
609 {
|
cannam@99
|
610 PluginLoader *loader = PluginLoader::getInstance();
|
cannam@88
|
611
|
cannam@99
|
612 vector<PluginLoader::PluginKey> plugins = loader->listPlugins();
|
cannam@88
|
613
|
cannam@99
|
614 set<string> printedcats;
|
cannam@99
|
615
|
cannam@99
|
616 for (size_t i = 0; i < plugins.size(); ++i) {
|
cannam@99
|
617
|
cannam@99
|
618 PluginLoader::PluginKey key = plugins[i];
|
cannam@99
|
619
|
cannam@99
|
620 PluginLoader::PluginCategoryHierarchy category =
|
cannam@99
|
621 loader->getPluginCategory(key);
|
cannam@99
|
622
|
cannam@99
|
623 Plugin *plugin = loader->loadPlugin(key, 48000);
|
cannam@99
|
624 if (!plugin) continue;
|
cannam@99
|
625
|
cannam@99
|
626 string catstr = "";
|
cannam@99
|
627
|
cannam@99
|
628 if (category.empty()) catstr = '|';
|
cannam@99
|
629 else {
|
cannam@99
|
630 for (size_t j = 0; j < category.size(); ++j) {
|
cannam@99
|
631 catstr += category[j];
|
cannam@99
|
632 catstr += '|';
|
cannam@99
|
633 if (printedcats.find(catstr) == printedcats.end()) {
|
cannam@99
|
634 std::cout << catstr << std::endl;
|
cannam@99
|
635 printedcats.insert(catstr);
|
cannam@99
|
636 }
|
cannam@99
|
637 }
|
cannam@16
|
638 }
|
cannam@88
|
639
|
cannam@99
|
640 std::cout << catstr << key << ":::" << plugin->getName() << ":::" << plugin->getMaker() << ":::" << plugin->getDescription() << std::endl;
|
cannam@16
|
641 }
|
cannam@16
|
642 }
|
cannam@16
|
643
|