annotate transform/FeatureExtractionModelTransformer.h @ 1588:0773b34d987f bqaudiostream

We should now be able to get these from Ogg files, though this might not be working yet...
author Chris Cannam
date Thu, 17 Jan 2019 15:08:38 +0000
parents 48e9f538e6e9
children c01cbe41aeb5
rev   line source
Chris@320 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@320 2
Chris@320 3 /*
Chris@320 4 Sonic Visualiser
Chris@320 5 An audio file viewer and annotation editor.
Chris@320 6 Centre for Digital Music, Queen Mary, University of London.
Chris@320 7 This file copyright 2006 Chris Cannam and QMUL.
Chris@320 8
Chris@320 9 This program is free software; you can redistribute it and/or
Chris@320 10 modify it under the terms of the GNU General Public License as
Chris@320 11 published by the Free Software Foundation; either version 2 of the
Chris@320 12 License, or (at your option) any later version. See the file
Chris@320 13 COPYING included with this distribution for more information.
Chris@320 14 */
Chris@320 15
Chris@849 16 #ifndef _FEATURE_EXTRACTION_MODEL_TRANSFORMER_H_
Chris@849 17 #define _FEATURE_EXTRACTION_MODEL_TRANSFORMER_H_
Chris@320 18
Chris@350 19 #include "ModelTransformer.h"
Chris@350 20
Chris@361 21 #include <QString>
Chris@1211 22 #include <QMutex>
Chris@1211 23 #include <QWaitCondition>
Chris@361 24
Chris@475 25 #include <vamp-hostsdk/Plugin.h>
Chris@350 26
Chris@350 27 #include <iostream>
Chris@876 28 #include <map>
Chris@320 29
Chris@320 30 class DenseTimeValueModel;
Chris@876 31 class SparseTimeValueModel;
Chris@320 32
Chris@1236 33 class FeatureExtractionModelTransformer : public ModelTransformer // + is a Thread
Chris@320 34 {
Chris@320 35 Q_OBJECT
Chris@320 36
Chris@320 37 public:
Chris@350 38 FeatureExtractionModelTransformer(Input input,
Chris@859 39 const Transform &transform);
Chris@848 40
Chris@848 41 // Obtain outputs for a set of transforms that all use the same
Chris@848 42 // plugin and input (but with different outputs). i.e. run the
Chris@848 43 // plugin once only and collect more than one output from it.
Chris@848 44 FeatureExtractionModelTransformer(Input input,
Chris@859 45 const Transforms &relatedTransforms);
gyorgyf@786 46
Chris@331 47 virtual ~FeatureExtractionModelTransformer();
Chris@320 48
Chris@877 49 // ModelTransformer method, retrieve the additional models
Chris@877 50 Models getAdditionalOutputModels();
Chris@877 51 bool willHaveAdditionalOutputModels();
Chris@877 52
Chris@320 53 protected:
Chris@849 54 bool initialise();
Chris@1237 55 void deinitialise();
Chris@849 56
Chris@320 57 virtual void run();
Chris@320 58
Chris@320 59 Vamp::Plugin *m_plugin;
Chris@849 60 std::vector<Vamp::Plugin::OutputDescriptor *> m_descriptors; // per transform
Chris@849 61 std::vector<int> m_fixedRateFeatureNos; // to assign times to FixedSampleRate features
Chris@876 62 std::vector<int> m_outputNos; // list of plugin output indexes required for this group of transforms
Chris@320 63
Chris@876 64 void createOutputModels(int n);
Chris@876 65
Chris@876 66 std::map<int, bool> m_needAdditionalModels; // transformNo -> necessity
Chris@876 67 typedef std::map<int, std::map<int, SparseTimeValueModel *> > AdditionalModelMap;
Chris@876 68 AdditionalModelMap m_additionalModels;
Chris@876 69 SparseTimeValueModel *getAdditionalModel(int transformNo, int binNo);
Chris@876 70
Chris@850 71 void addFeature(int n,
Chris@1039 72 sv_frame_t blockFrame,
Chris@1429 73 const Vamp::Plugin::Feature &feature);
Chris@320 74
Chris@850 75 void setCompletion(int, int);
Chris@320 76
Chris@1039 77 void getFrames(int channelCount, sv_frame_t startFrame, sv_frame_t size,
Chris@363 78 float **buffer);
Chris@320 79
Chris@1211 80 bool m_haveOutputs;
Chris@1211 81 QMutex m_outputMutex;
Chris@1211 82 QWaitCondition m_outputsCondition;
Chris@1211 83 void awaitOutputModels();
Chris@1211 84
Chris@1211 85 // just casts:
Chris@441 86
Chris@350 87 DenseTimeValueModel *getConformingInput();
Chris@441 88
Chris@849 89 template <typename ModelClass> bool isOutput(int n) {
Chris@849 90 return dynamic_cast<ModelClass *>(m_outputs[n]) != 0;
Chris@441 91 }
Chris@441 92
Chris@849 93 template <typename ModelClass> ModelClass *getConformingOutput(int n) {
Chris@849 94 if ((int)m_outputs.size() > n) {
Chris@849 95 ModelClass *mc = dynamic_cast<ModelClass *>(m_outputs[n]);
Chris@849 96 if (!mc) {
Chris@849 97 std::cerr << "FeatureExtractionModelTransformer::getOutput: Output model not conformable" << std::endl;
Chris@849 98 }
Chris@849 99 return mc;
Chris@849 100 } else {
Chris@849 101 std::cerr << "FeatureExtractionModelTransformer::getOutput: No such output number " << n << std::endl;
Chris@849 102 return 0;
Chris@849 103 }
Chris@320 104 }
Chris@320 105 };
Chris@320 106
Chris@320 107 #endif
Chris@320 108