comparison runner/FeatureExtractionManager.cpp @ 110:ca565b18ba3e multiplex

Merge from default branch
author Chris Cannam
date Thu, 02 Oct 2014 14:54:48 +0100
parents 7b60603966cf 78a7c77ba432
children 0c2d8c945bbf
comparison
equal deleted inserted replaced
107:7b60603966cf 110:ca565b18ba3e
347 } 347 }
348 348
349 } else { 349 } else {
350 350
351 plugin = m_transformPluginMap[transform]; 351 plugin = m_transformPluginMap[transform];
352 }
353
354 if (m_plugins.find(plugin) == m_plugins.end()) {
355 m_orderedPlugins.push_back(plugin);
352 } 356 }
353 357
354 m_plugins[plugin][transform] = writers; 358 m_plugins[plugin][transform] = writers;
355 359
356 return true; 360 return true;
657 661
658 int earliestStartFrame = 0; 662 int earliestStartFrame = 0;
659 int latestEndFrame = frameCount; 663 int latestEndFrame = frameCount;
660 bool haveExtents = false; 664 bool haveExtents = false;
661 665
662 for (PluginMap::iterator pi = m_plugins.begin(); 666 foreach (Plugin *plugin, m_orderedPlugins) {
663 pi != m_plugins.end(); ++pi) { 667
664 668 PluginMap::iterator pi = m_plugins.find(plugin);
665 Plugin *plugin = pi->first; 669
666 670 std::cerr << "Calling reset on " << plugin << std::endl;
667 // std::cerr << "Calling reset on " << plugin << std::endl;
668 plugin->reset(); 671 plugin->reset();
669 672
670 for (TransformWriterMap::iterator ti = pi->second.begin(); 673 for (TransformWriterMap::iterator ti = pi->second.begin();
671 ti != pi->second.end(); ++ti) { 674 ti != pi->second.end(); ++ti) {
672 675
684 earliestStartFrame = startFrame; 687 earliestStartFrame = startFrame;
685 } 688 }
686 if (!haveExtents || startFrame + duration > latestEndFrame) { 689 if (!haveExtents || startFrame + duration > latestEndFrame) {
687 latestEndFrame = startFrame + duration; 690 latestEndFrame = startFrame + duration;
688 } 691 }
692
693 cerr << "startFrame for transform " << startFrame << endl;
694 cerr << "duration for transform " << duration << endl;
695 cerr << "earliestStartFrame becomes " << earliestStartFrame << endl;
696 cerr << "latestEndFrame becomes " << latestEndFrame << endl;
689 697
690 haveExtents = true; 698 haveExtents = true;
691 699
692 string outputId = transform.getOutput().toStdString(); 700 string outputId = transform.getOutput().toStdString();
693 if (m_pluginOutputs[plugin].find(outputId) == 701 if (m_pluginOutputs[plugin].find(outputId) ==
716 } 724 }
717 725
718 int startFrame = earliestStartFrame; 726 int startFrame = earliestStartFrame;
719 int endFrame = latestEndFrame; 727 int endFrame = latestEndFrame;
720 728
721 for (PluginMap::iterator pi = m_plugins.begin(); 729 foreach (Plugin *plugin, m_orderedPlugins) {
722 pi != m_plugins.end(); ++pi) { 730
731 PluginMap::iterator pi = m_plugins.find(plugin);
723 732
724 for (TransformWriterMap::const_iterator ti = pi->second.begin(); 733 for (TransformWriterMap::const_iterator ti = pi->second.begin();
725 ti != pi->second.end(); ++ti) { 734 ti != pi->second.end(); ++ti) {
726 735
727 const vector<FeatureWriter *> &writers = ti->second; 736 const vector<FeatureWriter *> &writers = ti->second;
789 } 798 }
790 799
791 Vamp::RealTime timestamp = Vamp::RealTime::frame2RealTime 800 Vamp::RealTime timestamp = Vamp::RealTime::frame2RealTime
792 (i, m_sampleRate); 801 (i, m_sampleRate);
793 802
794 for (PluginMap::iterator pi = m_plugins.begin(); 803 foreach (Plugin *plugin, m_orderedPlugins) {
795 pi != m_plugins.end(); ++pi) { 804
796 805 PluginMap::iterator pi = m_plugins.find(plugin);
797 Plugin *plugin = pi->first;
798 Plugin::FeatureSet featureSet = plugin->process(data, timestamp); 806 Plugin::FeatureSet featureSet = plugin->process(data, timestamp);
799 807
800 if (!m_summariesOnly) { 808 if (!m_summariesOnly) {
801 writeFeatures(audioSource, plugin, featureSet); 809 writeFeatures(audioSource, plugin, featureSet);
802 } 810 }
809 817
810 // std::cerr << "FeatureExtractionManager: deleting audio file reader" << std::endl; 818 // std::cerr << "FeatureExtractionManager: deleting audio file reader" << std::endl;
811 819
812 lifemgr.destroy(); // deletes reader, data 820 lifemgr.destroy(); // deletes reader, data
813 821
814 // In order to ensure our results are written to the output in a 822 foreach (Plugin *plugin, m_orderedPlugins) {
815 // fixed order (and not one that depends on the pointer value of 823
816 // each plugin on the heap in any given run of the program) we 824 PluginMap::iterator pi = m_plugins.find(plugin);
817 // take the plugins' entries from the plugin map and sort them
818 // into a new, temporary map that is indexed by the first
819 // transform for each plugin. We then iterate over than instead of
820 // over m_plugins in order to get the right ordering.
821
822 // This is not the most elegant way to do this -- it would be more
823 // elegant to impose an ordering directly on the plugins that are
824 // used as keys to m_plugins. But the plugin type comes from the
825 // Vamp SDK, so this change is more localised.
826
827 // Thanks to Matthias for this.
828
829 typedef map<Transform, PluginMap::value_type> OrderedPluginMap;
830 OrderedPluginMap orderedPlugins;
831
832 for (PluginMap::iterator pi = m_plugins.begin();
833 pi != m_plugins.end(); ++pi) {
834 Transform firstForPlugin = (pi->second).begin()->first;
835 orderedPlugins.insert(OrderedPluginMap::value_type(firstForPlugin, *pi));
836 }
837
838 for (OrderedPluginMap::iterator superPi = orderedPlugins.begin();
839 superPi != orderedPlugins.end(); ++superPi) {
840
841 // The value we extract from this map is just the same as the
842 // value_type we get from iterating over our PluginMap
843 // directly -- but we happen to get them in the right order
844 // now because the map iterator is ordered by the Transform
845 // key type ordering
846 PluginMap::value_type pi = superPi->second;
847
848 Plugin *plugin = pi.first;
849 Plugin::FeatureSet featureSet = plugin->getRemainingFeatures(); 825 Plugin::FeatureSet featureSet = plugin->getRemainingFeatures();
850 826
851 if (!m_summariesOnly) { 827 if (!m_summariesOnly) {
852 writeFeatures(audioSource, plugin, featureSet); 828 writeFeatures(audioSource, plugin, featureSet);
853 } 829 }
986 } 962 }
987 } 963 }
988 964
989 void FeatureExtractionManager::finish() 965 void FeatureExtractionManager::finish()
990 { 966 {
991 for (PluginMap::iterator pi = m_plugins.begin(); 967 foreach (Plugin *plugin, m_orderedPlugins) {
992 pi != m_plugins.end(); ++pi) { 968
969 PluginMap::iterator pi = m_plugins.find(plugin);
993 970
994 for (TransformWriterMap::iterator ti = pi->second.begin(); 971 for (TransformWriterMap::iterator ti = pi->second.begin();
995 ti != pi->second.end(); ++ti) { 972 ti != pi->second.end(); ++ti) {
996 973
997 vector<FeatureWriter *> &writers = ti->second; 974 vector<FeatureWriter *> &writers = ti->second;