svcore
1.9
|
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 Sonic Visualiser 00005 An audio file viewer and annotation editor. 00006 Centre for Digital Music, Queen Mary, University of London. 00007 This file copyright 2006 Chris Cannam and QMUL. 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License as 00011 published by the Free Software Foundation; either version 2 of the 00012 License, or (at your option) any later version. See the file 00013 COPYING included with this distribution for more information. 00014 */ 00015 00016 #ifndef _FEATURE_EXTRACTION_MODEL_TRANSFORMER_H_ 00017 #define _FEATURE_EXTRACTION_MODEL_TRANSFORMER_H_ 00018 00019 #include "ModelTransformer.h" 00020 00021 #include <QString> 00022 00023 #include <vamp-hostsdk/Plugin.h> 00024 00025 #include <iostream> 00026 #include <map> 00027 00028 class DenseTimeValueModel; 00029 class SparseTimeValueModel; 00030 00031 class FeatureExtractionModelTransformer : public ModelTransformer 00032 { 00033 Q_OBJECT 00034 00035 public: 00036 FeatureExtractionModelTransformer(Input input, 00037 const Transform &transform); 00038 00039 // Obtain outputs for a set of transforms that all use the same 00040 // plugin and input (but with different outputs). i.e. run the 00041 // plugin once only and collect more than one output from it. 00042 FeatureExtractionModelTransformer(Input input, 00043 const Transforms &relatedTransforms); 00044 00045 virtual ~FeatureExtractionModelTransformer(); 00046 00047 // ModelTransformer method, retrieve the additional models 00048 Models getAdditionalOutputModels(); 00049 bool willHaveAdditionalOutputModels(); 00050 00051 protected: 00052 bool initialise(); 00053 00054 virtual void run(); 00055 00056 Vamp::Plugin *m_plugin; 00057 std::vector<Vamp::Plugin::OutputDescriptor *> m_descriptors; // per transform 00058 std::vector<int> m_fixedRateFeatureNos; // to assign times to FixedSampleRate features 00059 std::vector<int> m_outputNos; // list of plugin output indexes required for this group of transforms 00060 00061 void createOutputModels(int n); 00062 00063 std::map<int, bool> m_needAdditionalModels; // transformNo -> necessity 00064 typedef std::map<int, std::map<int, SparseTimeValueModel *> > AdditionalModelMap; 00065 AdditionalModelMap m_additionalModels; 00066 SparseTimeValueModel *getAdditionalModel(int transformNo, int binNo); 00067 00068 void addFeature(int n, 00069 int blockFrame, 00070 const Vamp::Plugin::Feature &feature); 00071 00072 void setCompletion(int, int); 00073 00074 void getFrames(int channelCount, long startFrame, long size, 00075 float **buffer); 00076 00077 // just casts 00078 00079 DenseTimeValueModel *getConformingInput(); 00080 00081 template <typename ModelClass> bool isOutput(int n) { 00082 return dynamic_cast<ModelClass *>(m_outputs[n]) != 0; 00083 } 00084 00085 template <typename ModelClass> ModelClass *getConformingOutput(int n) { 00086 if ((int)m_outputs.size() > n) { 00087 ModelClass *mc = dynamic_cast<ModelClass *>(m_outputs[n]); 00088 if (!mc) { 00089 std::cerr << "FeatureExtractionModelTransformer::getOutput: Output model not conformable" << std::endl; 00090 } 00091 return mc; 00092 } else { 00093 std::cerr << "FeatureExtractionModelTransformer::getOutput: No such output number " << n << std::endl; 00094 return 0; 00095 } 00096 } 00097 }; 00098 00099 #endif 00100