comparison host/vamp-simple-host.cpp @ 190:1982246a3902

* Provide PluginWrapper method for getting hold of a nested wrapper directly (a bit gross, but useful) * Use the above to enable the simple host to adjust timestamps appropriately when printing out results from input domain adapter wrapped plugins
author cannam
date Wed, 17 Sep 2008 13:16:09 +0000
parents 31eda4b11f2b
children
comparison
equal deleted inserted replaced
189:5ce2c3f79a45 190:1982246a3902
34 use or other dealings in this Software without prior written 34 use or other dealings in this Software without prior written
35 authorization. 35 authorization.
36 */ 36 */
37 37
38 #include "vamp-sdk/PluginHostAdapter.h" 38 #include "vamp-sdk/PluginHostAdapter.h"
39 #include "vamp-sdk/hostext/PluginChannelAdapter.h"
40 #include "vamp-sdk/hostext/PluginInputDomainAdapter.h" 39 #include "vamp-sdk/hostext/PluginInputDomainAdapter.h"
41 #include "vamp-sdk/hostext/PluginLoader.h" 40 #include "vamp-sdk/hostext/PluginLoader.h"
42 #include "vamp/vamp.h" 41 #include "vamp/vamp.h"
43 42
44 #include <iostream> 43 #include <iostream>
57 56
58 using Vamp::Plugin; 57 using Vamp::Plugin;
59 using Vamp::PluginHostAdapter; 58 using Vamp::PluginHostAdapter;
60 using Vamp::RealTime; 59 using Vamp::RealTime;
61 using Vamp::HostExt::PluginLoader; 60 using Vamp::HostExt::PluginLoader;
62 61 using Vamp::HostExt::PluginWrapper;
63 #define HOST_VERSION "1.1" 62 using Vamp::HostExt::PluginInputDomainAdapter;
63
64 #define HOST_VERSION "1.3"
64 65
65 enum Verbosity { 66 enum Verbosity {
66 PluginIds, 67 PluginIds,
67 PluginOutputIds, 68 PluginOutputIds,
68 PluginInformation 69 PluginInformation
326 Plugin::OutputDescriptor od; 327 Plugin::OutputDescriptor od;
327 328
328 int returnValue = 1; 329 int returnValue = 1;
329 int progress = 0; 330 int progress = 0;
330 331
332 RealTime rt;
333 PluginWrapper *wrapper = 0;
334 RealTime adjustment = RealTime::zeroTime;
335
331 if (outputs.empty()) { 336 if (outputs.empty()) {
332 cerr << "ERROR: Plugin has no outputs!" << endl; 337 cerr << "ERROR: Plugin has no outputs!" << endl;
333 goto done; 338 goto done;
334 } 339 }
335 340
363 << ", stepSize = " << stepSize << ", blockSize = " 368 << ", stepSize = " << stepSize << ", blockSize = "
364 << blockSize << ") failed." << endl; 369 << blockSize << ") failed." << endl;
365 goto done; 370 goto done;
366 } 371 }
367 372
373 wrapper = dynamic_cast<PluginWrapper *>(plugin);
374 if (wrapper) {
375 PluginInputDomainAdapter *ida =
376 wrapper->getWrapper<PluginInputDomainAdapter>();
377 if (ida) adjustment = ida->getTimestampAdjustment();
378 }
379
368 for (size_t i = 0; i < sfinfo.frames; i += stepSize) { 380 for (size_t i = 0; i < sfinfo.frames; i += stepSize) {
369 381
370 int count; 382 int count;
371 383
372 if (sf_seek(sndfile, i, SEEK_SET) < 0) { 384 if (sf_seek(sndfile, i, SEEK_SET) < 0) {
389 plugbuf[c][j] = 0.0f; 401 plugbuf[c][j] = 0.0f;
390 ++j; 402 ++j;
391 } 403 }
392 } 404 }
393 405
406 rt = RealTime::frame2RealTime(i, sfinfo.samplerate);
407
394 printFeatures 408 printFeatures
395 (i, sfinfo.samplerate, outputNo, plugin->process 409 (RealTime::realTime2Frame(rt + adjustment, sfinfo.samplerate),
396 (plugbuf, RealTime::frame2RealTime(i, sfinfo.samplerate)), 410 sfinfo.samplerate, outputNo, plugin->process(plugbuf, rt),
397 out, useFrames); 411 out, useFrames);
398 412
399 int pp = progress; 413 int pp = progress;
400 progress = lrintf((float(i) / sfinfo.frames) * 100.f); 414 progress = lrintf((float(i) / sfinfo.frames) * 100.f);
401 if (progress != pp && out) { 415 if (progress != pp && out) {
402 cerr << "\r" << progress << "%"; 416 cerr << "\r" << progress << "%";
403 } 417 }
404 } 418 }
405 if (out) cerr << "\rDone" << endl; 419 if (out) cerr << "\rDone" << endl;
406 420
407 printFeatures(sfinfo.frames, sfinfo.samplerate, outputNo, 421 rt = RealTime::frame2RealTime(sfinfo.frames, sfinfo.samplerate);
422
423 printFeatures(RealTime::realTime2Frame(rt + adjustment, sfinfo.samplerate),
424 sfinfo.samplerate, outputNo,
408 plugin->getRemainingFeatures(), out, useFrames); 425 plugin->getRemainingFeatures(), out, useFrames);
409 426
410 returnValue = 0; 427 returnValue = 0;
411 428
412 done: 429 done: