cannam@0: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ cannam@0: cannam@0: /* cannam@0: Vamp feature extraction plugin using the MATCH audio alignment cannam@0: algorithm. cannam@0: cannam@0: Centre for Digital Music, Queen Mary, University of London. cannam@0: This file copyright 2007 Simon Dixon, Chris Cannam and QMUL. cannam@0: cannam@0: This program is free software; you can redistribute it and/or cannam@0: modify it under the terms of the GNU General Public License as cannam@0: published by the Free Software Foundation; either version 2 of the cannam@0: License, or (at your option) any later version. See the file cannam@0: COPYING included with this distribution for more information. cannam@0: */ cannam@0: cannam@0: #ifndef _FINDER_H_ cannam@0: #define _FINDER_H_ cannam@0: cannam@0: #include cannam@0: #include cannam@0: cannam@0: #include "Matcher.h" cannam@0: cannam@0: /** Maps cost matrix coordinates into an efficient cannam@0: * (linear instead of quadratic space) representation. cannam@0: * Stores result of most recent mapping for fast cannam@0: * sequential access. cannam@0: */ cannam@0: class Finder { cannam@0: cannam@0: protected: cannam@0: Matcher *pm1, *pm2; cannam@0: int index1, index2, bestRow, bestCol; cannam@0: int *rowRange; cannam@0: int *colRange; cannam@0: cannam@0: public: cannam@0: Finder(Matcher *p1, Matcher *p2); cannam@0: cannam@0: ~Finder(); cannam@0: cannam@0: /** Sets up the instance variables to point to the given cannam@0: * coordinate in the distance matrix. cannam@0: * cannam@0: * @param i1 frameNumber in the first Matcher cannam@0: * @param i2 frameNumber in the second Matcher cannam@0: * @return true iff the point (i2,i1) is represented in the distance matrix cannam@0: */ cannam@0: bool find(int i1, int i2); cannam@0: cannam@0: /** Returns the range [lo,hi) of legal column indices for the cannam@0: * given row. */ cannam@0: void getColRange(int row, int *range); cannam@0: cannam@0: /** Returns the range [lo,hi) of legal row indices for the given cannam@0: * column. */ cannam@0: void getRowRange(int col, int *range); cannam@0: cannam@0: int getExpandDirection(int row, int col); cannam@0: int getExpandDirection(int row, int col, bool check); cannam@0: cannam@0: unsigned char getDistance(int row, int col); cannam@0: void setDistance(int row, int col, unsigned char b); cannam@0: cannam@0: int getPathCost(int row, int col); cannam@0: int getRawPathCost(int row, int col); cannam@0: void setPathCost(int row, int col, int i); cannam@0: cannam@0: unsigned char getDistance(); cannam@0: void setDistance(int b); cannam@0: cannam@0: int getPathCost(); cannam@0: void setPathCost(int i); cannam@0: cannam@0: /** Calculates a rectangle of the path cost matrix so that the cannam@0: * minimum cost path between the bottom left and top right cannam@0: * corners can be computed. Caches previous values to avoid cannam@0: * calling find() multiple times, and is several times faster as cannam@0: * a result. cannam@0: * cannam@0: * @param r1 the bottom of the rectangle to be calculated cannam@0: * @param c1 the left side of the rectangle to be calculated cannam@0: * @param r2 the top of the rectangle to be calculated cannam@0: * @param c2 the right side of the rectangle to be calculated cannam@0: */ cannam@0: void recalculatePathCostMatrix(int r1, int c1, int r2, int c2); cannam@0: Chris@30: /** Chris@30: * Track back after all of the matchers have been fed in order to Chris@30: * obtain the lowest cost path available. Path x and y coordinate Chris@30: * pairs are returned in corresponding elements of pathx and Chris@30: * pathy. Return value is the length of the returned path: only Chris@30: * this many elements from pathx and pathy are valid (any Chris@30: * subsequent ones may be spurious). Chris@30: */ Chris@30: int retrievePath(std::vector &pathx, std::vector &pathy); Chris@30: cannam@0: }; // class Finder cannam@0: cannam@0: #endif