# HG changeset patch
# User Chris Cannam
# Date 1425046250 0
# Node ID 6373d14deace46ff1e45c7a041664a88b50463c4
# Parent 96dc6a59e1ed02835b0efa5ea940134531e181a6
Clip cost when adding increment in direction comparison as well as when updating
diff -r 96dc6a59e1ed -r 6373d14deace src/Matcher.cpp
--- a/src/Matcher.cpp Fri Feb 27 14:00:48 2015 +0000
+++ b/src/Matcher.cpp Fri Feb 27 14:10:50 2015 +0000
@@ -294,13 +294,23 @@
calcAdvance();
}
+pathcost_t
+Matcher::addToCost(pathcost_t cost, pathcost_t increment)
+{
+ if (MaxPathCost - increment < cost) {
+ return MaxPathCost;
+ } else {
+ return cost + pathcost_t(increment);
+ }
+}
+
void
Matcher::calcAdvance()
{
int frameIndex = m_frameCount % m_blockSize;
if (m_frameCount >= m_distXSize) {
- m_distXSize *= 1.2;
+ m_distXSize = int(m_distXSize * 1.2);
size();
}
@@ -371,7 +381,8 @@
} else {
pathcost_t min1 = getPathCost(m_frameCount - 1, index - 1);
- if (min1 + diagIncrement <= min2 + straightIncrement) {
+ if (addToCost(min1, diagIncrement) <=
+ addToCost(min2, straightIncrement)) {
updateValue(m_frameCount, index, AdvanceBoth,
min1, distance);
} else {
@@ -386,9 +397,9 @@
pathcost_t min2 = getPathCost(m_frameCount - 1, index);
pathcost_t min3 = getPathCost(m_frameCount - 1, index - 1);
- pathcost_t cost1 = min1 + straightIncrement;
- pathcost_t cost2 = min2 + straightIncrement;
- pathcost_t cost3 = min3 + diagIncrement;
+ pathcost_t cost1 = addToCost(min1, straightIncrement);
+ pathcost_t cost2 = addToCost(min2, straightIncrement);
+ pathcost_t cost3 = addToCost(min3, diagIncrement);
// Choosing is easy if there is a strict cheapest of the
// three. If two or more share the lowest cost, we choose
@@ -436,10 +447,10 @@
increment = pathcost_t(increment * m_params.diagonalWeight);
}
- pathcost_t newValue = value + increment;
- if (MaxPathCost - increment < value) {
+ pathcost_t newValue = addToCost(value, increment);
+ if (newValue == MaxPathCost) {
cerr << "ERROR: Path cost overflow at i=" << i << ", j=" << j << ": "
- << value << " + " << increment << " > " << MaxPathCost << endl;
+ << value << " + " << increment << " >= " << MaxPathCost << endl;
newValue = MaxPathCost;
}
diff -r 96dc6a59e1ed -r 6373d14deace src/Matcher.h
--- a/src/Matcher.h Fri Feb 27 14:00:48 2015 +0000
+++ b/src/Matcher.h Fri Feb 27 14:10:50 2015 +0000
@@ -278,11 +278,14 @@
void calcAdvance();
+ /**
+ * Add the given distance increment to the given path cost, and
+ * return the result clipped (if necessary) at MaxPathCost.
+ */
+ pathcost_t addToCost(pathcost_t cost, pathcost_t increment);
+
/** Points to the other performance with which this one is being
- * compared. The data for the distance metric and the dynamic
- * time warping is shared between the two matchers. In the
- * original version, only one of the two performance matchers
- * contained the distance metric. (See first
)
+ * compared. (See m_firstPM
)
*/
Matcher *m_otherMatcher;