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@105
|
22 Matcher::Parameters matchParams) :
|
Chris@105
|
23 m_fe1(feParams),
|
Chris@105
|
24 m_fe2(feParams),
|
Chris@105
|
25 m_fc1(fcParams),
|
Chris@105
|
26 m_fc2(fcParams),
|
Chris@105
|
27 m_pm1(matchParams, 0),
|
Chris@105
|
28 m_pm2(matchParams, &m_pm1),
|
Chris@105
|
29 m_feeder(&m_pm1, &m_pm2),
|
Chris@105
|
30 m_lastFrameIn1(0),
|
Chris@105
|
31 m_lastFrameIn2(0),
|
Chris@105
|
32 m_frameNo(0)
|
Chris@105
|
33 {
|
Chris@105
|
34 m_pm1.setOtherMatcher(&m_pm2);
|
Chris@105
|
35 }
|
Chris@105
|
36
|
Chris@105
|
37 MatchPipeline::~MatchPipeline()
|
Chris@105
|
38 {
|
Chris@105
|
39 }
|
Chris@105
|
40
|
Chris@105
|
41 void
|
Chris@105
|
42 MatchPipeline::feedFrequencyDomainAudio(const float *arr1, const float *arr2)
|
Chris@105
|
43 {
|
Chris@105
|
44 feedFeatures(m_fe1.process(arr1), m_fe2.process(arr2));
|
Chris@105
|
45 }
|
Chris@105
|
46
|
Chris@105
|
47 void
|
Chris@105
|
48 MatchPipeline::feedFeatures(const vector<double> &f1, const vector<double> &f2)
|
Chris@105
|
49 {
|
Chris@106
|
50 m_f1 = f1;
|
Chris@106
|
51 m_f2 = f2;
|
Chris@106
|
52
|
Chris@140
|
53 #ifdef DEBUG_MATCH_PIPELINE
|
Chris@140
|
54 if (m_lastFrameIn1 == 1) {
|
Chris@140
|
55 cerr << "features 1 -> ";
|
Chris@140
|
56 for (int i = 0; i < (int) m_f1.size(); ++i) {
|
Chris@140
|
57 cerr << m_f1[i] << " ";
|
Chris@140
|
58 }
|
Chris@140
|
59 cerr << endl;
|
Chris@140
|
60 }
|
Chris@140
|
61 #endif
|
Chris@140
|
62
|
Chris@105
|
63 feedConditionedFeatures(m_fc1.process(f1), m_fc2.process(f2));
|
Chris@105
|
64 }
|
Chris@105
|
65
|
Chris@105
|
66 void
|
Chris@106
|
67 MatchPipeline::feedConditionedFeatures(const vector<double> &c1, const vector<double> &c2)
|
Chris@105
|
68 {
|
Chris@106
|
69 m_c1 = c1;
|
Chris@106
|
70 m_c2 = c2;
|
Chris@140
|
71
|
Chris@140
|
72 #ifdef DEBUG_MATCH_PIPELINE
|
Chris@140
|
73 if (m_lastFrameIn1 == 1) {
|
Chris@140
|
74 cerr << "conditioned features 1 -> ";
|
Chris@140
|
75 for (int i = 0; i < (int) m_c1.size(); ++i) {
|
Chris@140
|
76 cerr << m_c1[i] << " ";
|
Chris@140
|
77 }
|
Chris@140
|
78 cerr << endl;
|
Chris@140
|
79 }
|
Chris@140
|
80 #endif
|
Chris@106
|
81
|
Chris@106
|
82 m_feeder.feed(c1, c2);
|
Chris@105
|
83
|
Chris@106
|
84 if (aboveThreshold(c1)) m_lastFrameIn1 = m_frameNo;
|
Chris@106
|
85 if (aboveThreshold(c2)) m_lastFrameIn2 = m_frameNo;
|
Chris@105
|
86
|
Chris@140
|
87 #ifdef DEBUG_MATCH_PIPELINE
|
Chris@140
|
88 cerr << "last frames are " << m_lastFrameIn1 << ", " << m_lastFrameIn2
|
Chris@140
|
89 << endl;
|
Chris@140
|
90 #endif
|
Chris@140
|
91
|
Chris@105
|
92 ++m_frameNo;
|
Chris@105
|
93 }
|
Chris@105
|
94
|
Chris@106
|
95 void
|
Chris@106
|
96 MatchPipeline::extractFeatures(vector<double> &f1, vector<double> &f2)
|
Chris@106
|
97 {
|
Chris@106
|
98 f1 = m_f1;
|
Chris@106
|
99 f2 = m_f2;
|
Chris@106
|
100 }
|
Chris@106
|
101
|
Chris@106
|
102 void
|
Chris@106
|
103 MatchPipeline::extractConditionedFeatures(vector<double> &c1, vector<double> &c2)
|
Chris@106
|
104 {
|
Chris@106
|
105 c1 = m_c1;
|
Chris@106
|
106 c2 = m_c2;
|
Chris@106
|
107 }
|
Chris@106
|
108
|
Chris@105
|
109 bool
|
Chris@105
|
110 MatchPipeline::aboveThreshold(const vector<double> &f)
|
Chris@105
|
111 {
|
Chris@140
|
112 // This threshold is used only to determine when either of the
|
Chris@140
|
113 // input streams has ended -- the last frame for a stream is
|
Chris@140
|
114 // considered to be the last one that was above the
|
Chris@140
|
115 // threshold. This is different from the silence threshold in
|
Chris@140
|
116 // FeatureConditioner.
|
Chris@105
|
117 double threshold = 1e-4f;
|
Chris@105
|
118 double sum = 0.f;
|
Chris@105
|
119 for (int i = 0; i < int(f.size()); ++i) {
|
Chris@105
|
120 sum += f[i] * f[i];
|
Chris@105
|
121 }
|
Chris@140
|
122 #ifdef DEBUG_MATCH_PIPELINE
|
Chris@140
|
123 cerr << "aboveThreshold: sum " << sum << ", threshold " << threshold
|
Chris@140
|
124 << ", returning " << (sum >= threshold) << endl;
|
Chris@140
|
125 #endif
|
Chris@105
|
126 return (sum >= threshold);
|
Chris@105
|
127 }
|
Chris@105
|
128
|
Chris@105
|
129 void
|
Chris@105
|
130 MatchPipeline::finish()
|
Chris@105
|
131 {
|
Chris@105
|
132 m_feeder.finish();
|
Chris@105
|
133 getFinder()->setDurations(m_lastFrameIn1, m_lastFrameIn2);
|
Chris@105
|
134 }
|
Chris@105
|
135
|
Chris@135
|
136 MatchFeatureFeeder *
|
Chris@135
|
137 MatchPipeline::getFeeder()
|
Chris@135
|
138 {
|
Chris@135
|
139 return &m_feeder;
|
Chris@135
|
140 }
|
Chris@135
|
141
|
Chris@105
|
142 Finder *
|
Chris@105
|
143 MatchPipeline::getFinder()
|
Chris@105
|
144 {
|
Chris@105
|
145 return m_feeder.getFinder();
|
Chris@105
|
146 }
|
Chris@105
|
147
|
Chris@105
|
148
|
Chris@105
|
149
|
Chris@105
|
150
|