annotate runner/FeatureExtractionManager.h @ 142:6b62bae0af33 midi

Help adjustments: require extra arg for help on a writer (help text was getting too long)
author Chris Cannam
date Mon, 13 Oct 2014 13:53:00 +0100
parents 1c0799754670
children 9a10c3ffff47
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@45 23 #include <QMap>
Chris@45 24
Chris@0 25 #include <vamp-hostsdk/Plugin.h>
Chris@0 26 #include <vamp-hostsdk/PluginSummarisingAdapter.h>
Chris@0 27 #include <transform/Transform.h>
Chris@0 28
Chris@0 29 using std::vector;
Chris@0 30 using std::set;
Chris@0 31 using std::string;
Chris@0 32 using std::pair;
Chris@0 33 using std::map;
Chris@0 34
Chris@0 35 class FeatureWriter;
Chris@45 36 class AudioFileReader;
Chris@0 37
Chris@0 38 class FeatureExtractionManager
Chris@0 39 {
Chris@0 40 public:
Chris@0 41 FeatureExtractionManager();
Chris@0 42 virtual ~FeatureExtractionManager();
Chris@0 43
Chris@0 44 void setChannels(int channels);
Chris@0 45 void setDefaultSampleRate(int sampleRate);
Chris@116 46 void setNormalise(bool normalise);
Chris@0 47
Chris@0 48 bool setSummaryTypes(const set<string> &summaryTypes,
Chris@0 49 const Vamp::HostExt::PluginSummarisingAdapter::SegmentBoundaries &boundaries);
Chris@0 50
Chris@102 51 void setSummariesOnly(bool summariesOnly);
Chris@102 52
Chris@0 53 bool addFeatureExtractor(Transform transform,
Chris@0 54 const vector<FeatureWriter*> &writers);
Chris@0 55
Chris@0 56 bool addFeatureExtractorFromFile(QString transformXmlFile,
Chris@0 57 const vector<FeatureWriter*> &writers);
Chris@0 58
Chris@0 59 bool addDefaultFeatureExtractor(TransformId transformId,
Chris@0 60 const vector<FeatureWriter*> &writers);
Chris@0 61
Chris@47 62 // Make a note of an audio or playlist file which will be passed
Chris@47 63 // to extractFeatures later. Amongst other things, this may
Chris@47 64 // initialise the default sample rate and channel count
Chris@106 65 void addSource(QString audioSource, bool willMultiplex);
Chris@47 66
Chris@47 67 // Extract features from the given audio or playlist file. If the
Chris@47 68 // file is a playlist and force is true, continue extracting even
Chris@47 69 // if a file in the playlist fails.
Chris@112 70 void extractFeatures(QString audioSource);
Chris@0 71
Chris@106 72 // Extract features from the given audio files, multiplexing into
Chris@106 73 // a single "file" whose individual channels are mixdowns of the
Chris@106 74 // supplied sources.
Chris@106 75 void extractFeaturesMultiplexed(QStringList sources);
Chris@106 76
Chris@0 77 private:
Chris@0 78 // A plugin may have many outputs, so we can have more than one
Chris@0 79 // transform requested for a single plugin. The things we want to
Chris@0 80 // run in our process loop are plugins rather than their outputs,
Chris@0 81 // so we maintain a map from the plugins to the transforms desired
Chris@0 82 // of them and then iterate through this map
Chris@0 83
Chris@0 84 typedef map<Transform, vector<FeatureWriter *> > TransformWriterMap;
Chris@0 85 typedef map<Vamp::Plugin *, TransformWriterMap> PluginMap;
Chris@0 86 PluginMap m_plugins;
Chris@108 87
Chris@109 88 // When we run plugins, we want to run them in a known order so as
Chris@109 89 // to get the same results on each run of Sonic Annotator with the
Chris@109 90 // same transforms. But if we just iterate through our PluginMap,
Chris@109 91 // we get them in an arbitrary order based on pointer
Chris@109 92 // address. This vector provides an underlying order for us. Note
Chris@109 93 // that the TransformWriterMap is consistently ordered (because
Chris@109 94 // the key is a Transform which has a proper ordering) so using
Chris@109 95 // this gives us a consistent order across the whole PluginMap
Chris@109 96 vector<Vamp::Plugin *> m_orderedPlugins;
Chris@109 97
Chris@0 98 // And a map back from transforms to their plugins. Note that
Chris@0 99 // this is keyed by transform, not transform ID -- two differently
Chris@0 100 // configured transforms with the same ID must use different
Chris@0 101 // plugin instances.
Chris@0 102
Chris@0 103 typedef map<Transform, Vamp::Plugin *> TransformPluginMap;
Chris@0 104 TransformPluginMap m_transformPluginMap;
Chris@0 105
Chris@0 106 // Cache the plugin output descriptors, mapping from plugin to a
Chris@0 107 // map from output ID to output descriptor.
Chris@0 108 typedef map<string, Vamp::Plugin::OutputDescriptor> OutputMap;
Chris@0 109 typedef map<Vamp::Plugin *, OutputMap> PluginOutputMap;
Chris@0 110 PluginOutputMap m_pluginOutputs;
Chris@0 111
Chris@0 112 // Map from plugin output identifier to plugin output index
Chris@0 113 typedef map<string, int> OutputIndexMap;
Chris@0 114 OutputIndexMap m_pluginOutputIndices;
Chris@0 115
Chris@0 116 typedef set<std::string> SummaryNameSet;
Chris@0 117 SummaryNameSet m_summaries;
Chris@0 118 bool m_summariesOnly;
Chris@0 119 Vamp::HostExt::PluginSummarisingAdapter::SegmentBoundaries m_boundaries;
Chris@0 120
Chris@106 121 AudioFileReader *prepareReader(QString audioSource);
Chris@106 122
Chris@106 123 void extractFeaturesFor(AudioFileReader *reader, QString audioSource);
Chris@106 124
Chris@0 125 void writeSummaries(QString audioSource, Vamp::Plugin *);
Chris@0 126
Chris@0 127 void writeFeatures(QString audioSource,
Chris@0 128 Vamp::Plugin *,
Chris@0 129 const Vamp::Plugin::FeatureSet &,
Chris@0 130 Transform::SummaryType summaryType =
Chris@0 131 Transform::NoSummary);
Chris@31 132
Chris@31 133 void testOutputFiles(QString audioSource);
Chris@0 134 void finish();
Chris@0 135
Chris@0 136 int m_blockSize;
Chris@0 137 int m_defaultSampleRate;
Chris@0 138 int m_sampleRate;
Chris@0 139 int m_channels;
Chris@116 140 bool m_normalise;
Chris@45 141
Chris@45 142 QMap<QString, AudioFileReader *> m_readyReaders;
Chris@0 143
Chris@0 144 void print(Transform transform) const;
Chris@0 145 };
Chris@0 146
Chris@0 147 #endif