Mercurial > hg > svcore
comparison transform/FeatureExtractionModelTransformer.cpp @ 822:54829c1e155e tonioni
Merge from the default branch
author | Chris Cannam |
---|---|
date | Fri, 12 Jul 2013 13:10:28 +0100 |
parents | 4faea021b5c1 98cf98a217d2 |
children | 2d53205f70cd |
comparison
equal
deleted
inserted
replaced
818:5e9ff92ca05e | 822:54829c1e155e |
---|---|
41 const Transform &transform, | 41 const Transform &transform, |
42 const PreferredOutputModel outputmodel) : | 42 const PreferredOutputModel outputmodel) : |
43 ModelTransformer(in, transform), | 43 ModelTransformer(in, transform), |
44 m_plugin(0), | 44 m_plugin(0), |
45 m_descriptor(0), | 45 m_descriptor(0), |
46 m_outputFeatureNo(0), | 46 m_outputNo(0), |
47 m_preferredOutputModel(outputmodel) | 47 m_fixedRateFeatureNo(-1), // we increment before use |
48 m_preferredOutputModel(outputmodel) | |
48 { | 49 { |
49 // SVDEBUG << "FeatureExtractionModelTransformer::FeatureExtractionModelTransformer: plugin " << pluginId << ", outputName " << m_transform.getOutput() << endl; | 50 // SVDEBUG << "FeatureExtractionModelTransformer::FeatureExtractionModelTransformer: plugin " << pluginId << ", outputName " << m_transform.getOutput() << endl; |
50 | 51 |
51 QString pluginId = transform.getPluginIdentifier(); | 52 QString pluginId = transform.getPluginIdentifier(); |
52 | 53 |
156 | 157 |
157 for (size_t i = 0; i < outputs.size(); ++i) { | 158 for (size_t i = 0; i < outputs.size(); ++i) { |
158 // SVDEBUG << "comparing output " << i << " name \"" << outputs[i].identifier << "\" with expected \"" << m_transform.getOutput() << "\"" << endl; | 159 // SVDEBUG << "comparing output " << i << " name \"" << outputs[i].identifier << "\" with expected \"" << m_transform.getOutput() << "\"" << endl; |
159 if (m_transform.getOutput() == "" || | 160 if (m_transform.getOutput() == "" || |
160 outputs[i].identifier == m_transform.getOutput().toStdString()) { | 161 outputs[i].identifier == m_transform.getOutput().toStdString()) { |
161 m_outputFeatureNo = i; | 162 m_outputNo = i; |
162 m_descriptor = new Vamp::Plugin::OutputDescriptor(outputs[i]); | 163 m_descriptor = new Vamp::Plugin::OutputDescriptor(outputs[i]); |
163 break; | 164 break; |
164 } | 165 } |
165 } | 166 } |
166 | 167 |
201 haveExtents = true; | 202 haveExtents = true; |
202 } | 203 } |
203 | 204 |
204 size_t modelRate = input->getSampleRate(); | 205 size_t modelRate = input->getSampleRate(); |
205 size_t modelResolution = 1; | 206 size_t modelResolution = 1; |
207 | |
208 if (m_descriptor->sampleType != | |
209 Vamp::Plugin::OutputDescriptor::OneSamplePerStep) { | |
210 if (m_descriptor->sampleRate > input->getSampleRate()) { | |
211 std::cerr << "WARNING: plugin reports output sample rate as " | |
212 << m_descriptor->sampleRate << " (can't display features with finer resolution than the input rate of " << input->getSampleRate() << ")" << std::endl; | |
213 } | |
214 } | |
206 | 215 |
207 switch (m_descriptor->sampleType) { | 216 switch (m_descriptor->sampleType) { |
208 | 217 |
209 case Vamp::Plugin::OutputDescriptor::VariableSampleRate: | 218 case Vamp::Plugin::OutputDescriptor::VariableSampleRate: |
210 if (m_descriptor->sampleRate != 0.0) { | 219 if (m_descriptor->sampleRate != 0.0) { |
350 model = new SparseTimeValueModel | 359 model = new SparseTimeValueModel |
351 (modelRate, modelResolution, false); | 360 (modelRate, modelResolution, false); |
352 } | 361 } |
353 | 362 |
354 Vamp::Plugin::OutputList outputs = m_plugin->getOutputDescriptors(); | 363 Vamp::Plugin::OutputList outputs = m_plugin->getOutputDescriptors(); |
355 model->setScaleUnits(outputs[m_outputFeatureNo].unit.c_str()); | 364 model->setScaleUnits(outputs[m_outputNo].unit.c_str()); |
356 | 365 |
357 m_output = model; | 366 m_output = model; |
358 | 367 |
359 QString outputEventTypeURI = description.getOutputEventTypeURI(outputId); | 368 QString outputEventTypeURI = description.getOutputEventTypeURI(outputId); |
360 m_output->setRDFTypeURI(outputEventTypeURI); | 369 m_output->setRDFTypeURI(outputEventTypeURI); |
545 Vamp::Plugin::FeatureSet features = m_plugin->process | 554 Vamp::Plugin::FeatureSet features = m_plugin->process |
546 (buffers, Vamp::RealTime::frame2RealTime(blockFrame, sampleRate)); | 555 (buffers, Vamp::RealTime::frame2RealTime(blockFrame, sampleRate)); |
547 | 556 |
548 if (m_abandoned) break; | 557 if (m_abandoned) break; |
549 | 558 |
550 for (size_t fi = 0; fi < features[m_outputFeatureNo].size(); ++fi) { | 559 for (size_t fi = 0; fi < features[m_outputNo].size(); ++fi) { |
551 Vamp::Plugin::Feature feature = | 560 Vamp::Plugin::Feature feature = features[m_outputNo][fi]; |
552 features[m_outputFeatureNo][fi]; | |
553 addFeature(blockFrame, feature); | 561 addFeature(blockFrame, feature); |
554 } | 562 } |
555 | 563 |
556 if (blockFrame == contextStart || completion > prevCompletion) { | 564 if (blockFrame == contextStart || completion > prevCompletion) { |
557 setCompletion(completion); | 565 setCompletion(completion); |
562 } | 570 } |
563 | 571 |
564 if (!m_abandoned) { | 572 if (!m_abandoned) { |
565 Vamp::Plugin::FeatureSet features = m_plugin->getRemainingFeatures(); | 573 Vamp::Plugin::FeatureSet features = m_plugin->getRemainingFeatures(); |
566 | 574 |
567 for (size_t fi = 0; fi < features[m_outputFeatureNo].size(); ++fi) { | 575 for (size_t fi = 0; fi < features[m_outputNo].size(); ++fi) { |
568 Vamp::Plugin::Feature feature = | 576 Vamp::Plugin::Feature feature = features[m_outputNo][fi]; |
569 features[m_outputFeatureNo][fi]; | |
570 addFeature(blockFrame, feature); | 577 addFeature(blockFrame, feature); |
571 } | 578 } |
572 } | 579 } |
573 | 580 |
574 setCompletion(100); | 581 setCompletion(100); |
675 } | 682 } |
676 | 683 |
677 } else if (m_descriptor->sampleType == | 684 } else if (m_descriptor->sampleType == |
678 Vamp::Plugin::OutputDescriptor::FixedSampleRate) { | 685 Vamp::Plugin::OutputDescriptor::FixedSampleRate) { |
679 | 686 |
680 if (feature.hasTimestamp) { | 687 if (!feature.hasTimestamp) { |
681 //!!! warning: sampleRate may be non-integral | 688 ++m_fixedRateFeatureNo; |
682 frame = Vamp::RealTime::realTime2Frame(feature.timestamp, | 689 } else { |
683 //!!! see comment above when setting up modelResolution and modelRate | 690 RealTime ts(feature.timestamp.sec, feature.timestamp.nsec); |
684 // lrintf(m_descriptor->sampleRate)); | 691 m_fixedRateFeatureNo = |
685 inputRate); | 692 lrint(ts.toDouble() * m_descriptor->sampleRate); |
686 } else { | 693 } |
687 frame = m_output->getEndFrame(); | 694 |
688 } | 695 frame = lrintf((m_fixedRateFeatureNo / m_descriptor->sampleRate) |
696 * inputRate); | |
689 } | 697 } |
690 | 698 |
691 // Rather than repeat the complicated tests from the constructor | 699 // Rather than repeat the complicated tests from the constructor |
692 // to determine what sort of model we must be adding the features | 700 // to determine what sort of model we must be adding the features |
693 // to, we instead test what sort of model the constructor decided | 701 // to, we instead test what sort of model the constructor decided |