annotate src/Finder.h @ 60:faa523be20f9 refactors_no_float

Update both Feeders so as to recognise the end of one input before the other has ended. MatchFeeder does this by detecting trailing silence (as both its inputs are technically the same length since the shorter is zero-padded) and reporting that to Finder. MatchFeatureFeeder simply recognises missing features at the end and won't queue them.
author Chris Cannam
date Fri, 14 Nov 2014 13:53:58 +0000
parents 16870e8770ae
children 19a93b15fcc3
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
cannam@0 25 /** Maps cost matrix coordinates into an efficient
cannam@0 26 * (linear instead of quadratic space) representation.
cannam@0 27 * Stores result of most recent mapping for fast
cannam@0 28 * sequential access.
cannam@0 29 */
cannam@0 30 class Finder {
cannam@0 31
cannam@0 32 protected:
cannam@0 33 Matcher *pm1, *pm2;
cannam@0 34 int index1, index2, bestRow, bestCol;
cannam@0 35 int *rowRange;
cannam@0 36 int *colRange;
Chris@60 37 int duration1, duration2;
cannam@0 38
cannam@0 39 public:
cannam@0 40 Finder(Matcher *p1, Matcher *p2);
cannam@0 41
cannam@0 42 ~Finder();
cannam@0 43
Chris@60 44 /**
Chris@60 45 * Tell the finder that one or both files ends sooner than it
Chris@60 46 * thought, i.e. that some of the trailing features are silence or
Chris@60 47 * otherwise to be ignored. d1 and d2 are feature frame counts for
Chris@60 48 * matchers 1 and 2 respectively. If this is not called, the full
Chris@60 49 * duration of each input will be considered.
Chris@60 50 */
Chris@60 51 void setDurations(int d1, int d2);
Chris@60 52
cannam@0 53 /** Sets up the instance variables to point to the given
cannam@0 54 * coordinate in the distance matrix.
cannam@0 55 *
cannam@0 56 * @param i1 frameNumber in the first Matcher
cannam@0 57 * @param i2 frameNumber in the second Matcher
cannam@0 58 * @return true iff the point (i2,i1) is represented in the distance matrix
cannam@0 59 */
cannam@0 60 bool find(int i1, int i2);
cannam@0 61
cannam@0 62 /** Returns the range [lo,hi) of legal column indices for the
cannam@0 63 * given row. */
cannam@0 64 void getColRange(int row, int *range);
cannam@0 65
cannam@0 66 /** Returns the range [lo,hi) of legal row indices for the given
cannam@0 67 * column. */
cannam@0 68 void getRowRange(int col, int *range);
cannam@0 69
cannam@0 70 int getExpandDirection(int row, int col);
cannam@0 71 int getExpandDirection(int row, int col, bool check);
cannam@0 72
cannam@0 73 unsigned char getDistance(int row, int col);
cannam@0 74 void setDistance(int row, int col, unsigned char b);
cannam@0 75
cannam@0 76 int getPathCost(int row, int col);
cannam@0 77 int getRawPathCost(int row, int col);
cannam@0 78 void setPathCost(int row, int col, int i);
cannam@0 79
cannam@0 80 unsigned char getDistance();
cannam@0 81 void setDistance(int b);
cannam@0 82
cannam@0 83 int getPathCost();
cannam@0 84 void setPathCost(int i);
cannam@0 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@30 110
cannam@0 111 }; // class Finder
cannam@0 112
cannam@0 113 #endif