Mercurial > hg > match-vamp
comparison src/FeatureConditioner.cpp @ 103:593054bf6476 feature_conditioner
Pull out normalisation and specdiff stuff into FeatureConditioner
author | Chris Cannam |
---|---|
date | Thu, 04 Dec 2014 13:05:16 +0000 |
parents | |
children | eed5f9594268 |
comparison
equal
deleted
inserted
replaced
96:6b91e40b2c04 | 103:593054bf6476 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Vamp feature extraction plugin using the MATCH audio alignment | |
5 algorithm. | |
6 | |
7 Centre for Digital Music, Queen Mary, University of London. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #include "FeatureConditioner.h" | |
17 | |
18 #include <iostream> | |
19 | |
20 using namespace std; | |
21 | |
22 vector<double> | |
23 FeatureConditioner::process(const vector<double> &feature) | |
24 { | |
25 if (m_prev.empty()) { | |
26 m_prev.resize(feature.size(), 0.0); | |
27 } | |
28 if (m_prev.size() != feature.size()) { | |
29 cerr << "ERROR: FeatureConditioner::process: feature size " | |
30 << feature.size() << " differs from previous feature size " | |
31 << m_prev.size() << endl; | |
32 return feature; | |
33 } | |
34 | |
35 int size = feature.size(); | |
36 | |
37 vector<double> out(size, 0.0); | |
38 | |
39 double totalEnergy = 0; | |
40 if (m_params.order == OutputRectifiedDerivative) { | |
41 for (int i = 0; i < size; i++) { | |
42 totalEnergy += feature[i]; | |
43 if (feature[i] > m_prev[i]) { | |
44 out[i] = feature[i] - m_prev[i]; | |
45 } else { | |
46 out[i] = 0; | |
47 } | |
48 } | |
49 } else { | |
50 for (int i = 0; i < size; i++) { | |
51 out[i] = feature[i]; | |
52 totalEnergy += out[i]; | |
53 } | |
54 } | |
55 | |
56 if (m_ltAverage == 0) { | |
57 m_ltAverage = totalEnergy; | |
58 } else { | |
59 double decay = m_params.decay; | |
60 m_ltAverage = m_ltAverage * decay + totalEnergy * (1.0 - decay); | |
61 } | |
62 | |
63 if (totalEnergy <= m_params.silenceThreshold) { | |
64 for (int i = 0; i < size; i++) { | |
65 out[i] = 0; | |
66 } | |
67 } else if (m_params.norm == NormaliseToSum1) { | |
68 for (int i = 0; i < size; i++) { | |
69 out[i] /= totalEnergy; | |
70 } | |
71 } else if (m_params.norm == NormaliseToLTAverage) { | |
72 for (int i = 0; i < size; i++) { | |
73 out[i] /= m_ltAverage; | |
74 } | |
75 } | |
76 | |
77 m_prev = feature; | |
78 return out; | |
79 } | |
80 |