annotate libmain.cpp @ 40:08d9660e57e8 tip

Or better, this
author Chris Cannam
date Thu, 16 May 2024 10:17:33 +0100
parents 76e255118810
children
rev   line source
cannam@0 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
cannam@0 2
cannam@0 3 /*
cannam@0 4 Vamp feature extraction plugins using Jamie Bullock's
cannam@0 5 libxtract audio feature extraction library.
cannam@0 6
cannam@0 7 Centre for Digital Music, Queen Mary, University of London.
cannam@0 8 This file copyright 2006 Queen Mary, University of London.
cannam@0 9
cannam@0 10 This program is free software; you can redistribute it and/or
cannam@0 11 modify it under the terms of the GNU General Public License as
cannam@0 12 published by the Free Software Foundation; either version 2 of the
cannam@0 13 License, or (at your option) any later version. See the file
cannam@0 14 COPYING included with this distribution for more information.
cannam@0 15
cannam@0 16 */
cannam@0 17
cannam@0 18 #include <vamp/vamp.h>
cannam@0 19 #include <vamp-sdk/PluginAdapter.h>
cannam@0 20
cannam@0 21 #include "plugins/XTractPlugin.h"
cannam@0 22
cannam@0 23 #include <xtract/libxtract.h>
cannam@0 24
cannam@0 25 #include <map>
cannam@0 26 #include <cassert>
cannam@0 27
cannam@0 28 class XTractPluginAdapter : public Vamp::PluginAdapterBase
cannam@0 29 {
cannam@0 30 public:
cannam@0 31 XTractPluginAdapter(unsigned int feature) :
cannam@0 32 PluginAdapterBase(),
cannam@0 33 m_xtFeature(feature)
cannam@0 34 { }
cannam@0 35
cannam@0 36 virtual ~XTractPluginAdapter() { }
cannam@0 37
cannam@0 38 protected:
cannam@0 39 Vamp::Plugin *createPlugin(float inputSampleRate) {
cannam@0 40 XTractPlugin *xtp = new XTractPlugin(m_xtFeature, inputSampleRate);
cannam@0 41 return xtp;
cannam@0 42 }
cannam@0 43
cannam@0 44 unsigned int m_xtFeature;
cannam@0 45 };
cannam@0 46
cannam@0 47 static std::map<unsigned int, XTractPluginAdapter *> pluginAdapterMap;
cannam@0 48
cannam@9 49 // Note: libxtract must have been compiled with XTRACT_FFT and
cannam@0 50 // linked with fftw3
cannam@0 51
cannam@3 52 const VampPluginDescriptor *vampGetPluginDescriptor(unsigned int vampApiVersion,
cannam@3 53 unsigned int index)
cannam@0 54 {
cannam@3 55 if (vampApiVersion < 1) return 0;
cannam@3 56
cannam@0 57 // The missingFeatures array contains the libxtract enum values
cannam@0 58 // for features that we are not providing in this plugin, either
cannam@0 59 // because they aren't very meaningful in isolation or because the
cannam@0 60 // version of libxtract we're using doesn't support them yet.
cannam@0 61 //
cannam@0 62 // These must appear in this array in the same order as in the
cannam@0 63 // original enum in libxtract.h.
cannam@0 64
cannam@0 65 const unsigned int missingFeatures[] = {
cannam@0 66
cannam@1 67 XTRACT_SPECTRAL_MEAN, // Just a wrapper for XTRACT_SPECTRAL_CENTROID
cannam@9 68 XTRACT_FLATNESS_DB, // appears to implement only the db part
cannam@1 69 XTRACT_POWER, // not implemented
cannam@1 70 XTRACT_HPS, // "this function doesn't work properly"
cannam@9 71 XTRACT_LNORM, // not quite sure what it is or its parameters
cannam@1 72 XTRACT_FLUX, // not implemented
cannam@1 73 XTRACT_ATTACK_TIME, // not implemented
cannam@1 74 XTRACT_DECAY_TIME, // not implemented
cannam@9 75 XTRACT_DIFFERENCE_VECTOR, // not meaningful (this used to be XTRACT_DELTA_FEATURE)
cannam@9 76 XTRACT_AUTOCORRELATION_FFT, // apparently erroneous
cannam@9 77 XTRACT_LPC, // not meaningful and/or not implemented here
cannam@9 78 XTRACT_LPCC, // not meaningful and/or not implemented here
cannam@9 79 XTRACT_SUBBANDS, // not meaningful in isolation
cannam@9 80 XTRACT_WINDOWED // not meaningful
cannam@0 81 };
cannam@0 82
cannam@0 83 for (unsigned int i = 0;
cannam@0 84 i < sizeof(missingFeatures)/sizeof(missingFeatures[0]);
cannam@0 85 ++i) {
cannam@0 86 if (i > 0) assert(missingFeatures[i] > missingFeatures[i-1]);
cannam@0 87 if (index >= missingFeatures[i]) ++index;
cannam@0 88 }
cannam@0 89
cannam@0 90 if (index >= XTRACT_FEATURES) return 0;
cannam@0 91
cannam@0 92 if (pluginAdapterMap.find(index) == pluginAdapterMap.end()) {
cannam@0 93 pluginAdapterMap[index] = new XTractPluginAdapter(index);
cannam@0 94 }
cannam@0 95
cannam@0 96 return pluginAdapterMap[index]->getDescriptor();
cannam@0 97 }
cannam@0 98