annotate libmain.cpp @ 3:bc0cdab67251

* Update to support API versioning
author cannam
date Tue, 27 Feb 2007 12:49:39 +0000
parents d9b43f698a44
children 76e255118810
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@0 49 // Define this if libxtract has been compiled with XTRACT_FFT and
cannam@0 50 // linked with fftw3
cannam@0 51 #define HAVE_XTRACT_FFT 1
cannam@0 52
cannam@3 53 const VampPluginDescriptor *vampGetPluginDescriptor(unsigned int vampApiVersion,
cannam@3 54 unsigned int index)
cannam@0 55 {
cannam@3 56 if (vampApiVersion < 1) return 0;
cannam@3 57
cannam@0 58 // The missingFeatures array contains the libxtract enum values
cannam@0 59 // for features that we are not providing in this plugin, either
cannam@0 60 // because they aren't very meaningful in isolation or because the
cannam@0 61 // version of libxtract we're using doesn't support them yet.
cannam@0 62 //
cannam@0 63 // These must appear in this array in the same order as in the
cannam@0 64 // original enum in libxtract.h.
cannam@0 65
cannam@0 66 const unsigned int missingFeatures[] = {
cannam@0 67
cannam@1 68 XTRACT_SPECTRAL_MEAN, // Just a wrapper for XTRACT_SPECTRAL_CENTROID
cannam@1 69 XTRACT_POWER, // not implemented
cannam@1 70 XTRACT_HPS, // "this function doesn't work properly"
cannam@1 71 XTRACT_FLUX, // not implemented
cannam@1 72 XTRACT_ATTACK_TIME, // not implemented
cannam@1 73 XTRACT_DECAY_TIME, // not implemented
cannam@1 74 XTRACT_DELTA_FEATURE, // not implemented (and not meaningful?)
cannam@0 75
cannam@0 76 #ifndef HAVE_XTRACT_FFT
cannam@1 77 XTRACT_MAGNITUDE_SPECTRUM, // requires fftw
cannam@1 78 #endif
cannam@1 79 XTRACT_AUTOCORRELATION_FFT, // requires fftw -- also erroneous
cannam@1 80 #ifndef HAVE_XTRACT_FFT
cannam@1 81 XTRACT_MFCC, // requires fftw
cannam@1 82 XTRACT_DCT, // requires fftw
cannam@0 83 #endif
cannam@0 84 };
cannam@0 85
cannam@0 86 for (unsigned int i = 0;
cannam@0 87 i < sizeof(missingFeatures)/sizeof(missingFeatures[0]);
cannam@0 88 ++i) {
cannam@0 89 if (i > 0) assert(missingFeatures[i] > missingFeatures[i-1]);
cannam@0 90 if (index >= missingFeatures[i]) ++index;
cannam@0 91 }
cannam@0 92
cannam@0 93 if (index >= XTRACT_FEATURES) return 0;
cannam@0 94
cannam@0 95 if (pluginAdapterMap.find(index) == pluginAdapterMap.end()) {
cannam@0 96 pluginAdapterMap[index] = new XTractPluginAdapter(index);
cannam@0 97 }
cannam@0 98
cannam@0 99 return pluginAdapterMap[index]->getDescriptor();
cannam@0 100 }
cannam@0 101