comparison src/vamp-hostsdk/PluginBufferingAdapter.cpp @ 415:1522e2f6d700

Fix handling of output sample rate in buffering adapter in case where SampleType is Fixed but no sample rate provided (which is invalid behaviour from the plugin, but we might as well do the right thing with it)
author Chris Cannam
date Fri, 04 Sep 2015 13:48:28 +0100
parents 656ce0eae135
children 35fa4733bc5d
comparison
equal deleted inserted replaced
414:6f88563ea26f 415:1522e2f6d700
38 #include <vector> 38 #include <vector>
39 #include <map> 39 #include <map>
40 40
41 #include <vamp-hostsdk/PluginBufferingAdapter.h> 41 #include <vamp-hostsdk/PluginBufferingAdapter.h>
42 #include <vamp-hostsdk/PluginInputDomainAdapter.h> 42 #include <vamp-hostsdk/PluginInputDomainAdapter.h>
43
44 #include <iostream>
45 using std::cerr;
46 using std::endl;
43 47
44 using std::vector; 48 using std::vector;
45 using std::map; 49 using std::map;
46 50
47 _VAMP_SDK_HOSTSPACE_BEGIN(PluginBufferingAdapter.cpp) 51 _VAMP_SDK_HOSTSPACE_BEGIN(PluginBufferingAdapter.cpp)
510 514
511 switch (outs[i].sampleType) { 515 switch (outs[i].sampleType) {
512 516
513 case OutputDescriptor::OneSamplePerStep: 517 case OutputDescriptor::OneSamplePerStep:
514 outs[i].sampleType = OutputDescriptor::FixedSampleRate; 518 outs[i].sampleType = OutputDescriptor::FixedSampleRate;
515 outs[i].sampleRate = (1.f / m_inputSampleRate) * m_stepSize; 519 outs[i].sampleRate = m_inputSampleRate / m_stepSize;
516 m_rewriteOutputTimes[i] = true; 520 m_rewriteOutputTimes[i] = true;
517 break; 521 break;
518 522
519 case OutputDescriptor::FixedSampleRate: 523 case OutputDescriptor::FixedSampleRate:
520 if (outs[i].sampleRate == 0.f) { 524 if (outs[i].sampleRate == 0.f) {
521 outs[i].sampleRate = (1.f / m_inputSampleRate) * m_stepSize; 525 outs[i].sampleRate = m_inputSampleRate / m_stepSize;
522 } 526 }
523 // We actually only need to rewrite output times for 527 // We actually only need to rewrite output times for
524 // features that don't have timestamps already, but we 528 // features that don't have timestamps already, but we
525 // can't tell from here whether our features will have 529 // can't tell from here whether our features will have
526 // timestamps or not 530 // timestamps or not
613 617
614 void 618 void
615 PluginBufferingAdapter::Impl::adjustFixedRateFeatureTime(int outputNo, 619 PluginBufferingAdapter::Impl::adjustFixedRateFeatureTime(int outputNo,
616 Feature &feature) 620 Feature &feature)
617 { 621 {
622 // cerr << "adjustFixedRateFeatureTime: from " << feature.timestamp;
623
624 double rate = m_outputs[outputNo].sampleRate;
625 if (rate == 0.0) {
626 rate = m_inputSampleRate / m_stepSize;
627 }
628
618 if (feature.hasTimestamp) { 629 if (feature.hasTimestamp) {
619 double secs = feature.timestamp.sec; 630 double secs = feature.timestamp.sec;
620 secs += feature.timestamp.nsec / 1e9; 631 secs += feature.timestamp.nsec / 1e9;
621 m_fixedRateFeatureNos[outputNo] = 632 m_fixedRateFeatureNos[outputNo] = int(secs * rate + 0.5);
622 int(secs * double(m_outputs[outputNo].sampleRate) + 0.5); 633 // cerr << " [secs = " << secs << ", no = " << m_fixedRateFeatureNos[outputNo] << "]";
623 } 634 }
624 635
625 feature.timestamp = RealTime::fromSeconds 636 feature.timestamp = RealTime::fromSeconds
626 (m_fixedRateFeatureNos[outputNo] / double(m_outputs[outputNo].sampleRate)); 637 (m_fixedRateFeatureNos[outputNo] / rate);
627 638
639 // cerr << " to " << feature.timestamp << " (rate = " << rate << ", hasTimestamp = " << feature.hasTimestamp << ")" << endl;
640
628 feature.hasTimestamp = true; 641 feature.hasTimestamp = true;
629 642
630 m_fixedRateFeatureNos[outputNo] = m_fixedRateFeatureNos[outputNo] + 1; 643 m_fixedRateFeatureNos[outputNo] = m_fixedRateFeatureNos[outputNo] + 1;
631 } 644 }
632 645