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