Mercurial > hg > match-vamp
comparison Path.cpp @ 0:640f92242cc1
* initial import
author | cannam |
---|---|
date | Wed, 24 Oct 2007 12:13:43 +0000 |
parents | |
children | cdead4a52755 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:640f92242cc1 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Vamp feature extraction plugin using the MATCH audio alignment | |
5 algorithm. | |
6 | |
7 Centre for Digital Music, Queen Mary, University of London. | |
8 This file copyright 2007 Simon Dixon, Chris Cannam and QMUL. | |
9 | |
10 This program is free software; you can redistribute it and/or | |
11 modify it under the terms of the GNU General Public License as | |
12 published by the Free Software Foundation; either version 2 of the | |
13 License, or (at your option) any later version. See the file | |
14 COPYING included with this distribution for more information. | |
15 */ | |
16 | |
17 #include "Path.h" | |
18 | |
19 int | |
20 Path::smooth(std::vector<int> &x, std::vector<int> &y, int length) | |
21 { | |
22 if (length == 0) | |
23 return 0; | |
24 while (val.size() < length) { | |
25 val.push_back(0); | |
26 len.push_back(0); | |
27 } | |
28 int p = 0; | |
29 val[0] = len[0] = 0; | |
30 for (int i = 1; i < length; i++) { // H = 1; V = 2; D = 3 | |
31 int current = x[i] - x[i-1] + 2 * (y[i] - y[i-1]); | |
32 if (current == val[p]) { | |
33 len[p]++; | |
34 } else if ((current == 3) || (val[p] == 0)) { | |
35 val[++p] = current; | |
36 len[p] = 1; | |
37 } else if (val[p] + current == 3) { // 1 + 2 | |
38 if (--len[p] == 0) | |
39 p--; | |
40 if (val[p] == 3) | |
41 len[p]++; | |
42 else { | |
43 val[++p] = 3; | |
44 len[p] = 1; | |
45 } | |
46 } else { // val[p] == 3 && current != 3 | |
47 if ((val[p-1] == current) || | |
48 (val[p-1] == 0) || | |
49 (len[p] > MAX_RUN_LENGTH)) { | |
50 val[++p] = current; | |
51 len[p] = 1; | |
52 } else { | |
53 if (--len[p-1] == 0) { | |
54 val[p-1] = val[p]; | |
55 len[p-1] = len[p]; | |
56 p--; | |
57 if (val[p-1] == 3) { | |
58 len[p-1] += len[p]; | |
59 p--; | |
60 } | |
61 } | |
62 len[p]++; | |
63 } | |
64 } | |
65 } | |
66 int i = 1; | |
67 for (int pp = 1; pp <= p; pp++) { | |
68 int dx = val[pp] & 1; | |
69 int dy = val[pp] >> 1; | |
70 for (int j = len[pp]; j > 0; j--, i++) { | |
71 x[i] = x[i-1] + dx; | |
72 y[i] = y[i-1] + dy; | |
73 } | |
74 } | |
75 return i; | |
76 } |