comparison runner/FeatureExtractionManager.h @ 1:92911f967a16

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