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@236
|
8 Copyright (c) 2007-2020 Simon Dixon, Chris Cannam, and Queen Mary
|
Chris@230
|
9 University of London, Copyright (c) 2014-2015 Tido GmbH.
|
Chris@103
|
10
|
Chris@103
|
11 This program is free software; you can redistribute it and/or
|
Chris@103
|
12 modify it under the terms of the GNU General Public License as
|
Chris@103
|
13 published by the Free Software Foundation; either version 2 of the
|
Chris@103
|
14 License, or (at your option) any later version. See the file
|
Chris@103
|
15 COPYING included with this distribution for more information.
|
Chris@103
|
16 */
|
Chris@103
|
17
|
Chris@103
|
18 #ifndef FEATURE_CONDITIONER_H
|
Chris@103
|
19 #define FEATURE_CONDITIONER_H
|
Chris@103
|
20
|
Chris@187
|
21 #include "MatchTypes.h"
|
Chris@103
|
22
|
Chris@103
|
23 /**
|
Chris@103
|
24 * Take a series of feature vectors and apply conditioning of some
|
Chris@103
|
25 * sort, such as normalisation or first-order derivative.
|
Chris@103
|
26 *
|
Chris@103
|
27 * Note that FeatureConditioner maintains internal frame-to-frame
|
Chris@103
|
28 * state: use one FeatureConditioner per audio source, and construct a
|
Chris@103
|
29 * new one for each new source.
|
Chris@103
|
30 */
|
Chris@103
|
31 class FeatureConditioner
|
Chris@103
|
32 {
|
Chris@103
|
33 public:
|
Chris@103
|
34 enum Normalisation {
|
Chris@103
|
35
|
Chris@103
|
36 /** Do not normalise */
|
Chris@103
|
37 NoNormalisation,
|
Chris@103
|
38
|
Chris@103
|
39 /** Normalise each feature vector to have a sum of 1 */
|
Chris@103
|
40 NormaliseToSum1,
|
Chris@103
|
41
|
Chris@103
|
42 /** Normalise each feature vector by the long-term average of
|
Chris@103
|
43 * the summed energy */
|
Chris@103
|
44 NormaliseToLTAverage,
|
Chris@103
|
45 };
|
Chris@103
|
46
|
Chris@103
|
47 enum OutputOrder {
|
Chris@103
|
48
|
Chris@103
|
49 /** Output the normalised features without further processing */
|
Chris@103
|
50 OutputFeatures,
|
Chris@103
|
51
|
Chris@103
|
52 /** Output the half-wave rectified difference between the
|
Chris@116
|
53 * previous and current features instead of the straight
|
Chris@116
|
54 * feature values. */
|
Chris@103
|
55 OutputRectifiedDerivative,
|
Chris@116
|
56
|
Chris@130
|
57 /** Output the absolute difference between the previous and
|
Chris@130
|
58 * current features instead of the straight feature
|
Chris@130
|
59 * values. */
|
Chris@116
|
60 OutputDerivative,
|
Chris@103
|
61 };
|
Chris@103
|
62
|
Chris@103
|
63 struct Parameters {
|
Chris@103
|
64
|
Chris@103
|
65 Parameters() :
|
Chris@103
|
66 norm(NormaliseToSum1),
|
Chris@103
|
67 order(OutputRectifiedDerivative),
|
Chris@151
|
68 silenceThreshold(0.01),
|
Chris@103
|
69 decay(0.99)
|
Chris@103
|
70 {}
|
Chris@103
|
71
|
Chris@103
|
72 /** Feature normalisation. */
|
Chris@103
|
73 Normalisation norm;
|
Chris@103
|
74
|
Chris@103
|
75 /** Type of output to generate (plain feature, derivative etc). */
|
Chris@103
|
76 OutputOrder order;
|
Chris@103
|
77
|
Chris@103
|
78 /** Silence threshold. If non-zero, any feature whose total
|
Chris@103
|
79 * energy (simply the sum of feature values) is below that
|
Chris@130
|
80 * threshold will be rounded down to all zeros. Note that
|
Chris@134
|
81 * this refers to the energy of the pre-norm feature, not of
|
Chris@134
|
82 * its derivative even if that is what is being returned. */
|
Chris@103
|
83 double silenceThreshold;
|
Chris@103
|
84
|
Chris@103
|
85 /** Frame-to-frame decay factor in calculating long-term average */
|
Chris@103
|
86 double decay;
|
Chris@103
|
87 };
|
Chris@103
|
88
|
Chris@103
|
89 /**
|
Chris@114
|
90 * Construct a FeatureConditioner with the given parameters.
|
Chris@103
|
91 *
|
Chris@114
|
92 * Note that FeatureConditioner maintains internal frame-to-frame
|
Chris@114
|
93 * state: use one FeatureConditioner per audio source, and construct
|
Chris@103
|
94 * a new one for each new source.
|
Chris@103
|
95 */
|
Chris@140
|
96 FeatureConditioner(Parameters parameters);
|
Chris@103
|
97
|
Chris@103
|
98 /**
|
Chris@103
|
99 * Process the given feature and return the conditioned feature.
|
Chris@103
|
100 */
|
Chris@185
|
101 feature_t process(const feature_t &feature);
|
Chris@103
|
102
|
Chris@103
|
103 protected:
|
Chris@103
|
104 Parameters m_params;
|
Chris@103
|
105
|
Chris@103
|
106 /** Long term average feature energy. */
|
Chris@103
|
107 double m_ltAverage;
|
Chris@103
|
108
|
Chris@103
|
109 /** The most recent feature, used for calculating the feature to
|
Chris@103
|
110 * feature difference. This is therefore not yet normalised. */
|
Chris@185
|
111 feature_t m_prev;
|
Chris@103
|
112 };
|
Chris@103
|
113
|
Chris@103
|
114 #endif
|