Chris@0: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@0: Chris@0: /* Chris@0: Sonic Annotator Chris@0: A utility for batch feature extraction from audio files. Chris@0: Mark Levy, Chris Sutton and Chris Cannam, Queen Mary, University of London. Chris@0: Copyright 2007-2008 QMUL. Chris@0: Chris@0: This program is free software; you can redistribute it and/or Chris@0: modify it under the terms of the GNU General Public License as Chris@0: published by the Free Software Foundation; either version 2 of the Chris@0: License, or (at your option) any later version. See the file Chris@0: COPYING included with this distribution for more information. Chris@0: */ Chris@0: Chris@0: #ifndef _FEATURE_EXTRACTION_MANAGER_H_ Chris@0: #define _FEATURE_EXTRACTION_MANAGER_H_ Chris@0: Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: Chris@45: #include Chris@45: Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: Chris@0: using std::vector; Chris@0: using std::set; Chris@0: using std::string; Chris@0: using std::pair; Chris@0: using std::map; Chris@0: Chris@0: class FeatureWriter; Chris@45: class AudioFileReader; Chris@0: Chris@0: class FeatureExtractionManager Chris@0: { Chris@0: public: Chris@0: FeatureExtractionManager(); Chris@0: virtual ~FeatureExtractionManager(); Chris@0: Chris@0: void setChannels(int channels); Chris@0: void setDefaultSampleRate(int sampleRate); Chris@0: Chris@0: bool setSummaryTypes(const set &summaryTypes, Chris@0: const Vamp::HostExt::PluginSummarisingAdapter::SegmentBoundaries &boundaries); Chris@0: Chris@102: void setSummariesOnly(bool summariesOnly); Chris@102: Chris@0: bool addFeatureExtractor(Transform transform, Chris@0: const vector &writers); Chris@0: Chris@0: bool addFeatureExtractorFromFile(QString transformXmlFile, Chris@0: const vector &writers); Chris@0: Chris@0: bool addDefaultFeatureExtractor(TransformId transformId, Chris@0: const vector &writers); Chris@0: Chris@47: // Make a note of an audio or playlist file which will be passed Chris@47: // to extractFeatures later. Amongst other things, this may Chris@47: // initialise the default sample rate and channel count Chris@45: void addSource(QString audioSource); Chris@47: Chris@47: // Extract features from the given audio or playlist file. If the Chris@47: // file is a playlist and force is true, continue extracting even Chris@47: // if a file in the playlist fails. Chris@47: void extractFeatures(QString audioSource, bool force); Chris@0: Chris@0: private: Chris@0: // A plugin may have many outputs, so we can have more than one Chris@0: // transform requested for a single plugin. The things we want to Chris@0: // run in our process loop are plugins rather than their outputs, Chris@0: // so we maintain a map from the plugins to the transforms desired Chris@0: // of them and then iterate through this map Chris@0: Chris@0: typedef map > TransformWriterMap; Chris@0: typedef map PluginMap; Chris@0: PluginMap m_plugins; Chris@108: Chris@0: // And a map back from transforms to their plugins. Note that Chris@0: // this is keyed by transform, not transform ID -- two differently Chris@0: // configured transforms with the same ID must use different Chris@0: // plugin instances. Chris@0: Chris@0: typedef map TransformPluginMap; Chris@0: TransformPluginMap m_transformPluginMap; Chris@0: Chris@0: // Cache the plugin output descriptors, mapping from plugin to a Chris@0: // map from output ID to output descriptor. Chris@0: typedef map OutputMap; Chris@0: typedef map PluginOutputMap; Chris@0: PluginOutputMap m_pluginOutputs; Chris@0: Chris@0: // Map from plugin output identifier to plugin output index Chris@0: typedef map OutputIndexMap; Chris@0: OutputIndexMap m_pluginOutputIndices; Chris@0: Chris@0: typedef set SummaryNameSet; Chris@0: SummaryNameSet m_summaries; Chris@0: bool m_summariesOnly; Chris@0: Vamp::HostExt::PluginSummarisingAdapter::SegmentBoundaries m_boundaries; Chris@0: Chris@0: void writeSummaries(QString audioSource, Vamp::Plugin *); Chris@0: Chris@0: void writeFeatures(QString audioSource, Chris@0: Vamp::Plugin *, Chris@0: const Vamp::Plugin::FeatureSet &, Chris@0: Transform::SummaryType summaryType = Chris@0: Transform::NoSummary); Chris@31: Chris@31: void testOutputFiles(QString audioSource); Chris@0: void finish(); Chris@0: Chris@0: int m_blockSize; Chris@0: int m_defaultSampleRate; Chris@0: int m_sampleRate; Chris@0: int m_channels; Chris@45: Chris@45: QMap m_readyReaders; Chris@0: Chris@0: void print(Transform transform) const; Chris@0: }; Chris@0: Chris@0: #endif