annotate src/Finder.h @ 163:cf1282d1f940 refactors

Add overall cost output to plugin. Looks suspiciously unaffected by tuning frequency.
author Chris Cannam
date Thu, 29 Jan 2015 17:38:09 +0000
parents c665173b3a33
children eeed3498fe96
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.
cannam@0 8 This file copyright 2007 Simon Dixon, Chris Cannam and QMUL.
cannam@0 9
cannam@0 10 This program is free software; you can redistribute it and/or
cannam@0 11 modify it under the terms of the GNU General Public License as
cannam@0 12 published by the Free Software Foundation; either version 2 of the
cannam@0 13 License, or (at your option) any later version. See the file
cannam@0 14 COPYING included with this distribution for more information.
cannam@0 15 */
cannam@0 16
cannam@0 17 #ifndef _FINDER_H_
cannam@0 18 #define _FINDER_H_
cannam@0 19
cannam@0 20 #include <vector>
cannam@0 21 #include <iostream>
cannam@0 22
cannam@0 23 #include "Matcher.h"
cannam@0 24
Chris@72 25 class Finder
Chris@72 26 {
cannam@0 27 public:
Chris@72 28 Finder(Matcher *pm);
cannam@0 29
cannam@0 30 ~Finder();
cannam@0 31
Chris@60 32 /**
Chris@60 33 * Tell the finder that one or both files ends sooner than it
Chris@60 34 * thought, i.e. that some of the trailing features are silence or
Chris@60 35 * otherwise to be ignored. d1 and d2 are feature frame counts for
Chris@60 36 * matchers 1 and 2 respectively. If this is not called, the full
Chris@60 37 * duration of each input will be considered.
Chris@60 38 */
Chris@60 39 void setDurations(int d1, int d2);
Chris@60 40
Chris@45 41 Matcher::Advance getExpandDirection(int row, int col);
Chris@45 42
cannam@0 43 /** Calculates a rectangle of the path cost matrix so that the
cannam@0 44 * minimum cost path between the bottom left and top right
cannam@0 45 * corners can be computed. Caches previous values to avoid
cannam@0 46 * calling find() multiple times, and is several times faster as
cannam@0 47 * a result.
cannam@0 48 *
cannam@0 49 * @param r1 the bottom of the rectangle to be calculated
cannam@0 50 * @param c1 the left side of the rectangle to be calculated
cannam@0 51 * @param r2 the top of the rectangle to be calculated
cannam@0 52 * @param c2 the right side of the rectangle to be calculated
cannam@0 53 */
cannam@0 54 void recalculatePathCostMatrix(int r1, int c1, int r2, int c2);
cannam@0 55
Chris@30 56 /**
Chris@30 57 * Track back after all of the matchers have been fed in order to
Chris@30 58 * obtain the lowest cost path available. Path x and y coordinate
Chris@30 59 * pairs are returned in corresponding elements of pathx and
Chris@30 60 * pathy. Return value is the length of the returned path: only
Chris@30 61 * this many elements from pathx and pathy are valid (any
Chris@30 62 * subsequent ones may be spurious).
Chris@31 63 *
Chris@31 64 * @param smooth whether to smooth the path before returning it
Chris@30 65 */
Chris@31 66 int retrievePath(bool smooth, std::vector<int> &pathx, std::vector<int> &pathy);
Chris@72 67
Chris@163 68 /**
Chris@163 69 * Get the path cost for the overall path to the end of both
Chris@163 70 * sources.
Chris@163 71 */
Chris@163 72 double getOverallCost();
Chris@163 73
Chris@72 74 protected:
Chris@82 75 #ifdef PERFORM_ERROR_CHECKS
Chris@81 76 struct ErrorPosition {
Chris@86 77 enum Type { NoError = 0, WrongCost, WrongAdvance, NoAdvance };
Chris@81 78 ErrorPosition() : type(NoError) { }
Chris@81 79 Type type;
Chris@81 80 int r;
Chris@81 81 int c;
Chris@81 82 double prevCost;
Chris@81 83 float distance;
Chris@81 84 double costWas;
Chris@81 85 double costShouldBe;
Chris@84 86 Matcher::Advance advanceWas;
Chris@84 87 Matcher::Advance advanceShouldBe;
Chris@81 88 };
Chris@81 89 ErrorPosition checkPathCostMatrix();
Chris@92 90 void checkAndReport();
Chris@82 91 #endif
Chris@82 92
Chris@72 93 Matcher *m_m;
Chris@72 94 int m_duration1;
Chris@72 95 int m_duration2;
cannam@0 96 }; // class Finder
cannam@0 97
cannam@0 98 #endif