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. Chris@236: Copyright (c) 2007-2020 Simon Dixon, Chris Cannam, and Queen Mary Chris@230: University of London, Copyright (c) 2014-2015 Tido GmbH. 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: #include "Path.h" cannam@0: cannam@0: int cannam@0: Path::smooth(std::vector &x, std::vector &y, int length) cannam@0: { Chris@188: if (length <= 0) cannam@0: return 0; Chris@188: while (m_val.size() < static_cast::size_type>(length)) { Chris@188: m_val.push_back(0); Chris@188: m_len.push_back(0); cannam@0: } cannam@0: int p = 0; Chris@188: m_val[0] = m_len[0] = 0; cannam@0: for (int i = 1; i < length; i++) { // H = 1; V = 2; D = 3 cannam@0: int current = x[i] - x[i-1] + 2 * (y[i] - y[i-1]); Chris@188: if (current == m_val[p]) { Chris@188: m_len[p]++; Chris@188: } else if ((current == 3) || (m_val[p] == 0)) { Chris@188: m_val[++p] = current; Chris@188: m_len[p] = 1; Chris@188: } else if (m_val[p] + current == 3) { // 1 + 2 Chris@188: if (--m_len[p] == 0) cannam@0: p--; Chris@188: if (m_val[p] == 3) Chris@188: m_len[p]++; cannam@0: else { Chris@188: m_val[++p] = 3; Chris@188: m_len[p] = 1; cannam@0: } Chris@188: } else { // m_val[p] == 3 && current != 3 Chris@188: if ((m_val[p-1] == current) || Chris@188: (m_val[p-1] == 0) || Chris@188: (m_len[p] > MAX_RUN_LENGTH)) { Chris@188: m_val[++p] = current; Chris@188: m_len[p] = 1; cannam@0: } else { Chris@188: if (--m_len[p-1] == 0) { Chris@188: m_val[p-1] = m_val[p]; Chris@188: m_len[p-1] = m_len[p]; cannam@0: p--; Chris@188: if (m_val[p-1] == 3) { Chris@188: m_len[p-1] += m_len[p]; cannam@0: p--; cannam@0: } cannam@0: } Chris@188: m_len[p]++; cannam@0: } cannam@0: } cannam@0: } cannam@0: int i = 1; cannam@0: for (int pp = 1; pp <= p; pp++) { Chris@188: int dx = m_val[pp] & 1; Chris@188: int dy = m_val[pp] >> 1; Chris@188: for (int j = m_len[pp]; j > 0; j--, i++) { cannam@0: x[i] = x[i-1] + dx; cannam@0: y[i] = y[i-1] + dy; cannam@0: } cannam@0: } cannam@0: return i; cannam@0: }