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@105
|
18 MatchPipeline::MatchPipeline(FeatureExtractor::Parameters feParams,
|
Chris@105
|
19 FeatureConditioner::Parameters fcParams,
|
Chris@105
|
20 Matcher::Parameters matchParams) :
|
Chris@105
|
21 m_fe1(feParams),
|
Chris@105
|
22 m_fe2(feParams),
|
Chris@105
|
23 m_fc1(fcParams),
|
Chris@105
|
24 m_fc2(fcParams),
|
Chris@105
|
25 m_pm1(matchParams, 0),
|
Chris@105
|
26 m_pm2(matchParams, &m_pm1),
|
Chris@105
|
27 m_feeder(&m_pm1, &m_pm2),
|
Chris@105
|
28 m_lastFrameIn1(0),
|
Chris@105
|
29 m_lastFrameIn2(0),
|
Chris@105
|
30 m_frameNo(0)
|
Chris@105
|
31 {
|
Chris@105
|
32 m_pm1.setOtherMatcher(&m_pm2);
|
Chris@105
|
33 }
|
Chris@105
|
34
|
Chris@105
|
35 MatchPipeline::~MatchPipeline()
|
Chris@105
|
36 {
|
Chris@105
|
37 }
|
Chris@105
|
38
|
Chris@105
|
39 void
|
Chris@105
|
40 MatchPipeline::feedFrequencyDomainAudio(const float *arr1, const float *arr2)
|
Chris@105
|
41 {
|
Chris@105
|
42 feedFeatures(m_fe1.process(arr1), m_fe2.process(arr2));
|
Chris@105
|
43 }
|
Chris@105
|
44
|
Chris@105
|
45 void
|
Chris@105
|
46 MatchPipeline::feedFeatures(const vector<double> &f1, const vector<double> &f2)
|
Chris@105
|
47 {
|
Chris@105
|
48 feedConditionedFeatures(m_fc1.process(f1), m_fc2.process(f2));
|
Chris@105
|
49 }
|
Chris@105
|
50
|
Chris@105
|
51 void
|
Chris@105
|
52 MatchPipeline::feedConditionedFeatures(const vector<double> &f1, const vector<double> &f2)
|
Chris@105
|
53 {
|
Chris@105
|
54 m_feeder.feed(f1, f2);
|
Chris@105
|
55
|
Chris@105
|
56 if (aboveThreshold(f1)) m_lastFrameIn1 = m_frameNo;
|
Chris@105
|
57 if (aboveThreshold(f2)) m_lastFrameIn2 = m_frameNo;
|
Chris@105
|
58
|
Chris@105
|
59 ++m_frameNo;
|
Chris@105
|
60 }
|
Chris@105
|
61
|
Chris@105
|
62 bool
|
Chris@105
|
63 MatchPipeline::aboveThreshold(const vector<double> &f)
|
Chris@105
|
64 {
|
Chris@105
|
65 double threshold = 1e-4f;
|
Chris@105
|
66 double sum = 0.f;
|
Chris@105
|
67 for (int i = 0; i < int(f.size()); ++i) {
|
Chris@105
|
68 sum += f[i] * f[i];
|
Chris@105
|
69 }
|
Chris@105
|
70 return (sum >= threshold);
|
Chris@105
|
71 }
|
Chris@105
|
72
|
Chris@105
|
73 void
|
Chris@105
|
74 MatchPipeline::finish()
|
Chris@105
|
75 {
|
Chris@105
|
76 m_feeder.finish();
|
Chris@105
|
77 getFinder()->setDurations(m_lastFrameIn1, m_lastFrameIn2);
|
Chris@105
|
78 }
|
Chris@105
|
79
|
Chris@105
|
80 Finder *
|
Chris@105
|
81 MatchPipeline::getFinder()
|
Chris@105
|
82 {
|
Chris@105
|
83 return m_feeder.getFinder();
|
Chris@105
|
84 }
|
Chris@105
|
85
|
Chris@105
|
86
|
Chris@105
|
87
|
Chris@105
|
88
|