annotate src/FeatureConditioner.h @ 116:eed5f9594268 refactors

Add OutputDerivative, for completeness, & make DistanceMetric cope with negative feature values
author Chris Cannam
date Fri, 05 Dec 2014 10:05:31 +0000
parents dc9cc3278636
children 96c2191a85cc 8e240bbea845
rev   line source
Chris@103 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@103 2
Chris@103 3 /*
Chris@103 4 Vamp feature extraction plugin using the MATCH audio alignment
Chris@103 5 algorithm.
Chris@103 6
Chris@103 7 Centre for Digital Music, Queen Mary, University of London.
Chris@103 8
Chris@103 9 This program is free software; you can redistribute it and/or
Chris@103 10 modify it under the terms of the GNU General Public License as
Chris@103 11 published by the Free Software Foundation; either version 2 of the
Chris@103 12 License, or (at your option) any later version. See the file
Chris@103 13 COPYING included with this distribution for more information.
Chris@103 14 */
Chris@103 15
Chris@103 16 #ifndef FEATURE_CONDITIONER_H
Chris@103 17 #define FEATURE_CONDITIONER_H
Chris@103 18
Chris@103 19 #include <vector>
Chris@103 20
Chris@103 21 /**
Chris@103 22 * Take a series of feature vectors and apply conditioning of some
Chris@103 23 * sort, such as normalisation or first-order derivative.
Chris@103 24 *
Chris@103 25 * Note that FeatureConditioner maintains internal frame-to-frame
Chris@103 26 * state: use one FeatureConditioner per audio source, and construct a
Chris@103 27 * new one for each new source.
Chris@103 28 */
Chris@103 29 class FeatureConditioner
Chris@103 30 {
Chris@103 31 public:
Chris@103 32 enum Normalisation {
Chris@103 33
Chris@103 34 /** Do not normalise */
Chris@103 35 NoNormalisation,
Chris@103 36
Chris@103 37 /** Normalise each feature vector to have a sum of 1 */
Chris@103 38 NormaliseToSum1,
Chris@103 39
Chris@103 40 /** Normalise each feature vector by the long-term average of
Chris@103 41 * the summed energy */
Chris@103 42 NormaliseToLTAverage,
Chris@103 43 };
Chris@103 44
Chris@103 45 enum OutputOrder {
Chris@103 46
Chris@103 47 /** Output the normalised features without further processing */
Chris@103 48 OutputFeatures,
Chris@103 49
Chris@103 50 /** Output the half-wave rectified difference between the
Chris@116 51 * previous and current features instead of the straight
Chris@116 52 * feature values. */
Chris@103 53 OutputRectifiedDerivative,
Chris@116 54
Chris@116 55 /** Output the difference between the previous and current
Chris@116 56 * features instead of the straight feature values. */
Chris@116 57 OutputDerivative,
Chris@103 58 };
Chris@103 59
Chris@103 60 struct Parameters {
Chris@103 61
Chris@103 62 Parameters() :
Chris@103 63 norm(NormaliseToSum1),
Chris@103 64 order(OutputRectifiedDerivative),
Chris@103 65 silenceThreshold(0.01),
Chris@103 66 decay(0.99)
Chris@103 67 {}
Chris@103 68
Chris@103 69 /** Feature normalisation. */
Chris@103 70 Normalisation norm;
Chris@103 71
Chris@103 72 /** Type of output to generate (plain feature, derivative etc). */
Chris@103 73 OutputOrder order;
Chris@103 74
Chris@103 75 /** Silence threshold. If non-zero, any feature whose total
Chris@103 76 * energy (simply the sum of feature values) is below that
Chris@103 77 * threshold will be rounded down to all zeros. */
Chris@103 78 double silenceThreshold;
Chris@103 79
Chris@103 80 /** Frame-to-frame decay factor in calculating long-term average */
Chris@103 81 double decay;
Chris@103 82 };
Chris@103 83
Chris@103 84 /**
Chris@114 85 * Construct a FeatureConditioner with the given parameters.
Chris@103 86 *
Chris@114 87 * Note that FeatureConditioner maintains internal frame-to-frame
Chris@114 88 * state: use one FeatureConditioner per audio source, and construct
Chris@103 89 * a new one for each new source.
Chris@103 90 */
Chris@103 91 FeatureConditioner(Parameters parameters) : m_params(parameters) { }
Chris@103 92
Chris@103 93 /**
Chris@103 94 * Process the given feature and return the conditioned feature.
Chris@103 95 */
Chris@103 96 std::vector<double> process(const std::vector<double> &feature);
Chris@103 97
Chris@103 98 protected:
Chris@103 99 Parameters m_params;
Chris@103 100
Chris@103 101 /** Long term average feature energy. */
Chris@103 102 double m_ltAverage;
Chris@103 103
Chris@103 104 /** The most recent feature, used for calculating the feature to
Chris@103 105 * feature difference. This is therefore not yet normalised. */
Chris@103 106 std::vector<double> m_prev;
Chris@103 107 };
Chris@103 108
Chris@103 109 #endif