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@103
|
51 * previous and current features instead of the straight
|
Chris@103
|
52 * feature values. */
|
Chris@103
|
53 OutputRectifiedDerivative,
|
Chris@103
|
54 };
|
Chris@103
|
55
|
Chris@103
|
56 struct Parameters {
|
Chris@103
|
57
|
Chris@103
|
58 Parameters() :
|
Chris@103
|
59 norm(NormaliseToSum1),
|
Chris@103
|
60 order(OutputRectifiedDerivative),
|
Chris@103
|
61 silenceThreshold(0.01),
|
Chris@103
|
62 decay(0.99)
|
Chris@103
|
63 {}
|
Chris@103
|
64
|
Chris@103
|
65 /** Feature normalisation. */
|
Chris@103
|
66 Normalisation norm;
|
Chris@103
|
67
|
Chris@103
|
68 /** Type of output to generate (plain feature, derivative etc). */
|
Chris@103
|
69 OutputOrder order;
|
Chris@103
|
70
|
Chris@103
|
71 /** Silence threshold. If non-zero, any feature whose total
|
Chris@103
|
72 * energy (simply the sum of feature values) is below that
|
Chris@103
|
73 * threshold will be rounded down to all zeros. */
|
Chris@103
|
74 double silenceThreshold;
|
Chris@103
|
75
|
Chris@103
|
76 /** Frame-to-frame decay factor in calculating long-term average */
|
Chris@103
|
77 double decay;
|
Chris@103
|
78 };
|
Chris@103
|
79
|
Chris@103
|
80 /**
|
Chris@103
|
81 * Construct a FeatureExtractor with the given parameters.
|
Chris@103
|
82 *
|
Chris@103
|
83 * Note that FeatureExtractor maintains internal frame-to-frame
|
Chris@103
|
84 * state: use one FeatureExtractor per audio source, and construct
|
Chris@103
|
85 * a new one for each new source.
|
Chris@103
|
86 */
|
Chris@103
|
87 FeatureConditioner(Parameters parameters) : m_params(parameters) { }
|
Chris@103
|
88
|
Chris@103
|
89 /**
|
Chris@103
|
90 * Process the given feature and return the conditioned feature.
|
Chris@103
|
91 */
|
Chris@103
|
92 std::vector<double> process(const std::vector<double> &feature);
|
Chris@103
|
93
|
Chris@103
|
94 protected:
|
Chris@103
|
95 Parameters m_params;
|
Chris@103
|
96
|
Chris@103
|
97 /** Long term average feature energy. */
|
Chris@103
|
98 double m_ltAverage;
|
Chris@103
|
99
|
Chris@103
|
100 /** The most recent feature, used for calculating the feature to
|
Chris@103
|
101 * feature difference. This is therefore not yet normalised. */
|
Chris@103
|
102 std::vector<double> m_prev;
|
Chris@103
|
103 };
|
Chris@103
|
104
|
Chris@103
|
105 #endif
|