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