Chris@105
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@105
|
2 /*
|
Chris@105
|
3 Vamp feature extraction plugin using the MATCH audio alignment
|
Chris@105
|
4 algorithm.
|
Chris@105
|
5
|
Chris@105
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@105
|
7 This file copyright 2007 Simon Dixon, Chris Cannam and QMUL.
|
Chris@105
|
8
|
Chris@105
|
9 This program is free software; you can redistribute it and/or
|
Chris@105
|
10 modify it under the terms of the GNU General Public License as
|
Chris@105
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@105
|
12 License, or (at your option) any later version. See the file
|
Chris@105
|
13 COPYING included with this distribution for more information.
|
Chris@105
|
14 */
|
Chris@105
|
15
|
Chris@105
|
16 #include "MatchPipeline.h"
|
Chris@105
|
17
|
Chris@140
|
18 //#define DEBUG_MATCH_PIPELINE 1
|
Chris@140
|
19
|
Chris@105
|
20 MatchPipeline::MatchPipeline(FeatureExtractor::Parameters feParams,
|
Chris@105
|
21 FeatureConditioner::Parameters fcParams,
|
Chris@143
|
22 DistanceMetric::Parameters dParams,
|
Chris@105
|
23 Matcher::Parameters matchParams) :
|
Chris@105
|
24 m_fe1(feParams),
|
Chris@105
|
25 m_fe2(feParams),
|
Chris@105
|
26 m_fc1(fcParams),
|
Chris@105
|
27 m_fc2(fcParams),
|
Chris@143
|
28 m_pm1(matchParams, dParams, 0),
|
Chris@143
|
29 m_pm2(matchParams, dParams, &m_pm1),
|
Chris@105
|
30 m_feeder(&m_pm1, &m_pm2),
|
Chris@105
|
31 m_lastFrameIn1(0),
|
Chris@105
|
32 m_lastFrameIn2(0),
|
Chris@105
|
33 m_frameNo(0)
|
Chris@105
|
34 {
|
Chris@105
|
35 m_pm1.setOtherMatcher(&m_pm2);
|
Chris@105
|
36 }
|
Chris@105
|
37
|
Chris@105
|
38 MatchPipeline::~MatchPipeline()
|
Chris@105
|
39 {
|
Chris@105
|
40 }
|
Chris@105
|
41
|
Chris@105
|
42 void
|
Chris@105
|
43 MatchPipeline::feedFrequencyDomainAudio(const float *arr1, const float *arr2)
|
Chris@105
|
44 {
|
Chris@105
|
45 feedFeatures(m_fe1.process(arr1), m_fe2.process(arr2));
|
Chris@105
|
46 }
|
Chris@105
|
47
|
Chris@105
|
48 void
|
Chris@105
|
49 MatchPipeline::feedFeatures(const vector<double> &f1, const vector<double> &f2)
|
Chris@105
|
50 {
|
Chris@106
|
51 m_f1 = f1;
|
Chris@106
|
52 m_f2 = f2;
|
Chris@106
|
53
|
Chris@140
|
54 #ifdef DEBUG_MATCH_PIPELINE
|
Chris@140
|
55 if (m_lastFrameIn1 == 1) {
|
Chris@140
|
56 cerr << "features 1 -> ";
|
Chris@140
|
57 for (int i = 0; i < (int) m_f1.size(); ++i) {
|
Chris@140
|
58 cerr << m_f1[i] << " ";
|
Chris@140
|
59 }
|
Chris@140
|
60 cerr << endl;
|
Chris@140
|
61 }
|
Chris@140
|
62 #endif
|
Chris@140
|
63
|
Chris@105
|
64 feedConditionedFeatures(m_fc1.process(f1), m_fc2.process(f2));
|
Chris@105
|
65 }
|
Chris@105
|
66
|
Chris@105
|
67 void
|
Chris@106
|
68 MatchPipeline::feedConditionedFeatures(const vector<double> &c1, const vector<double> &c2)
|
Chris@105
|
69 {
|
Chris@106
|
70 m_c1 = c1;
|
Chris@106
|
71 m_c2 = c2;
|
Chris@140
|
72
|
Chris@140
|
73 #ifdef DEBUG_MATCH_PIPELINE
|
Chris@140
|
74 if (m_lastFrameIn1 == 1) {
|
Chris@140
|
75 cerr << "conditioned features 1 -> ";
|
Chris@140
|
76 for (int i = 0; i < (int) m_c1.size(); ++i) {
|
Chris@140
|
77 cerr << m_c1[i] << " ";
|
Chris@140
|
78 }
|
Chris@140
|
79 cerr << endl;
|
Chris@140
|
80 }
|
Chris@140
|
81 #endif
|
Chris@106
|
82
|
Chris@106
|
83 m_feeder.feed(c1, c2);
|
Chris@105
|
84
|
Chris@106
|
85 if (aboveThreshold(c1)) m_lastFrameIn1 = m_frameNo;
|
Chris@106
|
86 if (aboveThreshold(c2)) m_lastFrameIn2 = m_frameNo;
|
Chris@105
|
87
|
Chris@140
|
88 #ifdef DEBUG_MATCH_PIPELINE
|
Chris@140
|
89 cerr << "last frames are " << m_lastFrameIn1 << ", " << m_lastFrameIn2
|
Chris@140
|
90 << endl;
|
Chris@140
|
91 #endif
|
Chris@140
|
92
|
Chris@105
|
93 ++m_frameNo;
|
Chris@105
|
94 }
|
Chris@105
|
95
|
Chris@106
|
96 void
|
Chris@106
|
97 MatchPipeline::extractFeatures(vector<double> &f1, vector<double> &f2)
|
Chris@106
|
98 {
|
Chris@106
|
99 f1 = m_f1;
|
Chris@106
|
100 f2 = m_f2;
|
Chris@106
|
101 }
|
Chris@106
|
102
|
Chris@106
|
103 void
|
Chris@106
|
104 MatchPipeline::extractConditionedFeatures(vector<double> &c1, vector<double> &c2)
|
Chris@106
|
105 {
|
Chris@106
|
106 c1 = m_c1;
|
Chris@106
|
107 c2 = m_c2;
|
Chris@106
|
108 }
|
Chris@106
|
109
|
Chris@105
|
110 bool
|
Chris@105
|
111 MatchPipeline::aboveThreshold(const vector<double> &f)
|
Chris@105
|
112 {
|
Chris@140
|
113 // This threshold is used only to determine when either of the
|
Chris@140
|
114 // input streams has ended -- the last frame for a stream is
|
Chris@140
|
115 // considered to be the last one that was above the
|
Chris@140
|
116 // threshold. This is different from the silence threshold in
|
Chris@140
|
117 // FeatureConditioner.
|
Chris@105
|
118 double threshold = 1e-4f;
|
Chris@105
|
119 double sum = 0.f;
|
Chris@105
|
120 for (int i = 0; i < int(f.size()); ++i) {
|
Chris@105
|
121 sum += f[i] * f[i];
|
Chris@105
|
122 }
|
Chris@140
|
123 #ifdef DEBUG_MATCH_PIPELINE
|
Chris@140
|
124 cerr << "aboveThreshold: sum " << sum << ", threshold " << threshold
|
Chris@140
|
125 << ", returning " << (sum >= threshold) << endl;
|
Chris@140
|
126 #endif
|
Chris@105
|
127 return (sum >= threshold);
|
Chris@105
|
128 }
|
Chris@105
|
129
|
Chris@105
|
130 void
|
Chris@105
|
131 MatchPipeline::finish()
|
Chris@105
|
132 {
|
Chris@105
|
133 m_feeder.finish();
|
Chris@105
|
134 getFinder()->setDurations(m_lastFrameIn1, m_lastFrameIn2);
|
Chris@105
|
135 }
|
Chris@105
|
136
|
Chris@135
|
137 MatchFeatureFeeder *
|
Chris@135
|
138 MatchPipeline::getFeeder()
|
Chris@135
|
139 {
|
Chris@135
|
140 return &m_feeder;
|
Chris@135
|
141 }
|
Chris@135
|
142
|
Chris@105
|
143 Finder *
|
Chris@105
|
144 MatchPipeline::getFinder()
|
Chris@105
|
145 {
|
Chris@105
|
146 return m_feeder.getFinder();
|
Chris@105
|
147 }
|
Chris@105
|
148
|
Chris@105
|
149
|
Chris@105
|
150
|
Chris@105
|
151
|