comparison transform/FeatureExtractionModelTransformer.cpp @ 876:47aa3aeb687b tonioni

For outputs with unknown bin count or multiple bins with variable sample rate, create additional output models for bins beyond the first
author Chris Cannam
date Wed, 29 Jan 2014 09:31:22 +0000
parents 3e6ed8a8577b
children b109b88bfa85
comparison
equal deleted inserted replaced
875:3e6ed8a8577b 876:47aa3aeb687b
211 return false; 211 return false;
212 } 212 }
213 } 213 }
214 214
215 for (int j = 0; j < (int)m_transforms.size(); ++j) { 215 for (int j = 0; j < (int)m_transforms.size(); ++j) {
216 createOutputModel(j); 216 createOutputModels(j);
217 } 217 }
218 218
219 return true; 219 return true;
220 } 220 }
221 221
222 void 222 void
223 FeatureExtractionModelTransformer::createOutputModel(int n) 223 FeatureExtractionModelTransformer::createOutputModels(int n)
224 { 224 {
225 DenseTimeValueModel *input = getConformingInput(); 225 DenseTimeValueModel *input = getConformingInput();
226 226
227 // cerr << "FeatureExtractionModelTransformer::createOutputModel: sample type " << m_descriptor->sampleType << ", rate " << m_descriptor->sampleRate << endl; 227 // cerr << "FeatureExtractionModelTransformer::createOutputModel: sample type " << m_descriptor->sampleType << ", rate " << m_descriptor->sampleRate << endl;
228 228
230 QString outputId = m_transforms[n].getOutput(); 230 QString outputId = m_transforms[n].getOutput();
231 231
232 int binCount = 1; 232 int binCount = 1;
233 float minValue = 0.0, maxValue = 0.0; 233 float minValue = 0.0, maxValue = 0.0;
234 bool haveExtents = false; 234 bool haveExtents = false;
235 235 bool haveBinCount = m_descriptors[n]->hasFixedBinCount;
236 if (m_descriptors[n]->hasFixedBinCount) { 236
237 if (haveBinCount) {
237 binCount = m_descriptors[n]->binCount; 238 binCount = m_descriptors[n]->binCount;
238 } 239 }
240
241 m_needAdditionalModels[n] = false;
239 242
240 // cerr << "FeatureExtractionModelTransformer: output bin count " 243 // cerr << "FeatureExtractionModelTransformer: output bin count "
241 // << binCount << endl; 244 // << binCount << endl;
242 245
243 if (binCount > 0 && m_descriptors[n]->hasKnownExtents) { 246 if (binCount > 0 && m_descriptors[n]->hasKnownExtents) {
390 } 393 }
391 394
392 QString outputEventTypeURI = description.getOutputEventTypeURI(outputId); 395 QString outputEventTypeURI = description.getOutputEventTypeURI(outputId);
393 out->setRDFTypeURI(outputEventTypeURI); 396 out->setRDFTypeURI(outputEventTypeURI);
394 397
395 } else if ((binCount == 1 && m_descriptors[n]->hasFixedBinCount) || 398 } else if (binCount == 1 ||
396 (m_descriptors[n]->sampleType == 399 (m_descriptors[n]->sampleType ==
397 Vamp::Plugin::OutputDescriptor::VariableSampleRate)) { 400 Vamp::Plugin::OutputDescriptor::VariableSampleRate)) {
398 401
399 // Anything that is not a 1D, note, or interval model and that 402 // Anything that is not a 1D, note, or interval model and that
400 // has only one value per result must be a sparse time value 403 // has only one value per result must be a sparse time value
401 // model. 404 // model.
402 405
403 // Anything that is not a 1D, note, or interval model and that 406 // Anything that is not a 1D, note, or interval model and that
404 // has a variable sample rate is also treated as a sparse time 407 // has a variable sample rate is treated as a set of sparse
405 // value model regardless of its bin count, because we lack a 408 // time value models, one per output bin, because we lack a
406 // sparse 3D model. 409 // sparse 3D model.
410
411 // Anything that is not a 1D, note, or interval model and that
412 // has a fixed sample rate but an unknown number of values per
413 // result is also treated as a set of sparse time value models.
414
415 // For sets of sparse time value models, we create a single
416 // model first as the "standard" output and then create models
417 // for bins 1+ in the additional model map (mapping the output
418 // descriptor to a list of models indexed by bin-1). But we
419 // don't create the additional models yet, as this case has to
420 // work even if the number of bins is unknown at this point --
421 // we just create an additional model (copying its parameters
422 // from the default one) each time a new bin is encountered.
423
424 if (!haveBinCount || binCount > 1) {
425 m_needAdditionalModels[n] = true;
426 }
407 427
408 SparseTimeValueModel *model; 428 SparseTimeValueModel *model;
409 if (haveExtents) { 429 if (haveExtents) {
410 model = new SparseTimeValueModel 430 model = new SparseTimeValueModel
411 (modelRate, modelResolution, minValue, maxValue, false); 431 (modelRate, modelResolution, minValue, maxValue, false);
459 // SVDEBUG << "FeatureExtractionModelTransformer::~FeatureExtractionModelTransformer()" << endl; 479 // SVDEBUG << "FeatureExtractionModelTransformer::~FeatureExtractionModelTransformer()" << endl;
460 delete m_plugin; 480 delete m_plugin;
461 for (int j = 0; j < m_descriptors.size(); ++j) { 481 for (int j = 0; j < m_descriptors.size(); ++j) {
462 delete m_descriptors[j]; 482 delete m_descriptors[j];
463 } 483 }
484 }
485
486 FeatureExtractionModelTransformer::Models
487 FeatureExtractionModelTransformer::getAdditionalOutputModels()
488 {
489 Models mm;
490 for (AdditionalModelMap::iterator i = m_additionalModels.begin();
491 i != m_additionalModels.end(); ++i) {
492 for (std::map<int, SparseTimeValueModel *>::iterator j =
493 i->second.begin();
494 j != i->second.end(); ++j) {
495 SparseTimeValueModel *m = j->second;
496 if (m) mm.push_back(m);
497 }
498 }
499 return mm;
500 }
501
502 SparseTimeValueModel *
503 FeatureExtractionModelTransformer::getAdditionalModel(int n, int binNo)
504 {
505 std::cerr << "getAdditionalModel(" << n << ", " << binNo << ")" << std::endl;
506
507 if (binNo == 0) {
508 std::cerr << "Internal error: binNo == 0 in getAdditionalModel (should be using primary model)" << std::endl;
509 return 0;
510 }
511
512 if (!m_needAdditionalModels[n]) return 0;
513 if (!isOutput<SparseTimeValueModel>(n)) return 0;
514 if (m_additionalModels[n][binNo]) return m_additionalModels[n][binNo];
515
516 std::cerr << "getAdditionalModel(" << n << ", " << binNo << "): creating" << std::endl;
517
518 SparseTimeValueModel *baseModel = getConformingOutput<SparseTimeValueModel>(n);
519 if (!baseModel) return 0;
520
521 std::cerr << "getAdditionalModel(" << n << ", " << binNo << "): (from " << baseModel << ")" << std::endl;
522
523 SparseTimeValueModel *additional =
524 new SparseTimeValueModel(baseModel->getSampleRate(),
525 baseModel->getResolution(),
526 baseModel->getValueMinimum(),
527 baseModel->getValueMaximum(),
528 false);
529
530 additional->setScaleUnits(baseModel->getScaleUnits());
531 additional->setRDFTypeURI(baseModel->getRDFTypeURI());
532
533 m_additionalModels[n][binNo] = additional;
534 return additional;
464 } 535 }
465 536
466 DenseTimeValueModel * 537 DenseTimeValueModel *
467 FeatureExtractionModelTransformer::getConformingInput() 538 FeatureExtractionModelTransformer::getConformingInput()
468 { 539 {
797 QString label = feature.label.c_str(); 868 QString label = feature.label.c_str();
798 if (feature.values.size() > 1) { 869 if (feature.values.size() > 1) {
799 label = QString("[%1] %2").arg(i+1).arg(label); 870 label = QString("[%1] %2").arg(i+1).arg(label);
800 } 871 }
801 872
802 model->addPoint(SparseTimeValueModel::Point(frame, value, label)); 873 SparseTimeValueModel *targetModel = model;
874
875 if (m_needAdditionalModels[n] && i > 0) {
876 targetModel = getAdditionalModel(n, i);
877 if (!targetModel) targetModel = model;
878 std::cerr << "adding point to model " << targetModel
879 << " for output " << n << " bin " << i << std::endl;
880 }
881
882 targetModel->addPoint
883 (SparseTimeValueModel::Point(frame, value, label));
803 } 884 }
804 885
805 } else if (isOutput<FlexiNoteModel>(n) || isOutput<NoteModel>(n) || isOutput<RegionModel>(n)) { //GF: Added Note Model 886 } else if (isOutput<FlexiNoteModel>(n) || isOutput<NoteModel>(n) || isOutput<RegionModel>(n)) { //GF: Added Note Model
806 887
807 int index = 0; 888 int index = 0;
896 } 977 }
897 978
898 void 979 void
899 FeatureExtractionModelTransformer::setCompletion(int n, int completion) 980 FeatureExtractionModelTransformer::setCompletion(int n, int completion)
900 { 981 {
901 int binCount = 1;
902 if (m_descriptors[n]->hasFixedBinCount) {
903 binCount = m_descriptors[n]->binCount;
904 }
905
906 // SVDEBUG << "FeatureExtractionModelTransformer::setCompletion(" 982 // SVDEBUG << "FeatureExtractionModelTransformer::setCompletion("
907 // << completion << ")" << endl; 983 // << completion << ")" << endl;
908 984
909 if (isOutput<SparseOneDimensionalModel>(n)) { 985 if (isOutput<SparseOneDimensionalModel>(n)) {
910 986