Mercurial > hg > svcore
comparison transform/FeatureExtractionModelTransformer.cpp @ 855:42bbc538d983 tonioni_multi_transform
Merge from tonioni branch
author | Chris Cannam |
---|---|
date | Wed, 04 Dec 2013 18:29:15 +0000 |
parents | dba8a02b0413 |
children | 13803edd513d |
comparison
equal
deleted
inserted
replaced
849:418cd2064769 | 855:42bbc538d983 |
---|---|
136 primaryTransform.getBlockSize())) { | 136 primaryTransform.getBlockSize())) { |
137 | 137 |
138 size_t pstep = primaryTransform.getStepSize(); | 138 size_t pstep = primaryTransform.getStepSize(); |
139 size_t pblock = primaryTransform.getBlockSize(); | 139 size_t pblock = primaryTransform.getBlockSize(); |
140 | 140 |
141 ///!!! hang on, this isn't right -- we're modifying a copy | |
141 primaryTransform.setStepSize(0); | 142 primaryTransform.setStepSize(0); |
142 primaryTransform.setBlockSize(0); | 143 primaryTransform.setBlockSize(0); |
143 TransformFactory::getInstance()->makeContextConsistentWithPlugin | 144 TransformFactory::getInstance()->makeContextConsistentWithPlugin |
144 (primaryTransform, m_plugin); | 145 (primaryTransform, m_plugin); |
145 | 146 |
447 | 448 |
448 FeatureExtractionModelTransformer::~FeatureExtractionModelTransformer() | 449 FeatureExtractionModelTransformer::~FeatureExtractionModelTransformer() |
449 { | 450 { |
450 // SVDEBUG << "FeatureExtractionModelTransformer::~FeatureExtractionModelTransformer()" << endl; | 451 // SVDEBUG << "FeatureExtractionModelTransformer::~FeatureExtractionModelTransformer()" << endl; |
451 delete m_plugin; | 452 delete m_plugin; |
452 delete m_descriptors[n]; | 453 for (int j = 0; j < m_descriptors.size(); ++j) { |
454 delete m_descriptors[j]; | |
455 } | |
453 } | 456 } |
454 | 457 |
455 DenseTimeValueModel * | 458 DenseTimeValueModel * |
456 FeatureExtractionModelTransformer::getConformingInput() | 459 FeatureExtractionModelTransformer::getConformingInput() |
457 { | 460 { |
471 DenseTimeValueModel *input = getConformingInput(); | 474 DenseTimeValueModel *input = getConformingInput(); |
472 if (!input) return; | 475 if (!input) return; |
473 | 476 |
474 if (m_outputs.empty()) return; | 477 if (m_outputs.empty()) return; |
475 | 478 |
479 Transform primaryTransform = m_transforms[0]; | |
480 | |
476 while (!input->isReady() && !m_abandoned) { | 481 while (!input->isReady() && !m_abandoned) { |
477 SVDEBUG << "FeatureExtractionModelTransformer::run: Waiting for input model to be ready..." << endl; | 482 SVDEBUG << "FeatureExtractionModelTransformer::run: Waiting for input model to be ready..." << endl; |
478 usleep(500000); | 483 usleep(500000); |
479 } | 484 } |
480 if (m_abandoned) return; | 485 if (m_abandoned) return; |
486 channelCount = 1; | 491 channelCount = 1; |
487 } | 492 } |
488 | 493 |
489 float **buffers = new float*[channelCount]; | 494 float **buffers = new float*[channelCount]; |
490 for (size_t ch = 0; ch < channelCount; ++ch) { | 495 for (size_t ch = 0; ch < channelCount; ++ch) { |
491 buffers[ch] = new float[m_transforms[n].getBlockSize() + 2]; | 496 buffers[ch] = new float[primaryTransform.getBlockSize() + 2]; |
492 } | 497 } |
493 | 498 |
494 size_t stepSize = m_transforms[n].getStepSize(); | 499 size_t stepSize = primaryTransform.getStepSize(); |
495 size_t blockSize = m_transforms[n].getBlockSize(); | 500 size_t blockSize = primaryTransform.getBlockSize(); |
496 | 501 |
497 bool frequencyDomain = (m_plugin->getInputDomain() == | 502 bool frequencyDomain = (m_plugin->getInputDomain() == |
498 Vamp::Plugin::FrequencyDomain); | 503 Vamp::Plugin::FrequencyDomain); |
499 std::vector<FFTModel *> fftModels; | 504 std::vector<FFTModel *> fftModels; |
500 | 505 |
501 if (frequencyDomain) { | 506 if (frequencyDomain) { |
502 for (size_t ch = 0; ch < channelCount; ++ch) { | 507 for (size_t ch = 0; ch < channelCount; ++ch) { |
503 FFTModel *model = new FFTModel | 508 FFTModel *model = new FFTModel |
504 (getConformingInput(), | 509 (getConformingInput(), |
505 channelCount == 1 ? m_input.getChannel() : ch, | 510 channelCount == 1 ? m_input.getChannel() : ch, |
506 m_transforms[n].getWindowType(), | 511 primaryTransform.getWindowType(), |
507 blockSize, | 512 blockSize, |
508 stepSize, | 513 stepSize, |
509 blockSize, | 514 blockSize, |
510 false, | 515 false, |
511 StorageAdviser::PrecisionCritical); | 516 StorageAdviser::PrecisionCritical); |
512 if (!model->isOK()) { | 517 if (!model->isOK()) { |
513 delete model; | 518 delete model; |
514 setCompletion(100); | 519 for (int j = 0; j < (int)m_outputNos.size(); ++j) { |
520 setCompletion(j, 100); | |
521 } | |
515 //!!! need a better way to handle this -- previously we were using a QMessageBox but that isn't an appropriate thing to do here either | 522 //!!! need a better way to handle this -- previously we were using a QMessageBox but that isn't an appropriate thing to do here either |
516 throw AllocationFailed("Failed to create the FFT model for this feature extraction model transformer"); | 523 throw AllocationFailed("Failed to create the FFT model for this feature extraction model transformer"); |
517 } | 524 } |
518 model->resume(); | 525 model->resume(); |
519 fftModels.push_back(model); | 526 fftModels.push_back(model); |
521 } | 528 } |
522 | 529 |
523 long startFrame = m_input.getModel()->getStartFrame(); | 530 long startFrame = m_input.getModel()->getStartFrame(); |
524 long endFrame = m_input.getModel()->getEndFrame(); | 531 long endFrame = m_input.getModel()->getEndFrame(); |
525 | 532 |
526 RealTime contextStartRT = m_transforms[n].getStartTime(); | 533 RealTime contextStartRT = primaryTransform.getStartTime(); |
527 RealTime contextDurationRT = m_transforms[n].getDuration(); | 534 RealTime contextDurationRT = primaryTransform.getDuration(); |
528 | 535 |
529 long contextStart = | 536 long contextStart = |
530 RealTime::realTime2Frame(contextStartRT, sampleRate); | 537 RealTime::realTime2Frame(contextStartRT, sampleRate); |
531 | 538 |
532 long contextDuration = | 539 long contextDuration = |
545 | 552 |
546 long blockFrame = contextStart; | 553 long blockFrame = contextStart; |
547 | 554 |
548 long prevCompletion = 0; | 555 long prevCompletion = 0; |
549 | 556 |
550 setCompletion(0); | 557 for (int j = 0; j < (int)m_outputNos.size(); ++j) { |
558 setCompletion(j, 0); | |
559 } | |
551 | 560 |
552 float *reals = 0; | 561 float *reals = 0; |
553 float *imaginaries = 0; | 562 float *imaginaries = 0; |
554 if (frequencyDomain) { | 563 if (frequencyDomain) { |
555 reals = new float[blockSize/2 + 1]; | 564 reals = new float[blockSize/2 + 1]; |
602 Vamp::Plugin::FeatureSet features = m_plugin->process | 611 Vamp::Plugin::FeatureSet features = m_plugin->process |
603 (buffers, Vamp::RealTime::frame2RealTime(blockFrame, sampleRate)); | 612 (buffers, Vamp::RealTime::frame2RealTime(blockFrame, sampleRate)); |
604 | 613 |
605 if (m_abandoned) break; | 614 if (m_abandoned) break; |
606 | 615 |
607 for (size_t fi = 0; fi < features[m_outputNos[n]].size(); ++fi) { | 616 for (int j = 0; j < (int)m_outputNos.size(); ++j) { |
608 Vamp::Plugin::Feature feature = features[m_outputNos[n]][fi]; | 617 for (size_t fi = 0; fi < features[m_outputNos[j]].size(); ++fi) { |
609 addFeature(blockFrame, feature); | 618 Vamp::Plugin::Feature feature = features[m_outputNos[j]][fi]; |
610 } | 619 addFeature(j, blockFrame, feature); |
620 } | |
621 } | |
611 | 622 |
612 if (blockFrame == contextStart || completion > prevCompletion) { | 623 if (blockFrame == contextStart || completion > prevCompletion) { |
613 setCompletion(completion); | 624 for (int j = 0; j < (int)m_outputNos.size(); ++j) { |
625 setCompletion(j, completion); | |
626 } | |
614 prevCompletion = completion; | 627 prevCompletion = completion; |
615 } | 628 } |
616 | 629 |
617 blockFrame += stepSize; | 630 blockFrame += stepSize; |
618 } | 631 } |
619 | 632 |
620 if (!m_abandoned) { | 633 if (!m_abandoned) { |
621 Vamp::Plugin::FeatureSet features = m_plugin->getRemainingFeatures(); | 634 Vamp::Plugin::FeatureSet features = m_plugin->getRemainingFeatures(); |
622 | 635 |
623 for (size_t fi = 0; fi < features[m_outputNos[n]].size(); ++fi) { | 636 for (int j = 0; j < (int)m_outputNos.size(); ++j) { |
624 Vamp::Plugin::Feature feature = features[m_outputNos[n]][fi]; | 637 for (size_t fi = 0; fi < features[m_outputNos[j]].size(); ++fi) { |
625 addFeature(blockFrame, feature); | 638 Vamp::Plugin::Feature feature = features[m_outputNos[j]][fi]; |
626 } | 639 addFeature(j, blockFrame, feature); |
627 } | 640 } |
628 | 641 } |
629 setCompletion(100); | 642 } |
643 | |
644 for (int j = 0; j < (int)m_outputNos.size(); ++j) { | |
645 setCompletion(j, 100); | |
646 } | |
630 | 647 |
631 if (frequencyDomain) { | 648 if (frequencyDomain) { |
632 for (size_t ch = 0; ch < channelCount; ++ch) { | 649 for (size_t ch = 0; ch < channelCount; ++ch) { |
633 delete fftModels[ch]; | 650 delete fftModels[ch]; |
634 } | 651 } |
696 ++got; | 713 ++got; |
697 } | 714 } |
698 } | 715 } |
699 | 716 |
700 void | 717 void |
701 FeatureExtractionModelTransformer::addFeature(size_t blockFrame, | 718 FeatureExtractionModelTransformer::addFeature(int n, |
702 const Vamp::Plugin::Feature &feature) | 719 size_t blockFrame, |
720 const Vamp::Plugin::Feature &feature) | |
703 { | 721 { |
704 size_t inputRate = m_input.getModel()->getSampleRate(); | 722 size_t inputRate = m_input.getModel()->getSampleRate(); |
705 | 723 |
706 // cerr << "FeatureExtractionModelTransformer::addFeature: blockFrame = " | 724 // cerr << "FeatureExtractionModelTransformer::addFeature: blockFrame = " |
707 // << blockFrame << ", hasTimestamp = " << feature.hasTimestamp | 725 // << blockFrame << ", hasTimestamp = " << feature.hasTimestamp |
747 // Rather than repeat the complicated tests from the constructor | 765 // Rather than repeat the complicated tests from the constructor |
748 // to determine what sort of model we must be adding the features | 766 // to determine what sort of model we must be adding the features |
749 // to, we instead test what sort of model the constructor decided | 767 // to, we instead test what sort of model the constructor decided |
750 // to create. | 768 // to create. |
751 | 769 |
752 //!!! currently hardcoding model 0 | |
753 | |
754 if (isOutput<SparseOneDimensionalModel>(n)) { | 770 if (isOutput<SparseOneDimensionalModel>(n)) { |
755 | 771 |
756 SparseOneDimensionalModel *model = | 772 SparseOneDimensionalModel *model = |
757 getConformingOutput<SparseOneDimensionalModel>(n); | 773 getConformingOutput<SparseOneDimensionalModel>(n); |
758 if (!model) return; | 774 if (!model) return; |
870 SVDEBUG << "FeatureExtractionModelTransformer::addFeature: Unknown output model type!" << endl; | 886 SVDEBUG << "FeatureExtractionModelTransformer::addFeature: Unknown output model type!" << endl; |
871 } | 887 } |
872 } | 888 } |
873 | 889 |
874 void | 890 void |
875 FeatureExtractionModelTransformer::setCompletion(int completion) | 891 FeatureExtractionModelTransformer::setCompletion(int n, int completion) |
876 { | 892 { |
877 int binCount = 1; | 893 int binCount = 1; |
878 if (m_descriptors[n]->hasFixedBinCount) { | 894 if (m_descriptors[n]->hasFixedBinCount) { |
879 binCount = m_descriptors[n]->binCount; | 895 binCount = m_descriptors[n]->binCount; |
880 } | 896 } |