comparison transform/FeatureExtractionModelTransformer.cpp @ 862:786ee8d1f30e

Fix handling of negative frame times in returned features from plugin -- we don't handle them, so don't insert them into the model (instead of blowing up)
author Chris Cannam
date Wed, 11 Dec 2013 21:40:27 +0000
parents e802e550a1f2
children 862fe7b20df7 7f97a4d9d14f
comparison
equal deleted inserted replaced
861:0f363d0fbdc3 862:786ee8d1f30e
636 } 636 }
637 } 637 }
638 638
639 void 639 void
640 FeatureExtractionModelTransformer::addFeature(size_t blockFrame, 640 FeatureExtractionModelTransformer::addFeature(size_t blockFrame,
641 const Vamp::Plugin::Feature &feature) 641 const Vamp::Plugin::Feature &feature)
642 { 642 {
643 size_t inputRate = m_input.getModel()->getSampleRate(); 643 size_t inputRate = m_input.getModel()->getSampleRate();
644 644
645 // cerr << "FeatureExtractionModelTransformer::addFeature: blockFrame = " 645 // cerr << "FeatureExtractionModelTransformer::addFeature: blockFrame = "
646 // << blockFrame << ", hasTimestamp = " << feature.hasTimestamp 646 // << blockFrame << ", hasTimestamp = " << feature.hasTimestamp
651 int binCount = 1; 651 int binCount = 1;
652 if (m_descriptor->hasFixedBinCount) { 652 if (m_descriptor->hasFixedBinCount) {
653 binCount = m_descriptor->binCount; 653 binCount = m_descriptor->binCount;
654 } 654 }
655 655
656 size_t frame = blockFrame; 656 int frame = blockFrame;
657 657
658 if (m_descriptor->sampleType == 658 if (m_descriptor->sampleType ==
659 Vamp::Plugin::OutputDescriptor::VariableSampleRate) { 659 Vamp::Plugin::OutputDescriptor::VariableSampleRate) {
660 660
661 if (!feature.hasTimestamp) { 661 if (!feature.hasTimestamp) {
676 } else { 676 } else {
677 RealTime ts(feature.timestamp.sec, feature.timestamp.nsec); 677 RealTime ts(feature.timestamp.sec, feature.timestamp.nsec);
678 m_fixedRateFeatureNo = 678 m_fixedRateFeatureNo =
679 lrint(ts.toDouble() * m_descriptor->sampleRate); 679 lrint(ts.toDouble() * m_descriptor->sampleRate);
680 } 680 }
681
682 // cerr << "m_fixedRateFeatureNo = " << m_fixedRateFeatureNo
683 // << ", m_descriptor->sampleRate = " << m_descriptor->sampleRate
684 // << ", inputRate = " << inputRate
685 // << " giving frame = ";
681 686
682 frame = lrintf((m_fixedRateFeatureNo / m_descriptor->sampleRate) 687 frame = lrintf((m_fixedRateFeatureNo / m_descriptor->sampleRate)
683 * inputRate); 688 * int(inputRate));
684 } 689
685 690 // cerr << frame << endl;
691 }
692
693 if (frame < 0) {
694 cerr
695 << "WARNING: FeatureExtractionModelTransformer::addFeature: "
696 << "Negative frame counts are not supported (frame = " << frame
697 << " from timestamp " << feature.timestamp
698 << "), dropping feature"
699 << endl;
700 return;
701 }
702
686 // Rather than repeat the complicated tests from the constructor 703 // Rather than repeat the complicated tests from the constructor
687 // to determine what sort of model we must be adding the features 704 // to determine what sort of model we must be adding the features
688 // to, we instead test what sort of model the constructor decided 705 // to, we instead test what sort of model the constructor decided
689 // to create. 706 // to create.
690 707