annotate src/Finder.h @ 246:aac9ad4064ea subsequence tip

Fix incorrect handling of silent tail in the non-subsequence MATCH phase; some debug output changes
author Chris Cannam
date Fri, 24 Jul 2020 14:29:55 +0100
parents 39fe8728e1ca
children
rev   line source
cannam@0 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
cannam@0 2
cannam@0 3 /*
cannam@0 4 Vamp feature extraction plugin using the MATCH audio alignment
cannam@0 5 algorithm.
cannam@0 6
cannam@0 7 Centre for Digital Music, Queen Mary, University of London.
Chris@236 8 Copyright (c) 2007-2020 Simon Dixon, Chris Cannam, and Queen Mary
Chris@230 9 University of London, Copyright (c) 2014-2015 Tido GmbH.
Chris@230 10
cannam@0 11 This program is free software; you can redistribute it and/or
cannam@0 12 modify it under the terms of the GNU General Public License as
cannam@0 13 published by the Free Software Foundation; either version 2 of the
cannam@0 14 License, or (at your option) any later version. See the file
cannam@0 15 COPYING included with this distribution for more information.
cannam@0 16 */
cannam@0 17
cannam@0 18 #ifndef _FINDER_H_
cannam@0 19 #define _FINDER_H_
cannam@0 20
cannam@0 21 #include <vector>
cannam@0 22 #include <iostream>
cannam@0 23
cannam@0 24 #include "Matcher.h"
cannam@0 25
Chris@72 26 class Finder
Chris@72 27 {
cannam@0 28 public:
Chris@72 29 Finder(Matcher *pm);
cannam@0 30
Chris@167 31 // default copy ctor and operator= are fine
Chris@167 32
cannam@0 33 ~Finder();
cannam@0 34
Chris@154 35 void setMatcher(Matcher *pm);
Chris@154 36
Chris@60 37 /**
Chris@60 38 * Tell the finder that one or both files ends sooner than it
Chris@60 39 * thought, i.e. that some of the trailing features are silence or
Chris@60 40 * otherwise to be ignored. d1 and d2 are feature frame counts for
Chris@60 41 * matchers 1 and 2 respectively. If this is not called, the full
Chris@60 42 * duration of each input will be considered.
Chris@60 43 */
Chris@60 44 void setDurations(int d1, int d2);
Chris@147 45
Chris@147 46 /**
Chris@191 47 * Find the location and normalised path cost of the column with
Chris@191 48 * the cheapest path cost within the given row. If the row is out
Chris@191 49 * of range, return false and leave the bestCol and bestCost
Chris@191 50 * variables unchanged.
Chris@154 51 */
Chris@191 52 bool getBestRowCost(int row, int &bestCol, normpathcost_t &bestCost);
Chris@154 53
Chris@154 54 /**
Chris@191 55 * Find the location and normalised path cost of the row with the
Chris@191 56 * cheapest path cost within the given column. If the column is
Chris@191 57 * out of range, return false and leave the bestRow and bestCost
Chris@191 58 * variables unchanged.
Chris@154 59 */
Chris@191 60 bool getBestColCost(int col, int &bestRow, normpathcost_t &bestCost);
Chris@154 61
Chris@154 62 /**
Chris@191 63 * Find the location and normalised path cost of the cheapest path
Chris@191 64 * cost within the final row and column of the search area, given
Chris@191 65 * that the area extends as far as the point at (row, col). This
Chris@191 66 * is used by getExpandDirection and can also be used, for
Chris@191 67 * example, to determine the current best estimate alignment for a
Chris@191 68 * frame we have just reached.
Chris@147 69 */
Chris@147 70 void getBestEdgeCost(int row, int col,
Chris@147 71 int &bestRow, int &bestCol,
Chris@191 72 normpathcost_t &bestCost);
Chris@147 73
Chris@147 74 /**
Chris@147 75 * Calculate which direction to expand the search area in, given
Chris@171 76 * its current extents.
Chris@171 77 */
Chris@181 78 advance_t getExpandDirection();
Chris@171 79
Chris@171 80 /**
Chris@171 81 * Calculate which direction to expand the search area in, given
Chris@147 82 * that so far it extends as far as the point at (row, col).
Chris@147 83 */
Chris@181 84 advance_t getExpandDirection(int row, int col);
Chris@45 85
cannam@0 86 /** Calculates a rectangle of the path cost matrix so that the
cannam@0 87 * minimum cost path between the bottom left and top right
cannam@0 88 * corners can be computed. Caches previous values to avoid
cannam@0 89 * calling find() multiple times, and is several times faster as
cannam@0 90 * a result.
cannam@0 91 *
cannam@0 92 * @param r1 the bottom of the rectangle to be calculated
cannam@0 93 * @param c1 the left side of the rectangle to be calculated
cannam@0 94 * @param r2 the top of the rectangle to be calculated
cannam@0 95 * @param c2 the right side of the rectangle to be calculated
cannam@0 96 */
cannam@0 97 void recalculatePathCostMatrix(int r1, int c1, int r2, int c2);
cannam@0 98
Chris@30 99 /**
Chris@30 100 * Track back after all of the matchers have been fed in order to
Chris@30 101 * obtain the lowest cost path available. Path x and y coordinate
Chris@30 102 * pairs are returned in corresponding elements of pathx and
Chris@30 103 * pathy. Return value is the length of the returned path: only
Chris@30 104 * this many elements from pathx and pathy are valid (any
Chris@30 105 * subsequent ones may be spurious).
Chris@31 106 *
Chris@31 107 * @param smooth whether to smooth the path before returning it
Chris@30 108 */
Chris@31 109 int retrievePath(bool smooth, std::vector<int> &pathx, std::vector<int> &pathy);
Chris@72 110
Chris@163 111 /**
Chris@163 112 * Get the path cost for the overall path to the end of both
Chris@163 113 * sources.
Chris@163 114 */
Chris@182 115 pathcost_t getOverallCost();
Chris@163 116
Chris@72 117 protected:
Chris@82 118 #ifdef PERFORM_ERROR_CHECKS
Chris@81 119 struct ErrorPosition {
Chris@86 120 enum Type { NoError = 0, WrongCost, WrongAdvance, NoAdvance };
Chris@81 121 ErrorPosition() : type(NoError) { }
Chris@81 122 Type type;
Chris@81 123 int r;
Chris@81 124 int c;
Chris@182 125 pathcost_t prevCost;
Chris@182 126 distance_t distance;
Chris@182 127 pathcost_t costWas;
Chris@182 128 pathcost_t costShouldBe;
Chris@181 129 advance_t advanceWas;
Chris@181 130 advance_t advanceShouldBe;
Chris@81 131 };
Chris@81 132 ErrorPosition checkPathCostMatrix();
Chris@92 133 void checkAndReport();
Chris@82 134 #endif
Chris@167 135
Chris@147 136 Matcher *m_m; // I do not own this
Chris@147 137
Chris@72 138 int m_duration1;
Chris@72 139 int m_duration2;
Chris@147 140 };
cannam@0 141
cannam@0 142 #endif