comparison src/vamp-hostsdk/PluginBufferingAdapter.cpp @ 348:8037a36dcf9e

Fix incorrect handling of FixedSampleRate outputs in PluginBufferingAdapter
author Chris Cannam
date Wed, 27 Mar 2013 16:50:19 +0000
parents c97e70ed5abc
children 1a8a58e8ea7a
comparison
equal deleted inserted replaced
347:efb69fd6f27f 348:8037a36dcf9e
242 float m_inputSampleRate; 242 float m_inputSampleRate;
243 long m_frame; 243 long m_frame;
244 bool m_unrun; 244 bool m_unrun;
245 mutable OutputList m_outputs; 245 mutable OutputList m_outputs;
246 mutable std::map<int, bool> m_rewriteOutputTimes; 246 mutable std::map<int, bool> m_rewriteOutputTimes;
247 std::map<int, int> m_fixedRateFeatureNos; // output no -> feature no
247 248
248 void processBlock(FeatureSet& allFeatureSets); 249 void processBlock(FeatureSet& allFeatureSets);
250 void adjustFixedRateFeatureTime(int outputNo, Feature &);
249 }; 251 };
250 252
251 PluginBufferingAdapter::PluginBufferingAdapter(Plugin *plugin) : 253 PluginBufferingAdapter::PluginBufferingAdapter(Plugin *plugin) :
252 PluginWrapper(plugin) 254 PluginWrapper(plugin)
253 { 255 {
605 } 607 }
606 608
607 return allFeatureSets; 609 return allFeatureSets;
608 } 610 }
609 611
612 void
613 PluginBufferingAdapter::Impl::adjustFixedRateFeatureTime(int outputNo,
614 Feature &feature)
615 {
616 if (feature.hasTimestamp) {
617 double secs = feature.timestamp.sec;
618 secs += feature.timestamp.nsec / 1e9;
619 double eps = 0.00001;
620 m_fixedRateFeatureNos[outputNo] =
621 int(secs * m_outputs[outputNo].sampleRate + 0.5);
622 }
623
624 feature.timestamp = RealTime::fromSeconds
625 (m_fixedRateFeatureNos[outputNo] / m_outputs[outputNo].sampleRate);
626
627 feature.hasTimestamp = true;
628
629 m_fixedRateFeatureNos[outputNo] = m_fixedRateFeatureNos[outputNo] + 1;
630 }
631
610 PluginBufferingAdapter::FeatureSet 632 PluginBufferingAdapter::FeatureSet
611 PluginBufferingAdapter::Impl::getRemainingFeatures() 633 PluginBufferingAdapter::Impl::getRemainingFeatures()
612 { 634 {
613 FeatureSet allFeatureSets; 635 FeatureSet allFeatureSets;
614 636
629 651
630 FeatureSet featureSet = m_plugin->getRemainingFeatures(); 652 FeatureSet featureSet = m_plugin->getRemainingFeatures();
631 653
632 for (map<int, FeatureList>::iterator iter = featureSet.begin(); 654 for (map<int, FeatureList>::iterator iter = featureSet.begin();
633 iter != featureSet.end(); ++iter) { 655 iter != featureSet.end(); ++iter) {
656
657 int outputNo = iter->first;
634 FeatureList featureList = iter->second; 658 FeatureList featureList = iter->second;
659
635 for (size_t i = 0; i < featureList.size(); ++i) { 660 for (size_t i = 0; i < featureList.size(); ++i) {
636 allFeatureSets[iter->first].push_back(featureList[i]); 661
662 if (m_outputs[outputNo].sampleType ==
663 OutputDescriptor::FixedSampleRate) {
664 adjustFixedRateFeatureTime(outputNo, featureList[i]);
665 }
666
667 allFeatureSets[outputNo].push_back(featureList[i]);
637 } 668 }
638 } 669 }
639 670
640 return allFeatureSets; 671 return allFeatureSets;
641 } 672 }
679 featureList[i].timestamp = timestamp + adjustment; 710 featureList[i].timestamp = timestamp + adjustment;
680 featureList[i].hasTimestamp = true; 711 featureList[i].hasTimestamp = true;
681 break; 712 break;
682 713
683 case OutputDescriptor::FixedSampleRate: 714 case OutputDescriptor::FixedSampleRate:
684 // use our internal timestamp if feature lacks one 715 adjustFixedRateFeatureTime(outputNo, featureList[i]);
685 if (!featureList[i].hasTimestamp) {
686 featureList[i].timestamp = timestamp + adjustment;
687 featureList[i].hasTimestamp = true;
688 }
689 break; 716 break;
690 717
691 case OutputDescriptor::VariableSampleRate: 718 case OutputDescriptor::VariableSampleRate:
692 break; // plugin must set timestamp 719 // plugin must set timestamp
720 break;
693 721
694 default: 722 default:
695 break; 723 break;
696 } 724 }
697 725