annotate runner/FeatureExtractionManager.h @ 34:76ea8ffc4dfa

* Fix mixdown for multi-channel source -> 1-channel plugin
author Chris Cannam
date Mon, 24 May 2010 15:06:30 +0000
parents 8b20521fc40f
children 69c438d4b9d3
rev   line source
Chris@0 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@0 4 Sonic Annotator
Chris@0 5 A utility for batch feature extraction from audio files.
Chris@0 6 Mark Levy, Chris Sutton and Chris Cannam, Queen Mary, University of London.
Chris@0 7 Copyright 2007-2008 QMUL.
Chris@0 8
Chris@0 9 This program is free software; you can redistribute it and/or
Chris@0 10 modify it under the terms of the GNU General Public License as
Chris@0 11 published by the Free Software Foundation; either version 2 of the
Chris@0 12 License, or (at your option) any later version. See the file
Chris@0 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@0 16 #ifndef _FEATURE_EXTRACTION_MANAGER_H_
Chris@0 17 #define _FEATURE_EXTRACTION_MANAGER_H_
Chris@0 18
Chris@0 19 #include <vector>
Chris@0 20 #include <set>
Chris@0 21 #include <string>
Chris@0 22
Chris@0 23 #include <vamp-hostsdk/Plugin.h>
Chris@0 24 #include <vamp-hostsdk/PluginSummarisingAdapter.h>
Chris@0 25 #include <transform/Transform.h>
Chris@0 26
Chris@0 27 using std::vector;
Chris@0 28 using std::set;
Chris@0 29 using std::string;
Chris@0 30 using std::pair;
Chris@0 31 using std::map;
Chris@0 32
Chris@0 33 class FeatureWriter;
Chris@0 34
Chris@0 35 class FeatureExtractionManager
Chris@0 36 {
Chris@0 37 public:
Chris@0 38 FeatureExtractionManager();
Chris@0 39 virtual ~FeatureExtractionManager();
Chris@0 40
Chris@0 41 void setChannels(int channels);
Chris@0 42 void setDefaultSampleRate(int sampleRate);
Chris@0 43
Chris@0 44 bool setSummaryTypes(const set<string> &summaryTypes,
Chris@0 45 bool summariesOnly,
Chris@0 46 const Vamp::HostExt::PluginSummarisingAdapter::SegmentBoundaries &boundaries);
Chris@0 47
Chris@0 48 bool addFeatureExtractor(Transform transform,
Chris@0 49 const vector<FeatureWriter*> &writers);
Chris@0 50
Chris@0 51 bool addFeatureExtractorFromFile(QString transformXmlFile,
Chris@0 52 const vector<FeatureWriter*> &writers);
Chris@0 53
Chris@0 54 bool addDefaultFeatureExtractor(TransformId transformId,
Chris@0 55 const vector<FeatureWriter*> &writers);
Chris@0 56
Chris@0 57 void extractFeatures(QString audioSource);
Chris@0 58
Chris@0 59 private:
Chris@0 60 // A plugin may have many outputs, so we can have more than one
Chris@0 61 // transform requested for a single plugin. The things we want to
Chris@0 62 // run in our process loop are plugins rather than their outputs,
Chris@0 63 // so we maintain a map from the plugins to the transforms desired
Chris@0 64 // of them and then iterate through this map
Chris@0 65
Chris@0 66 typedef map<Transform, vector<FeatureWriter *> > TransformWriterMap;
Chris@0 67 typedef map<Vamp::Plugin *, TransformWriterMap> PluginMap;
Chris@0 68 PluginMap m_plugins;
Chris@0 69
Chris@0 70 // And a map back from transforms to their plugins. Note that
Chris@0 71 // this is keyed by transform, not transform ID -- two differently
Chris@0 72 // configured transforms with the same ID must use different
Chris@0 73 // plugin instances.
Chris@0 74
Chris@0 75 typedef map<Transform, Vamp::Plugin *> TransformPluginMap;
Chris@0 76 TransformPluginMap m_transformPluginMap;
Chris@0 77
Chris@0 78 // Cache the plugin output descriptors, mapping from plugin to a
Chris@0 79 // map from output ID to output descriptor.
Chris@0 80 typedef map<string, Vamp::Plugin::OutputDescriptor> OutputMap;
Chris@0 81 typedef map<Vamp::Plugin *, OutputMap> PluginOutputMap;
Chris@0 82 PluginOutputMap m_pluginOutputs;
Chris@0 83
Chris@0 84 // Map from plugin output identifier to plugin output index
Chris@0 85 typedef map<string, int> OutputIndexMap;
Chris@0 86 OutputIndexMap m_pluginOutputIndices;
Chris@0 87
Chris@0 88 typedef set<std::string> SummaryNameSet;
Chris@0 89 SummaryNameSet m_summaries;
Chris@0 90 bool m_summariesOnly;
Chris@0 91 Vamp::HostExt::PluginSummarisingAdapter::SegmentBoundaries m_boundaries;
Chris@0 92
Chris@0 93 void writeSummaries(QString audioSource, Vamp::Plugin *);
Chris@0 94
Chris@0 95 void writeFeatures(QString audioSource,
Chris@0 96 Vamp::Plugin *,
Chris@0 97 const Vamp::Plugin::FeatureSet &,
Chris@0 98 Transform::SummaryType summaryType =
Chris@0 99 Transform::NoSummary);
Chris@31 100
Chris@31 101 void testOutputFiles(QString audioSource);
Chris@0 102 void finish();
Chris@0 103
Chris@0 104 int m_blockSize;
Chris@0 105 int m_defaultSampleRate;
Chris@0 106 int m_sampleRate;
Chris@0 107 int m_channels;
Chris@0 108
Chris@0 109 void print(Transform transform) const;
Chris@0 110 };
Chris@0 111
Chris@0 112 #endif