Mercurial > hg > vamp-plugin-sdk
comparison host/vamp-simple-host.cpp @ 442:4101e3f80aa0
Fix fixed-sample-rate output timestamps in simple host; update test files
author | Chris Cannam |
---|---|
date | Thu, 18 Aug 2016 12:00:24 +0100 |
parents | 629faeec0229 |
children | 22b29720da41 |
comparison
equal
deleted
inserted
replaced
441:3204d711cf4b | 442:4101e3f80aa0 |
---|---|
78 PluginOutputIds, | 78 PluginOutputIds, |
79 PluginInformation, | 79 PluginInformation, |
80 PluginInformationDetailed | 80 PluginInformationDetailed |
81 }; | 81 }; |
82 | 82 |
83 void printFeatures(int, int, int, Plugin::FeatureSet, ofstream *, bool frames); | 83 void printFeatures(int, int, |
84 const Plugin::OutputDescriptor &, int, | |
85 const Plugin::FeatureSet &, ofstream *, bool frames); | |
84 void transformInput(float *, size_t); | 86 void transformInput(float *, size_t); |
85 void fft(unsigned int, bool, double *, double *, double *, double *); | 87 void fft(unsigned int, bool, double *, double *, double *, double *); |
86 void printPluginPath(bool verbose); | 88 void printPluginPath(bool verbose); |
87 void printPluginCategoryList(); | 89 void printPluginCategoryList(); |
88 void enumeratePlugins(Verbosity); | 90 void enumeratePlugins(Verbosity); |
362 cerr << "Plugin accepts " << minch << " -> " << maxch << " channel(s)" << endl; | 364 cerr << "Plugin accepts " << minch << " -> " << maxch << " channel(s)" << endl; |
363 cerr << "Sound file has " << channels << " (will mix/augment if necessary)" << endl; | 365 cerr << "Sound file has " << channels << " (will mix/augment if necessary)" << endl; |
364 | 366 |
365 Plugin::OutputList outputs = plugin->getOutputDescriptors(); | 367 Plugin::OutputList outputs = plugin->getOutputDescriptors(); |
366 Plugin::OutputDescriptor od; | 368 Plugin::OutputDescriptor od; |
369 Plugin::FeatureSet features; | |
367 | 370 |
368 int returnValue = 1; | 371 int returnValue = 1; |
369 int progress = 0; | 372 int progress = 0; |
370 | 373 |
371 RealTime rt; | 374 RealTime rt; |
453 } | 456 } |
454 } | 457 } |
455 | 458 |
456 rt = RealTime::frame2RealTime(currentStep * stepSize, sfinfo.samplerate); | 459 rt = RealTime::frame2RealTime(currentStep * stepSize, sfinfo.samplerate); |
457 | 460 |
461 features = plugin->process(plugbuf, rt); | |
462 | |
458 printFeatures | 463 printFeatures |
459 (RealTime::realTime2Frame(rt + adjustment, sfinfo.samplerate), | 464 (RealTime::realTime2Frame(rt + adjustment, sfinfo.samplerate), |
460 sfinfo.samplerate, outputNo, plugin->process(plugbuf, rt), | 465 sfinfo.samplerate, od, outputNo, features, out, useFrames); |
461 out, useFrames); | |
462 | 466 |
463 if (sfinfo.frames > 0){ | 467 if (sfinfo.frames > 0){ |
464 int pp = progress; | 468 int pp = progress; |
465 progress = (int)((float(currentStep * stepSize) / sfinfo.frames) * 100.f + 0.5f); | 469 progress = (int)((float(currentStep * stepSize) / sfinfo.frames) * 100.f + 0.5f); |
466 if (progress != pp && out) { | 470 if (progress != pp && out) { |
474 | 478 |
475 if (out) cerr << "\rDone" << endl; | 479 if (out) cerr << "\rDone" << endl; |
476 | 480 |
477 rt = RealTime::frame2RealTime(currentStep * stepSize, sfinfo.samplerate); | 481 rt = RealTime::frame2RealTime(currentStep * stepSize, sfinfo.samplerate); |
478 | 482 |
483 features = plugin->getRemainingFeatures(); | |
484 | |
479 printFeatures(RealTime::realTime2Frame(rt + adjustment, sfinfo.samplerate), | 485 printFeatures(RealTime::realTime2Frame(rt + adjustment, sfinfo.samplerate), |
480 sfinfo.samplerate, outputNo, | 486 sfinfo.samplerate, od, outputNo, features, out, useFrames); |
481 plugin->getRemainingFeatures(), out, useFrames); | |
482 | 487 |
483 returnValue = 0; | 488 returnValue = 0; |
484 | 489 |
485 done: | 490 done: |
486 delete plugin; | 491 delete plugin; |
490 } | 495 } |
491 sf_close(sndfile); | 496 sf_close(sndfile); |
492 return returnValue; | 497 return returnValue; |
493 } | 498 } |
494 | 499 |
500 static double | |
501 toSeconds(const RealTime &time) | |
502 { | |
503 return time.sec + double(time.nsec + 1) / 1000000000.0; | |
504 } | |
505 | |
495 void | 506 void |
496 printFeatures(int frame, int sr, int output, | 507 printFeatures(int frame, int sr, |
497 Plugin::FeatureSet features, ofstream *out, bool useFrames) | 508 const Plugin::OutputDescriptor &output, int outputNo, |
509 const Plugin::FeatureSet &features, ofstream *out, bool useFrames) | |
498 { | 510 { |
499 for (unsigned int i = 0; i < features[output].size(); ++i) { | 511 static int featureCount = 0; |
500 | 512 |
513 if (features.find(outputNo) == features.end()) return; | |
514 | |
515 for (size_t i = 0; i < features.at(outputNo).size(); ++i) { | |
516 | |
517 const Plugin::Feature &f = features.at(outputNo).at(i); | |
518 | |
519 bool haveRt = false; | |
520 RealTime rt; | |
521 | |
522 if (output.sampleType == Plugin::OutputDescriptor::VariableSampleRate) { | |
523 rt = f.timestamp; | |
524 haveRt = true; | |
525 } else if (output.sampleType == Plugin::OutputDescriptor::FixedSampleRate) { | |
526 int n = featureCount; | |
527 if (f.hasTimestamp) { | |
528 n = int(round(toSeconds(f.timestamp) * output.sampleRate)); | |
529 } | |
530 rt = RealTime::fromSeconds(double(n) / output.sampleRate); | |
531 haveRt = true; | |
532 } | |
533 | |
501 if (useFrames) { | 534 if (useFrames) { |
502 | 535 |
503 int displayFrame = frame; | 536 int displayFrame = frame; |
504 | 537 |
505 if (features[output][i].hasTimestamp) { | 538 if (haveRt) { |
506 displayFrame = RealTime::realTime2Frame | 539 displayFrame = RealTime::realTime2Frame(rt, sr); |
507 (features[output][i].timestamp, sr); | |
508 } | 540 } |
509 | 541 |
510 (out ? *out : cout) << displayFrame; | 542 (out ? *out : cout) << displayFrame; |
511 | 543 |
512 if (features[output][i].hasDuration) { | 544 if (f.hasDuration) { |
513 displayFrame = RealTime::realTime2Frame | 545 displayFrame = RealTime::realTime2Frame(f.duration, sr); |
514 (features[output][i].duration, sr); | |
515 (out ? *out : cout) << "," << displayFrame; | 546 (out ? *out : cout) << "," << displayFrame; |
516 } | 547 } |
517 | 548 |
518 (out ? *out : cout) << ":"; | 549 (out ? *out : cout) << ":"; |
519 | 550 |
520 } else { | 551 } else { |
521 | 552 |
522 RealTime rt = RealTime::frame2RealTime(frame, sr); | 553 if (!haveRt) { |
523 | 554 rt = RealTime::frame2RealTime(frame, sr); |
524 if (features[output][i].hasTimestamp) { | |
525 rt = features[output][i].timestamp; | |
526 } | 555 } |
527 | 556 |
528 (out ? *out : cout) << rt.toString(); | 557 (out ? *out : cout) << rt.toString(); |
529 | 558 |
530 if (features[output][i].hasDuration) { | 559 if (f.hasDuration) { |
531 rt = features[output][i].duration; | 560 rt = f.duration; |
532 (out ? *out : cout) << "," << rt.toString(); | 561 (out ? *out : cout) << "," << rt.toString(); |
533 } | 562 } |
534 | 563 |
535 (out ? *out : cout) << ":"; | 564 (out ? *out : cout) << ":"; |
536 } | 565 } |
537 | 566 |
538 for (unsigned int j = 0; j < features[output][i].values.size(); ++j) { | 567 for (unsigned int j = 0; j < f.values.size(); ++j) { |
539 (out ? *out : cout) << " " << features[output][i].values[j]; | 568 (out ? *out : cout) << " " << f.values[j]; |
540 } | 569 } |
541 (out ? *out : cout) << " " << features[output][i].label; | 570 (out ? *out : cout) << " " << f.label; |
542 | 571 |
543 (out ? *out : cout) << endl; | 572 (out ? *out : cout) << endl; |
573 | |
574 ++featureCount; | |
544 } | 575 } |
545 } | 576 } |
546 | 577 |
547 void | 578 void |
548 printPluginPath(bool verbose) | 579 printPluginPath(bool verbose) |