cannam@0: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ cannam@0: cannam@0: /* cannam@0: Vamp feature extraction plugins using Jamie Bullock's cannam@0: libxtract audio feature extraction library. cannam@0: cannam@0: Centre for Digital Music, Queen Mary, University of London. cannam@0: This file copyright 2006 Queen Mary, University of London. cannam@0: cannam@0: This program is free software; you can redistribute it and/or cannam@0: modify it under the terms of the GNU General Public License as cannam@0: published by the Free Software Foundation; either version 2 of the cannam@0: License, or (at your option) any later version. See the file cannam@0: COPYING included with this distribution for more information. cannam@0: cannam@0: */ cannam@0: cannam@0: #include cannam@0: #include cannam@0: cannam@0: #include "plugins/XTractPlugin.h" cannam@0: cannam@0: #include cannam@0: cannam@0: #include cannam@0: #include cannam@0: cannam@0: class XTractPluginAdapter : public Vamp::PluginAdapterBase cannam@0: { cannam@0: public: cannam@0: XTractPluginAdapter(unsigned int feature) : cannam@0: PluginAdapterBase(), cannam@0: m_xtFeature(feature) cannam@0: { } cannam@0: cannam@0: virtual ~XTractPluginAdapter() { } cannam@0: cannam@0: protected: cannam@0: Vamp::Plugin *createPlugin(float inputSampleRate) { cannam@0: XTractPlugin *xtp = new XTractPlugin(m_xtFeature, inputSampleRate); cannam@0: return xtp; cannam@0: } cannam@0: cannam@0: unsigned int m_xtFeature; cannam@0: }; cannam@0: cannam@0: static std::map pluginAdapterMap; cannam@0: cannam@9: // Note: libxtract must have been compiled with XTRACT_FFT and cannam@0: // linked with fftw3 cannam@0: cannam@3: const VampPluginDescriptor *vampGetPluginDescriptor(unsigned int vampApiVersion, cannam@3: unsigned int index) cannam@0: { cannam@3: if (vampApiVersion < 1) return 0; cannam@3: cannam@0: // The missingFeatures array contains the libxtract enum values cannam@0: // for features that we are not providing in this plugin, either cannam@0: // because they aren't very meaningful in isolation or because the cannam@0: // version of libxtract we're using doesn't support them yet. cannam@0: // cannam@0: // These must appear in this array in the same order as in the cannam@0: // original enum in libxtract.h. cannam@0: cannam@0: const unsigned int missingFeatures[] = { cannam@0: cannam@1: XTRACT_SPECTRAL_MEAN, // Just a wrapper for XTRACT_SPECTRAL_CENTROID cannam@9: XTRACT_FLATNESS_DB, // appears to implement only the db part cannam@1: XTRACT_POWER, // not implemented cannam@1: XTRACT_HPS, // "this function doesn't work properly" cannam@9: XTRACT_LNORM, // not quite sure what it is or its parameters cannam@1: XTRACT_FLUX, // not implemented cannam@1: XTRACT_ATTACK_TIME, // not implemented cannam@1: XTRACT_DECAY_TIME, // not implemented cannam@9: XTRACT_DIFFERENCE_VECTOR, // not meaningful (this used to be XTRACT_DELTA_FEATURE) cannam@9: XTRACT_AUTOCORRELATION_FFT, // apparently erroneous cannam@9: XTRACT_LPC, // not meaningful and/or not implemented here cannam@9: XTRACT_LPCC, // not meaningful and/or not implemented here cannam@9: XTRACT_SUBBANDS, // not meaningful in isolation cannam@9: XTRACT_WINDOWED // not meaningful cannam@0: }; cannam@0: cannam@0: for (unsigned int i = 0; cannam@0: i < sizeof(missingFeatures)/sizeof(missingFeatures[0]); cannam@0: ++i) { cannam@0: if (i > 0) assert(missingFeatures[i] > missingFeatures[i-1]); cannam@0: if (index >= missingFeatures[i]) ++index; cannam@0: } cannam@0: cannam@0: if (index >= XTRACT_FEATURES) return 0; cannam@0: cannam@0: if (pluginAdapterMap.find(index) == pluginAdapterMap.end()) { cannam@0: pluginAdapterMap[index] = new XTractPluginAdapter(index); cannam@0: } cannam@0: cannam@0: return pluginAdapterMap[index]->getDescriptor(); cannam@0: } cannam@0: