comparison host/vamp-simple-host.cpp @ 109:9830daccee4b

* Add -s option to output features with sample frame timestamps
author cannam
date Thu, 14 Feb 2008 15:12:12 +0000
parents fe31e6aed666
children 44e6b94c2696
comparison
equal deleted inserted replaced
108:1e7ab0399852 109:9830daccee4b
63 PluginIds, 63 PluginIds,
64 PluginOutputIds, 64 PluginOutputIds,
65 PluginInformation 65 PluginInformation
66 }; 66 };
67 67
68 void printFeatures(int, int, int, Plugin::FeatureSet, ofstream *); 68 void printFeatures(int, int, int, Plugin::FeatureSet, ofstream *, bool frames);
69 void transformInput(float *, size_t); 69 void transformInput(float *, size_t);
70 void fft(unsigned int, bool, double *, double *, double *, double *); 70 void fft(unsigned int, bool, double *, double *, double *, double *);
71 void printPluginPath(bool verbose); 71 void printPluginPath(bool verbose);
72 void printPluginCategoryList(); 72 void printPluginCategoryList();
73 void enumeratePlugins(Verbosity); 73 void enumeratePlugins(Verbosity);
74 void listPluginsInLibrary(string soname); 74 void listPluginsInLibrary(string soname);
75 int runPlugin(string myname, string soname, string id, string output, 75 int runPlugin(string myname, string soname, string id, string output,
76 int outputNo, string inputFile, string outfilename); 76 int outputNo, string inputFile, string outfilename, bool frames);
77 77
78 void usage(const char *name) 78 void usage(const char *name)
79 { 79 {
80 cerr << "\n" 80 cerr << "\n"
81 << name << ": A simple Vamp plugin host.\n\n" 81 << name << ": A simple Vamp plugin host.\n\n"
82 "Centre for Digital Music, Queen Mary, University of London.\n" 82 "Centre for Digital Music, Queen Mary, University of London.\n"
83 "Copyright 2006-2007 Chris Cannam and QMUL.\n" 83 "Copyright 2006-2007 Chris Cannam and QMUL.\n"
84 "Freely redistributable; published under a BSD-style license.\n\n" 84 "Freely redistributable; published under a BSD-style license.\n\n"
85 "Usage:\n\n" 85 "Usage:\n\n"
86 " " << name << " pluginlibrary[." << PLUGIN_SUFFIX << "]:plugin[:output] file.wav [-o out.txt]\n" 86 " " << name << " [-s] pluginlibrary[." << PLUGIN_SUFFIX << "]:plugin[:output] file.wav [-o out.txt]\n"
87 " " << name << " pluginlibrary[." << PLUGIN_SUFFIX << "]:plugin file.wav [outputno] [-o out.txt]\n\n" 87 " " << name << " [-s] pluginlibrary[." << PLUGIN_SUFFIX << "]:plugin file.wav [outputno] [-o out.txt]\n\n"
88 " -- Load plugin id \"plugin\" from \"pluginlibrary\" and run it on the\n" 88 " -- Load plugin id \"plugin\" from \"pluginlibrary\" and run it on the\n"
89 " audio data in \"file.wav\", retrieving the named \"output\", or output\n" 89 " audio data in \"file.wav\", retrieving the named \"output\", or output\n"
90 " number \"outputno\" (the first output by default) and dumping it to\n" 90 " number \"outputno\" (the first output by default) and dumping it to\n"
91 " standard output, or to \"out.txt\" if the -o option is given.\n\n" 91 " standard output, or to \"out.txt\" if the -o option is given.\n\n"
92 " \"pluginlibrary\" should be a library name, not a file path; the\n" 92 " \"pluginlibrary\" should be a library name, not a file path; the\n"
93 " standard Vamp library search path will be used to locate it. If\n" 93 " standard Vamp library search path will be used to locate it. If\n"
94 " a file path is supplied, the directory part(s) will be ignored.\n\n" 94 " a file path is supplied, the directory part(s) will be ignored.\n\n"
95 " If the -s option is given, results will be labelled with the audio\n"
96 " sample frame at which they occur. Otherwise, they will be labelled\n"
97 " with time in seconds.\n\n"
95 " " << name << " -l\n\n" 98 " " << name << " -l\n\n"
96 " -- List the plugin libraries and Vamp plugins in the library search path\n" 99 " -- List the plugin libraries and Vamp plugins in the library search path\n"
97 " in a verbose human-readable format.\n\n" 100 " in a verbose human-readable format.\n\n"
98 " " << name << " --list-ids\n\n" 101 " " << name << " --list-ids\n\n"
99 " -- List the plugins in the search path in a terse machine-readable format,\n" 102 " -- List the plugins in the search path in a terse machine-readable format,\n"
162 } else usage(name); 165 } else usage(name);
163 } 166 }
164 167
165 if (argc < 3) usage(name); 168 if (argc < 3) usage(name);
166 169
167 string soname = argv[1]; 170 bool useFrames = false;
168 string wavname = argv[2]; 171
172 int base = 1;
173 if (!strcmp(argv[1], "-s")) {
174 useFrames = true;
175 base = 2;
176 }
177
178 string soname = argv[base];
179 string wavname = argv[base+1];
169 string plugid = ""; 180 string plugid = "";
170 string output = ""; 181 string output = "";
171 int outputNo = -1; 182 int outputNo = -1;
172 string outfilename; 183 string outfilename;
173 184
174 if (argc >= 4) { 185 if (argc >= base+3) {
175 186
176 int idx = 3; 187 int idx = base+2;
177 188
178 if (isdigit(*argv[idx])) { 189 if (isdigit(*argv[idx])) {
179 outputNo = atoi(argv[idx++]); 190 outputNo = atoi(argv[idx++]);
180 } 191 }
181 192
221 if (output == "" && outputNo == -1) { 232 if (output == "" && outputNo == -1) {
222 outputNo = 0; 233 outputNo = 0;
223 } 234 }
224 235
225 return runPlugin(name, soname, plugid, output, outputNo, 236 return runPlugin(name, soname, plugid, output, outputNo,
226 wavname, outfilename); 237 wavname, outfilename, useFrames);
227 } 238 }
228 239
229 240
230 int runPlugin(string myname, string soname, string id, 241 int runPlugin(string myname, string soname, string id,
231 string output, int outputNo, string wavname, 242 string output, int outputNo, string wavname,
232 string outfilename) 243 string outfilename, bool useFrames)
233 { 244 {
234 PluginLoader *loader = PluginLoader::getInstance(); 245 PluginLoader *loader = PluginLoader::getInstance();
235 246
236 PluginLoader::PluginKey key = loader->composePluginKey(soname, id); 247 PluginLoader::PluginKey key = loader->composePluginKey(soname, id);
237 248
378 } 389 }
379 390
380 printFeatures 391 printFeatures
381 (i, sfinfo.samplerate, outputNo, plugin->process 392 (i, sfinfo.samplerate, outputNo, plugin->process
382 (plugbuf, RealTime::frame2RealTime(i, sfinfo.samplerate)), 393 (plugbuf, RealTime::frame2RealTime(i, sfinfo.samplerate)),
383 out); 394 out, useFrames);
384 395
385 int pp = progress; 396 int pp = progress;
386 progress = lrintf((float(i) / sfinfo.frames) * 100.f); 397 progress = lrintf((float(i) / sfinfo.frames) * 100.f);
387 if (progress != pp && out) { 398 if (progress != pp && out) {
388 cerr << "\r" << progress << "%"; 399 cerr << "\r" << progress << "%";
389 } 400 }
390 } 401 }
391 if (out) cerr << "\rDone" << endl; 402 if (out) cerr << "\rDone" << endl;
392 403
393 printFeatures(sfinfo.frames, sfinfo.samplerate, outputNo, 404 printFeatures(sfinfo.frames, sfinfo.samplerate, outputNo,
394 plugin->getRemainingFeatures(), out); 405 plugin->getRemainingFeatures(), out, useFrames);
395 406
396 returnValue = 0; 407 returnValue = 0;
397 408
398 done: 409 done:
399 delete plugin; 410 delete plugin;
405 return returnValue; 416 return returnValue;
406 } 417 }
407 418
408 void 419 void
409 printFeatures(int frame, int sr, int output, 420 printFeatures(int frame, int sr, int output,
410 Plugin::FeatureSet features, ofstream *out) 421 Plugin::FeatureSet features, ofstream *out, bool useFrames)
411 { 422 {
412 for (unsigned int i = 0; i < features[output].size(); ++i) { 423 for (unsigned int i = 0; i < features[output].size(); ++i) {
413 424
414 RealTime rt = RealTime::frame2RealTime(frame, sr); 425 if (useFrames) {
415 426
416 if (features[output][i].hasTimestamp) { 427 int displayFrame = frame;
417 rt = features[output][i].timestamp; 428
418 } 429 if (features[output][i].hasTimestamp) {
419 430 displayFrame = RealTime::realTime2Frame
420 (out ? *out : cout) << rt.toString() << ":"; 431 (features[output][i].timestamp, sr);
432 }
433
434 (out ? *out : cout) << displayFrame << ":";
435
436 } else {
437
438 RealTime rt = RealTime::frame2RealTime(frame, sr);
439
440 if (features[output][i].hasTimestamp) {
441 rt = features[output][i].timestamp;
442 }
443
444 (out ? *out : cout) << rt.toString() << ":";
445 }
421 446
422 for (unsigned int j = 0; j < features[output][i].values.size(); ++j) { 447 for (unsigned int j = 0; j < features[output][i].values.size(); ++j) {
423 (out ? *out : cout) << " " << features[output][i].values[j]; 448 (out ? *out : cout) << " " << features[output][i].values[j];
424 } 449 }
425 450