annotate src/Path.cpp @ 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.
cannam@0 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 #include "Path.h"
cannam@0 19
cannam@0 20 int
cannam@0 21 Path::smooth(std::vector<int> &x, std::vector<int> &y, int length)
cannam@0 22 {
Chris@188 23 if (length <= 0)
cannam@0 24 return 0;
Chris@188 25 while (m_val.size() < static_cast<std::vector<int>::size_type>(length)) {
Chris@188 26 m_val.push_back(0);
Chris@188 27 m_len.push_back(0);
cannam@0 28 }
cannam@0 29 int p = 0;
Chris@188 30 m_val[0] = m_len[0] = 0;
cannam@0 31 for (int i = 1; i < length; i++) { // H = 1; V = 2; D = 3
cannam@0 32 int current = x[i] - x[i-1] + 2 * (y[i] - y[i-1]);
Chris@188 33 if (current == m_val[p]) {
Chris@188 34 m_len[p]++;
Chris@188 35 } else if ((current == 3) || (m_val[p] == 0)) {
Chris@188 36 m_val[++p] = current;
Chris@188 37 m_len[p] = 1;
Chris@188 38 } else if (m_val[p] + current == 3) { // 1 + 2
Chris@188 39 if (--m_len[p] == 0)
cannam@0 40 p--;
Chris@188 41 if (m_val[p] == 3)
Chris@188 42 m_len[p]++;
cannam@0 43 else {
Chris@188 44 m_val[++p] = 3;
Chris@188 45 m_len[p] = 1;
cannam@0 46 }
Chris@188 47 } else { // m_val[p] == 3 && current != 3
Chris@188 48 if ((m_val[p-1] == current) ||
Chris@188 49 (m_val[p-1] == 0) ||
Chris@188 50 (m_len[p] > MAX_RUN_LENGTH)) {
Chris@188 51 m_val[++p] = current;
Chris@188 52 m_len[p] = 1;
cannam@0 53 } else {
Chris@188 54 if (--m_len[p-1] == 0) {
Chris@188 55 m_val[p-1] = m_val[p];
Chris@188 56 m_len[p-1] = m_len[p];
cannam@0 57 p--;
Chris@188 58 if (m_val[p-1] == 3) {
Chris@188 59 m_len[p-1] += m_len[p];
cannam@0 60 p--;
cannam@0 61 }
cannam@0 62 }
Chris@188 63 m_len[p]++;
cannam@0 64 }
cannam@0 65 }
cannam@0 66 }
cannam@0 67 int i = 1;
cannam@0 68 for (int pp = 1; pp <= p; pp++) {
Chris@188 69 int dx = m_val[pp] & 1;
Chris@188 70 int dy = m_val[pp] >> 1;
Chris@188 71 for (int j = m_len[pp]; j > 0; j--, i++) {
cannam@0 72 x[i] = x[i-1] + dx;
cannam@0 73 y[i] = y[i-1] + dy;
cannam@0 74 }
cannam@0 75 }
cannam@0 76 return i;
cannam@0 77 }