annotate src/MatchPipeline.cpp @ 183:24ddab06aace re-minimise

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