1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
6 * Copyright 2008 Centre for Digital Music, Queen Mary, University of London.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version. See the file
12 COPYING included with this distribution for more information.
15 #ifndef _SIMILARITY_PLUGIN_H_
16 #define _SIMILARITY_PLUGIN_H_
18 #include <vamp-sdk/Plugin.h>
19 #include <vamp-sdk/RealTime.h>
28 class SimilarityPlugin : public Vamp::Plugin
31 SimilarityPlugin(float inputSampleRate);
32 virtual ~SimilarityPlugin();
34 bool initialise(size_t channels, size_t stepSize, size_t blockSize);
37 std::string getIdentifier() const;
38 std::string getName() const;
39 std::string getDescription() const;
40 std::string getMaker() const;
41 int getPluginVersion() const;
42 std::string getCopyright() const;
44 size_t getPreferredStepSize() const;
45 size_t getPreferredBlockSize() const;
46 InputDomain getInputDomain() const { return TimeDomain; }
48 size_t getMinChannelCount() const;
49 size_t getMaxChannelCount() const;
51 SimilarityPlugin::ParameterList getParameterDescriptors() const;
52 float getParameter(std::string param) const;
53 void setParameter(std::string param, float value);
55 OutputList getOutputDescriptors() const;
57 FeatureSet process(const float *const *inputBuffers, Vamp::RealTime timestamp);
59 FeatureSet getRemainingFeatures();
62 int getDecimationFactor() const;
69 void calculateBlockSize() const;
70 bool needRhythm() const { return m_rhythmWeighting > m_noRhythm; }
71 bool needTimbre() const { return m_rhythmWeighting < m_allRhythm; }
76 Chromagram *m_chromagram;
77 Decimator *m_decimator;
78 int m_featureColumnSize;
79 float m_rhythmWeighting;
80 float m_rhythmClipDuration;
81 float m_rhythmClipOrigin;
82 int m_rhythmClipFrameSize;
83 int m_rhythmClipFrames;
84 int m_rhythmColumnSize;
85 mutable int m_blockSize; // before decimation
86 int m_fftSize; // after decimation
92 static const float m_noRhythm;
93 static const float m_allRhythm;
95 std::vector<int> m_lastNonEmptyFrame; // per channel
96 std::vector<int> m_emptyFrameCount; // per channel
98 mutable int m_distanceMatrixOutput;
99 mutable int m_distanceVectorOutput;
100 mutable int m_sortedVectorOutput;
101 mutable int m_meansOutput;
102 mutable int m_variancesOutput;
103 mutable int m_beatSpectraOutput;
105 typedef std::vector<double> FeatureColumn;
106 typedef std::vector<FeatureColumn> FeatureMatrix;
107 typedef std::vector<FeatureMatrix> FeatureMatrixSet;
109 typedef std::deque<FeatureColumn> FeatureColumnQueue;
110 typedef std::vector<FeatureColumnQueue> FeatureQueueSet;
112 FeatureMatrixSet m_values;
113 FeatureQueueSet m_rhythmValues;
115 FeatureMatrix calculateTimbral(FeatureSet &returnFeatures);
116 FeatureMatrix calculateRhythmic(FeatureSet &returnFeatures);
117 double getDistance(const FeatureMatrix &timbral,
118 const FeatureMatrix &rhythmic,