Mercurial > hg > svcore
comparison transform/FeatureExtractionModelTransformer.cpp @ 935:f960d67ce842 tonioni
Merge from branch warnfix_no_size_t
author | Chris Cannam |
---|---|
date | Wed, 18 Jun 2014 13:42:01 +0100 |
parents | d03b3d956358 |
children | 65494d0d9ded |
comparison
equal
deleted
inserted
replaced
925:3efc20c59a94 | 935:f960d67ce842 |
---|---|
110 (primaryTransform, m_plugin); | 110 (primaryTransform, m_plugin); |
111 | 111 |
112 TransformFactory::getInstance()->setPluginParameters | 112 TransformFactory::getInstance()->setPluginParameters |
113 (primaryTransform, m_plugin); | 113 (primaryTransform, m_plugin); |
114 | 114 |
115 size_t channelCount = input->getChannelCount(); | 115 int channelCount = input->getChannelCount(); |
116 if (m_plugin->getMaxChannelCount() < channelCount) { | 116 if ((int)m_plugin->getMaxChannelCount() < channelCount) { |
117 channelCount = 1; | 117 channelCount = 1; |
118 } | 118 } |
119 if (m_plugin->getMinChannelCount() > channelCount) { | 119 if ((int)m_plugin->getMinChannelCount() > channelCount) { |
120 m_message = tr("Cannot provide enough channels to feature extraction plugin \"%1\" (plugin min is %2, max %3; input model has %4)") | 120 m_message = tr("Cannot provide enough channels to feature extraction plugin \"%1\" (plugin min is %2, max %3; input model has %4)") |
121 .arg(pluginId) | 121 .arg(pluginId) |
122 .arg(m_plugin->getMinChannelCount()) | 122 .arg(m_plugin->getMinChannelCount()) |
123 .arg(m_plugin->getMaxChannelCount()) | 123 .arg(m_plugin->getMaxChannelCount()) |
124 .arg(input->getChannelCount()); | 124 .arg(input->getChannelCount()); |
131 | 131 |
132 if (!m_plugin->initialise(channelCount, | 132 if (!m_plugin->initialise(channelCount, |
133 primaryTransform.getStepSize(), | 133 primaryTransform.getStepSize(), |
134 primaryTransform.getBlockSize())) { | 134 primaryTransform.getBlockSize())) { |
135 | 135 |
136 size_t pstep = primaryTransform.getStepSize(); | 136 int pstep = primaryTransform.getStepSize(); |
137 size_t pblock = primaryTransform.getBlockSize(); | 137 int pblock = primaryTransform.getBlockSize(); |
138 | 138 |
139 ///!!! hang on, this isn't right -- we're modifying a copy | 139 ///!!! hang on, this isn't right -- we're modifying a copy |
140 primaryTransform.setStepSize(0); | 140 primaryTransform.setStepSize(0); |
141 primaryTransform.setBlockSize(0); | 141 primaryTransform.setBlockSize(0); |
142 TransformFactory::getInstance()->makeContextConsistentWithPlugin | 142 TransformFactory::getInstance()->makeContextConsistentWithPlugin |
202 m_fixedRateFeatureNos.push_back(-1); // we increment before use | 202 m_fixedRateFeatureNos.push_back(-1); // we increment before use |
203 break; | 203 break; |
204 } | 204 } |
205 } | 205 } |
206 | 206 |
207 if (m_descriptors.size() <= j) { | 207 if ((int)m_descriptors.size() <= j) { |
208 m_message = tr("Plugin \"%1\" has no output named \"%2\"") | 208 m_message = tr("Plugin \"%1\" has no output named \"%2\"") |
209 .arg(pluginId) | 209 .arg(pluginId) |
210 .arg(m_transforms[j].getOutput()); | 210 .arg(m_transforms[j].getOutput()); |
211 return false; | 211 return false; |
212 } | 212 } |
247 minValue = m_descriptors[n]->minValue; | 247 minValue = m_descriptors[n]->minValue; |
248 maxValue = m_descriptors[n]->maxValue; | 248 maxValue = m_descriptors[n]->maxValue; |
249 haveExtents = true; | 249 haveExtents = true; |
250 } | 250 } |
251 | 251 |
252 size_t modelRate = input->getSampleRate(); | 252 int modelRate = input->getSampleRate(); |
253 size_t modelResolution = 1; | 253 int modelResolution = 1; |
254 | 254 |
255 if (m_descriptors[n]->sampleType != | 255 if (m_descriptors[n]->sampleType != |
256 Vamp::Plugin::OutputDescriptor::OneSamplePerStep) { | 256 Vamp::Plugin::OutputDescriptor::OneSamplePerStep) { |
257 if (m_descriptors[n]->sampleRate > input->getSampleRate()) { | 257 if (m_descriptors[n]->sampleRate > input->getSampleRate()) { |
258 cerr << "WARNING: plugin reports output sample rate as " | 258 cerr << "WARNING: plugin reports output sample rate as " |
262 | 262 |
263 switch (m_descriptors[n]->sampleType) { | 263 switch (m_descriptors[n]->sampleType) { |
264 | 264 |
265 case Vamp::Plugin::OutputDescriptor::VariableSampleRate: | 265 case Vamp::Plugin::OutputDescriptor::VariableSampleRate: |
266 if (m_descriptors[n]->sampleRate != 0.0) { | 266 if (m_descriptors[n]->sampleRate != 0.0) { |
267 modelResolution = size_t(modelRate / m_descriptors[n]->sampleRate + 0.001); | 267 modelResolution = int(modelRate / m_descriptors[n]->sampleRate + 0.001); |
268 } | 268 } |
269 break; | 269 break; |
270 | 270 |
271 case Vamp::Plugin::OutputDescriptor::OneSamplePerStep: | 271 case Vamp::Plugin::OutputDescriptor::OneSamplePerStep: |
272 modelResolution = m_transforms[n].getStepSize(); | 272 modelResolution = m_transforms[n].getStepSize(); |
279 //!!! the resolution appropriately. We can't properly display | 279 //!!! the resolution appropriately. We can't properly display |
280 //!!! data with a higher resolution than the base model at all | 280 //!!! data with a higher resolution than the base model at all |
281 if (m_descriptors[n]->sampleRate > input->getSampleRate()) { | 281 if (m_descriptors[n]->sampleRate > input->getSampleRate()) { |
282 modelResolution = 1; | 282 modelResolution = 1; |
283 } else { | 283 } else { |
284 modelResolution = size_t(round(input->getSampleRate() / | 284 modelResolution = int(round(input->getSampleRate() / |
285 m_descriptors[n]->sampleRate)); | 285 m_descriptors[n]->sampleRate)); |
286 } | 286 } |
287 break; | 287 break; |
288 } | 288 } |
289 | 289 |
453 EditableDenseThreeDimensionalModel::BasicMultirateCompression, | 453 EditableDenseThreeDimensionalModel::BasicMultirateCompression, |
454 false); | 454 false); |
455 | 455 |
456 if (!m_descriptors[n]->binNames.empty()) { | 456 if (!m_descriptors[n]->binNames.empty()) { |
457 std::vector<QString> names; | 457 std::vector<QString> names; |
458 for (size_t i = 0; i < m_descriptors[n]->binNames.size(); ++i) { | 458 for (int i = 0; i < (int)m_descriptors[n]->binNames.size(); ++i) { |
459 names.push_back(m_descriptors[n]->binNames[i].c_str()); | 459 names.push_back(m_descriptors[n]->binNames[i].c_str()); |
460 } | 460 } |
461 model->setBinNames(names); | 461 model->setBinNames(names); |
462 } | 462 } |
463 | 463 |
475 | 475 |
476 FeatureExtractionModelTransformer::~FeatureExtractionModelTransformer() | 476 FeatureExtractionModelTransformer::~FeatureExtractionModelTransformer() |
477 { | 477 { |
478 // SVDEBUG << "FeatureExtractionModelTransformer::~FeatureExtractionModelTransformer()" << endl; | 478 // SVDEBUG << "FeatureExtractionModelTransformer::~FeatureExtractionModelTransformer()" << endl; |
479 delete m_plugin; | 479 delete m_plugin; |
480 for (int j = 0; j < m_descriptors.size(); ++j) { | 480 for (int j = 0; j < (int)m_descriptors.size(); ++j) { |
481 delete m_descriptors[j]; | 481 delete m_descriptors[j]; |
482 } | 482 } |
483 } | 483 } |
484 | 484 |
485 FeatureExtractionModelTransformer::Models | 485 FeatureExtractionModelTransformer::Models |
571 cerr << "FeatureExtractionModelTransformer::run: Waiting for input model to be ready..." << endl; | 571 cerr << "FeatureExtractionModelTransformer::run: Waiting for input model to be ready..." << endl; |
572 usleep(500000); | 572 usleep(500000); |
573 } | 573 } |
574 if (m_abandoned) return; | 574 if (m_abandoned) return; |
575 | 575 |
576 size_t sampleRate = input->getSampleRate(); | 576 int sampleRate = input->getSampleRate(); |
577 | 577 |
578 size_t channelCount = input->getChannelCount(); | 578 int channelCount = input->getChannelCount(); |
579 if (m_plugin->getMaxChannelCount() < channelCount) { | 579 if ((int)m_plugin->getMaxChannelCount() < channelCount) { |
580 channelCount = 1; | 580 channelCount = 1; |
581 } | 581 } |
582 | 582 |
583 float **buffers = new float*[channelCount]; | 583 float **buffers = new float*[channelCount]; |
584 for (size_t ch = 0; ch < channelCount; ++ch) { | 584 for (int ch = 0; ch < channelCount; ++ch) { |
585 buffers[ch] = new float[primaryTransform.getBlockSize() + 2]; | 585 buffers[ch] = new float[primaryTransform.getBlockSize() + 2]; |
586 } | 586 } |
587 | 587 |
588 size_t stepSize = primaryTransform.getStepSize(); | 588 int stepSize = primaryTransform.getStepSize(); |
589 size_t blockSize = primaryTransform.getBlockSize(); | 589 int blockSize = primaryTransform.getBlockSize(); |
590 | 590 |
591 bool frequencyDomain = (m_plugin->getInputDomain() == | 591 bool frequencyDomain = (m_plugin->getInputDomain() == |
592 Vamp::Plugin::FrequencyDomain); | 592 Vamp::Plugin::FrequencyDomain); |
593 std::vector<FFTModel *> fftModels; | 593 std::vector<FFTModel *> fftModels; |
594 | 594 |
595 if (frequencyDomain) { | 595 if (frequencyDomain) { |
596 for (size_t ch = 0; ch < channelCount; ++ch) { | 596 for (int ch = 0; ch < channelCount; ++ch) { |
597 FFTModel *model = new FFTModel | 597 FFTModel *model = new FFTModel |
598 (getConformingInput(), | 598 (getConformingInput(), |
599 channelCount == 1 ? m_input.getChannel() : ch, | 599 channelCount == 1 ? m_input.getChannel() : ch, |
600 primaryTransform.getWindowType(), | 600 primaryTransform.getWindowType(), |
601 blockSize, | 601 blockSize, |
675 (contextDuration / stepSize + 1); | 675 (contextDuration / stepSize + 1); |
676 | 676 |
677 // channelCount is either m_input.getModel()->channelCount or 1 | 677 // channelCount is either m_input.getModel()->channelCount or 1 |
678 | 678 |
679 if (frequencyDomain) { | 679 if (frequencyDomain) { |
680 for (size_t ch = 0; ch < channelCount; ++ch) { | 680 for (int ch = 0; ch < channelCount; ++ch) { |
681 int column = (blockFrame - startFrame) / stepSize; | 681 int column = (blockFrame - startFrame) / stepSize; |
682 fftModels[ch]->getValuesAt(column, reals, imaginaries); | 682 fftModels[ch]->getValuesAt(column, reals, imaginaries); |
683 for (size_t i = 0; i <= blockSize/2; ++i) { | 683 for (int i = 0; i <= blockSize/2; ++i) { |
684 buffers[ch][i*2] = reals[i]; | 684 buffers[ch][i*2] = reals[i]; |
685 buffers[ch][i*2+1] = imaginaries[i]; | 685 buffers[ch][i*2+1] = imaginaries[i]; |
686 } | 686 } |
687 error = fftModels[ch]->getError(); | 687 error = fftModels[ch]->getError(); |
688 if (error != "") { | 688 if (error != "") { |
701 (buffers, Vamp::RealTime::frame2RealTime(blockFrame, sampleRate)); | 701 (buffers, Vamp::RealTime::frame2RealTime(blockFrame, sampleRate)); |
702 | 702 |
703 if (m_abandoned) break; | 703 if (m_abandoned) break; |
704 | 704 |
705 for (int j = 0; j < (int)m_outputNos.size(); ++j) { | 705 for (int j = 0; j < (int)m_outputNos.size(); ++j) { |
706 for (size_t fi = 0; fi < features[m_outputNos[j]].size(); ++fi) { | 706 for (int fi = 0; fi < (int)features[m_outputNos[j]].size(); ++fi) { |
707 Vamp::Plugin::Feature feature = features[m_outputNos[j]][fi]; | 707 Vamp::Plugin::Feature feature = features[m_outputNos[j]][fi]; |
708 addFeature(j, blockFrame, feature); | 708 addFeature(j, blockFrame, feature); |
709 } | 709 } |
710 } | 710 } |
711 | 711 |
721 | 721 |
722 if (!m_abandoned) { | 722 if (!m_abandoned) { |
723 Vamp::Plugin::FeatureSet features = m_plugin->getRemainingFeatures(); | 723 Vamp::Plugin::FeatureSet features = m_plugin->getRemainingFeatures(); |
724 | 724 |
725 for (int j = 0; j < (int)m_outputNos.size(); ++j) { | 725 for (int j = 0; j < (int)m_outputNos.size(); ++j) { |
726 for (size_t fi = 0; fi < features[m_outputNos[j]].size(); ++fi) { | 726 for (int fi = 0; fi < (int)features[m_outputNos[j]].size(); ++fi) { |
727 Vamp::Plugin::Feature feature = features[m_outputNos[j]][fi]; | 727 Vamp::Plugin::Feature feature = features[m_outputNos[j]][fi]; |
728 addFeature(j, blockFrame, feature); | 728 addFeature(j, blockFrame, feature); |
729 } | 729 } |
730 } | 730 } |
731 } | 731 } |
733 for (int j = 0; j < (int)m_outputNos.size(); ++j) { | 733 for (int j = 0; j < (int)m_outputNos.size(); ++j) { |
734 setCompletion(j, 100); | 734 setCompletion(j, 100); |
735 } | 735 } |
736 | 736 |
737 if (frequencyDomain) { | 737 if (frequencyDomain) { |
738 for (size_t ch = 0; ch < channelCount; ++ch) { | 738 for (int ch = 0; ch < channelCount; ++ch) { |
739 delete fftModels[ch]; | 739 delete fftModels[ch]; |
740 } | 740 } |
741 delete[] reals; | 741 delete[] reals; |
742 delete[] imaginaries; | 742 delete[] imaginaries; |
743 } | 743 } |
803 } | 803 } |
804 } | 804 } |
805 | 805 |
806 void | 806 void |
807 FeatureExtractionModelTransformer::addFeature(int n, | 807 FeatureExtractionModelTransformer::addFeature(int n, |
808 size_t blockFrame, | 808 int blockFrame, |
809 const Vamp::Plugin::Feature &feature) | 809 const Vamp::Plugin::Feature &feature) |
810 { | 810 { |
811 size_t inputRate = m_input.getModel()->getSampleRate(); | 811 int inputRate = m_input.getModel()->getSampleRate(); |
812 | 812 |
813 // cerr << "FeatureExtractionModelTransformer::addFeature: blockFrame = " | 813 // cerr << "FeatureExtractionModelTransformer::addFeature: blockFrame = " |
814 // << blockFrame << ", hasTimestamp = " << feature.hasTimestamp | 814 // << blockFrame << ", hasTimestamp = " << feature.hasTimestamp |
815 // << ", timestamp = " << feature.timestamp << ", hasDuration = " | 815 // << ", timestamp = " << feature.timestamp << ", hasDuration = " |
816 // << feature.hasDuration << ", duration = " << feature.duration | 816 // << feature.hasDuration << ", duration = " << feature.duration |
817 // << endl; | 817 // << endl; |
818 | |
819 int binCount = 1; | |
820 if (m_descriptors[n]->hasFixedBinCount) { | |
821 binCount = m_descriptors[n]->binCount; | |
822 } | |
823 | 818 |
824 int frame = blockFrame; | 819 int frame = blockFrame; |
825 | 820 |
826 if (m_descriptors[n]->sampleType == | 821 if (m_descriptors[n]->sampleType == |
827 Vamp::Plugin::OutputDescriptor::VariableSampleRate) { | 822 Vamp::Plugin::OutputDescriptor::VariableSampleRate) { |
883 | 878 |
884 SparseTimeValueModel *model = | 879 SparseTimeValueModel *model = |
885 getConformingOutput<SparseTimeValueModel>(n); | 880 getConformingOutput<SparseTimeValueModel>(n); |
886 if (!model) return; | 881 if (!model) return; |
887 | 882 |
888 for (int i = 0; i < feature.values.size(); ++i) { | 883 for (int i = 0; i < (int)feature.values.size(); ++i) { |
889 | 884 |
890 float value = feature.values[i]; | 885 float value = feature.values[i]; |
891 | 886 |
892 QString label = feature.label.c_str(); | 887 QString label = feature.label.c_str(); |
893 if (feature.values.size() > 1) { | 888 if (feature.values.size() > 1) { |
910 } else if (isOutput<FlexiNoteModel>(n) || isOutput<NoteModel>(n) || isOutput<RegionModel>(n)) { //GF: Added Note Model | 905 } else if (isOutput<FlexiNoteModel>(n) || isOutput<NoteModel>(n) || isOutput<RegionModel>(n)) { //GF: Added Note Model |
911 | 906 |
912 int index = 0; | 907 int index = 0; |
913 | 908 |
914 float value = 0.0; | 909 float value = 0.0; |
915 if (feature.values.size() > index) { | 910 if ((int)feature.values.size() > index) { |
916 value = feature.values[index++]; | 911 value = feature.values[index++]; |
917 } | 912 } |
918 | 913 |
919 float duration = 1; | 914 float duration = 1; |
920 if (feature.hasDuration) { | 915 if (feature.hasDuration) { |
921 duration = Vamp::RealTime::realTime2Frame(feature.duration, inputRate); | 916 duration = Vamp::RealTime::realTime2Frame(feature.duration, inputRate); |
922 } else { | 917 } else { |
923 if (feature.values.size() > index) { | 918 if ((int)feature.values.size() > index) { |
924 duration = feature.values[index++]; | 919 duration = feature.values[index++]; |
925 } | 920 } |
926 } | 921 } |
927 | 922 |
928 if (isOutput<FlexiNoteModel>(n)) { // GF: added for flexi note model | 923 if (isOutput<FlexiNoteModel>(n)) { // GF: added for flexi note model |
929 | 924 |
930 float velocity = 100; | 925 float velocity = 100; |
931 if (feature.values.size() > index) { | 926 if ((int)feature.values.size() > index) { |
932 velocity = feature.values[index++]; | 927 velocity = feature.values[index++]; |
933 } | 928 } |
934 if (velocity < 0) velocity = 127; | 929 if (velocity < 0) velocity = 127; |
935 if (velocity > 127) velocity = 127; | 930 if (velocity > 127) velocity = 127; |
936 | 931 |
942 feature.label.c_str())); | 937 feature.label.c_str())); |
943 // GF: end -- added for flexi note model | 938 // GF: end -- added for flexi note model |
944 } else if (isOutput<NoteModel>(n)) { | 939 } else if (isOutput<NoteModel>(n)) { |
945 | 940 |
946 float velocity = 100; | 941 float velocity = 100; |
947 if (feature.values.size() > index) { | 942 if ((int)feature.values.size() > index) { |
948 velocity = feature.values[index++]; | 943 velocity = feature.values[index++]; |
949 } | 944 } |
950 if (velocity < 0) velocity = 127; | 945 if (velocity < 0) velocity = 127; |
951 if (velocity > 127) velocity = 127; | 946 if (velocity > 127) velocity = 127; |
952 | 947 |
961 RegionModel *model = getConformingOutput<RegionModel>(n); | 956 RegionModel *model = getConformingOutput<RegionModel>(n); |
962 if (!model) return; | 957 if (!model) return; |
963 | 958 |
964 if (feature.hasDuration && !feature.values.empty()) { | 959 if (feature.hasDuration && !feature.values.empty()) { |
965 | 960 |
966 for (int i = 0; i < feature.values.size(); ++i) { | 961 for (int i = 0; i < (int)feature.values.size(); ++i) { |
967 | 962 |
968 float value = feature.values[i]; | 963 float value = feature.values[i]; |
969 | 964 |
970 QString label = feature.label.c_str(); | 965 QString label = feature.label.c_str(); |
971 if (feature.values.size() > 1) { | 966 if (feature.values.size() > 1) { |