annotate Matcher.cpp @ 4:ca29b0ef78ce

* minor build stuff
author cannam
date Tue, 02 Dec 2008 13:03:44 +0000
parents de792b8c2801
children a02321c31884
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.
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 "Matcher.h"
cannam@0 18 #include "Finder.h"
cannam@0 19
cannam@0 20 #include <iostream>
cannam@0 21
cannam@4 22 #include <cstdlib>
cannam@4 23
cannam@0 24 bool Matcher::silent = true;
cannam@0 25
cannam@0 26 Matcher::Matcher(float rate, Matcher *p)
cannam@0 27 {
cannam@0 28 std::cerr << "Matcher::Matcher(" << rate << ", " << p << ")" << std::endl;
cannam@0 29
cannam@0 30 sampleRate = rate;
cannam@0 31 otherMatcher = p; // the first matcher will need this to be set later
cannam@0 32 firstPM = (!p);
cannam@0 33 matchFileOffset = 0;
cannam@0 34 ltAverage = 0;
cannam@0 35 frameCount = 0;
cannam@0 36 runCount = 0;
cannam@0 37 paused = false;
cannam@0 38 hopSize = 0;
cannam@0 39 fftSize = 0;
cannam@0 40 blockSize = 0;
cannam@0 41 hopTime = 0.020; // DEFAULT, overridden with -h //!!!
cannam@0 42 fftTime = 0.04644; // DEFAULT, overridden with -f
cannam@0 43 blockTime = 10.0; // DEFAULT, overridden with -c
cannam@0 44 normalise1 = true;
cannam@0 45 normalise2 = false;
cannam@0 46 normalise3 = false;
cannam@0 47 normalise4 = true;
cannam@0 48 useSpectralDifference = true;
cannam@0 49 useChromaFrequencyMap = false;
cannam@0 50 scale = 90;
cannam@0 51 maxFrames = 0; // stop at EOF
cannam@0 52
cannam@0 53 hopSize = lrint(sampleRate * hopTime);
cannam@0 54 fftSize = lrint(pow(2, lrint(log(fftTime * sampleRate) / log(2))));
cannam@0 55 blockSize = lrint(blockTime / hopTime);
cannam@0 56
cannam@0 57 distance = 0;
cannam@0 58 bestPathCost = 0;
cannam@0 59 distYSizes = 0;
cannam@0 60 distXSize = 0;
cannam@0 61
cannam@0 62 initialised = false;
cannam@0 63
cannam@0 64 } // default constructor
cannam@0 65
cannam@1 66 void
cannam@1 67 Matcher::setHopSize(int sz)
cannam@1 68 {
cannam@1 69 if (initialised) {
cannam@1 70 std::cerr << "Matcher::setHopSize: Can't set after use" << std::endl;
cannam@1 71 return;
cannam@1 72 }
cannam@1 73
cannam@1 74 hopSize = sz;
cannam@1 75 hopTime = float(hopSize) / sampleRate;
cannam@1 76 blockTime = blockSize * hopTime;
cannam@1 77 }
cannam@1 78
cannam@0 79 Matcher::~Matcher()
cannam@0 80 {
cannam@0 81 std::cerr << "Matcher(" << this << ")::~Matcher()" << std::endl;
cannam@0 82
cannam@0 83 if (initialised) {
cannam@0 84
cannam@0 85 for (int i = 0; i < distXSize; ++i) {
cannam@0 86 if (distance[i]) {
cannam@0 87 free(distance[i]);
cannam@0 88 free(bestPathCost[i]);
cannam@0 89 }
cannam@0 90 }
cannam@0 91 free(distance);
cannam@0 92 free(bestPathCost);
cannam@0 93
cannam@0 94 free(first);
cannam@0 95 free(last);
cannam@0 96
cannam@0 97 free(distYSizes);
cannam@0 98 }
cannam@0 99 }
cannam@0 100
cannam@0 101 void
cannam@0 102 Matcher::print()
cannam@0 103 {
cannam@0 104 cerr << toString() << endl;
cannam@0 105 } // print()
cannam@0 106
cannam@0 107 string
cannam@0 108 Matcher::toString()
cannam@0 109 {
cannam@0 110 std::stringstream os;
cannam@0 111 os << "Matcher " << this << ": (" << sampleRate
cannam@0 112 << "kHz)"
cannam@0 113 << "\n\tHop size: " << hopSize
cannam@0 114 << "\n\tFFT size: " << fftSize
cannam@0 115 << "\n\tBlock size: " << blockSize;
cannam@0 116 return os.str();
cannam@0 117 } // toString()
cannam@0 118
cannam@0 119 void
cannam@0 120 Matcher::init()
cannam@0 121 {
cannam@0 122 if (initialised) return;
cannam@0 123
cannam@4 124 std::cerr << "Matcher::init() - initialising" << std::endl;
cannam@4 125
cannam@0 126 initialised = true;
cannam@0 127
cannam@0 128 makeFreqMap(fftSize, sampleRate);
cannam@0 129
cannam@0 130 initVector<double>(prevFrame, freqMapSize);
cannam@0 131 initVector<double>(newFrame, freqMapSize);
cannam@0 132 initMatrix<double>(frames, blockSize, freqMapSize + 1);
cannam@0 133
cannam@0 134 int distSize = (MAX_RUN_COUNT + 1) * blockSize;
cannam@0 135
cannam@0 136 distXSize = blockSize * 2;
cannam@0 137
cannam@0 138 // std::cerr << "Matcher::init: distXSize = " << distXSize << std::endl;
cannam@0 139
cannam@0 140 distance = (unsigned char **)malloc(distXSize * sizeof(unsigned char *));
cannam@0 141 bestPathCost = (int **)malloc(distXSize * sizeof(int *));
cannam@0 142 distYSizes = (int *)malloc(distXSize * sizeof(int));
cannam@0 143
cannam@0 144 for (int i = 0; i < blockSize; ++i) {
cannam@0 145 distance[i] = (unsigned char *)malloc(distSize * sizeof(unsigned char));
cannam@0 146 bestPathCost[i] = (int *)malloc(distSize * sizeof(int));
cannam@0 147 distYSizes[i] = distSize;
cannam@0 148 }
cannam@0 149 for (int i = blockSize; i < distXSize; ++i) {
cannam@0 150 distance[i] = 0;
cannam@0 151 }
cannam@0 152
cannam@0 153 first = (int *)malloc(distXSize * sizeof(int));
cannam@0 154 last = (int *)malloc(distXSize * sizeof(int));
cannam@0 155
cannam@0 156 frameCount = 0;
cannam@0 157 runCount = 0;
cannam@0 158 // frameRMS = 0;
cannam@0 159 ltAverage = 0;
cannam@0 160
cannam@0 161 if (!silent) print();
cannam@0 162 } // init
cannam@0 163
cannam@0 164 void
cannam@0 165 Matcher::makeFreqMap(int fftSize, float sampleRate)
cannam@0 166 {
cannam@0 167 initVector<int>(freqMap, fftSize/2 + 1);
cannam@0 168 if (useChromaFrequencyMap)
cannam@0 169 makeChromaFrequencyMap(fftSize, sampleRate);
cannam@0 170 else
cannam@0 171 makeStandardFrequencyMap(fftSize, sampleRate);
cannam@0 172 } // makeFreqMap()
cannam@0 173
cannam@0 174 void
cannam@0 175 Matcher::makeStandardFrequencyMap(int fftSize, float sampleRate)
cannam@0 176 {
cannam@0 177 double binWidth = sampleRate / fftSize;
cannam@0 178 int crossoverBin = (int)(2 / (pow(2, 1/12.0) - 1));
cannam@0 179 int crossoverMidi = lrint(log(crossoverBin*binWidth/440)/
cannam@0 180 log(2) * 12 + 69);
cannam@0 181 // freq = 440 * Math.pow(2, (midi-69)/12.0) / binWidth;
cannam@0 182 int i = 0;
cannam@0 183 while (i <= crossoverBin) {
cannam@0 184 freqMap[i] = i;
cannam@0 185 ++i;
cannam@0 186 }
cannam@0 187 while (i <= fftSize/2) {
cannam@0 188 double midi = log(i*binWidth/440) / log(2) * 12 + 69;
cannam@0 189 if (midi > 127)
cannam@0 190 midi = 127;
cannam@0 191 freqMap[i++] = crossoverBin + lrint(midi) - crossoverMidi;
cannam@0 192 }
cannam@0 193 freqMapSize = freqMap[i-1] + 1;
cannam@0 194 if (!silent) {
cannam@0 195 cerr << "Standard map size: " << freqMapSize
cannam@0 196 << "; Crossover at: " << crossoverBin << endl;
cannam@0 197 //!!! for (i = 0; i < fftSize / 2; i++)
cannam@0 198 // cerr << "freqMap[" << i << "] = " << freqMap[i] << endl;
cannam@0 199 }
cannam@0 200 } // makeStandardFrequencyMap()
cannam@0 201
cannam@0 202 void
cannam@0 203 Matcher::makeChromaFrequencyMap(int fftSize, float sampleRate)
cannam@0 204 {
cannam@0 205 double binWidth = sampleRate / fftSize;
cannam@0 206 int crossoverBin = (int)(1 / (pow(2, 1/12.0) - 1));
cannam@0 207 // freq = 440 * Math.pow(2, (midi-69)/12.0) / binWidth;
cannam@0 208 int i = 0;
cannam@0 209 while (i <= crossoverBin)
cannam@0 210 freqMap[i++] = 0;
cannam@0 211 while (i <= fftSize/2) {
cannam@0 212 double midi = log(i*binWidth/440) / log(2) * 12 + 69;
cannam@0 213 freqMap[i++] = (lrint(midi)) % 12 + 1;
cannam@0 214 }
cannam@0 215 freqMapSize = 13;
cannam@0 216 if (!silent) {
cannam@0 217 cerr << "Chroma map size: " << freqMapSize
cannam@0 218 << "; Crossover at: " << crossoverBin << endl;
cannam@0 219 for (i = 0; i < fftSize / 2; i++)
cannam@0 220 cerr << "freqMap[" << i << "] = " << freqMap[i] << endl;
cannam@0 221 }
cannam@0 222 } // makeChromaFrequencyMap()
cannam@0 223
cannam@0 224 void
cannam@0 225 Matcher::processFrame(double *reBuffer, double *imBuffer)
cannam@0 226 {
cannam@0 227 if (!initialised) init();
cannam@0 228
cannam@0 229 for (int i = 0; i < (int)newFrame.size(); ++i) {
cannam@0 230 newFrame[i] = 0;
cannam@0 231 }
cannam@0 232 double rms = 0;
cannam@0 233 for (int i = 0; i <= fftSize/2; i++) {
cannam@0 234 double mag = reBuffer[i] * reBuffer[i] +
cannam@0 235 imBuffer[i] * imBuffer[i];
cannam@0 236 rms += mag;
cannam@0 237 newFrame[freqMap[i]] += mag;
cannam@0 238 }
cannam@0 239 rms = sqrt(rms / (fftSize/2));
cannam@0 240
cannam@0 241 int frameIndex = frameCount % blockSize;
cannam@0 242
cannam@0 243 if (frameCount >= distXSize) {
cannam@0 244 // std::cerr << "Resizing " << distXSize << " -> " << distXSize * 2 << std::endl;
cannam@0 245 distXSize *= 2;
cannam@0 246 distance = (unsigned char **)realloc(distance, distXSize * sizeof(unsigned char *));
cannam@0 247 bestPathCost = (int **)realloc(bestPathCost, distXSize * sizeof(int *));
cannam@0 248 distYSizes = (int *)realloc(distYSizes, distXSize * sizeof(int));
cannam@0 249 first = (int *)realloc(first, distXSize * sizeof(int));
cannam@0 250 last = (int *)realloc(last, distXSize * sizeof(int));
cannam@0 251
cannam@0 252 for (int i = distXSize/2; i < distXSize; ++i) {
cannam@0 253 distance[i] = 0;
cannam@0 254 }
cannam@0 255 }
cannam@0 256
cannam@0 257 if (firstPM && (frameCount >= blockSize)) {
cannam@0 258
cannam@0 259 int len = last[frameCount - blockSize] -
cannam@0 260 first[frameCount - blockSize];
cannam@0 261
cannam@0 262 // We need to copy distance[frameCount-blockSize] to
cannam@0 263 // distance[frameCount], and then truncate
cannam@0 264 // distance[frameCount-blockSize] to its first len elements.
cannam@0 265 // Same for bestPathCost.
cannam@0 266 /*
cannam@4 267 std::cerr << "Matcher(" << this << "): moving " << distYSizes[frameCount - blockSize] << " from " << frameCount - blockSize << " to "
cannam@0 268 << frameCount << ", allocating " << len << " for "
cannam@0 269 << frameCount - blockSize << std::endl;
cannam@0 270 */
cannam@0 271 distance[frameCount] = distance[frameCount - blockSize];
cannam@0 272
cannam@0 273 distance[frameCount - blockSize] = (unsigned char *)
cannam@0 274 malloc(len * sizeof(unsigned char));
cannam@0 275 for (int i = 0; i < len; ++i) {
cannam@0 276 distance[frameCount - blockSize][i] =
cannam@0 277 distance[frameCount][i];
cannam@0 278 }
cannam@0 279
cannam@0 280 bestPathCost[frameCount] = bestPathCost[frameCount - blockSize];
cannam@0 281
cannam@0 282 bestPathCost[frameCount - blockSize] = (int *)
cannam@0 283 malloc(len * sizeof(int));
cannam@0 284 for (int i = 0; i < len; ++i) {
cannam@0 285 bestPathCost[frameCount - blockSize][i] =
cannam@0 286 bestPathCost[frameCount][i];
cannam@0 287 }
cannam@0 288
cannam@0 289 distYSizes[frameCount] = distYSizes[frameCount - blockSize];
cannam@0 290 distYSizes[frameCount - blockSize] = len;
cannam@0 291 }
cannam@0 292
cannam@0 293 double totalEnergy = 0;
cannam@0 294 if (useSpectralDifference) {
cannam@0 295 for (int i = 0; i < freqMapSize; i++) {
cannam@0 296 totalEnergy += newFrame[i];
cannam@0 297 if (newFrame[i] > prevFrame[i]) {
cannam@0 298 frames[frameIndex][i] = newFrame[i] - prevFrame[i];
cannam@0 299 } else {
cannam@0 300 frames[frameIndex][i] = 0;
cannam@0 301 }
cannam@0 302 }
cannam@0 303 } else {
cannam@0 304 for (int i = 0; i < freqMapSize; i++) {
cannam@0 305 frames[frameIndex][i] = newFrame[i];
cannam@0 306 totalEnergy += frames[frameIndex][i];
cannam@0 307 }
cannam@0 308 }
cannam@0 309 frames[frameIndex][freqMapSize] = totalEnergy;
cannam@0 310
cannam@0 311 double decay = frameCount >= 200 ? 0.99:
cannam@0 312 (frameCount < 100? 0: (frameCount - 100) / 100.0);
cannam@0 313
cannam@0 314 if (ltAverage == 0)
cannam@0 315 ltAverage = totalEnergy;
cannam@0 316 else
cannam@0 317 ltAverage = ltAverage * decay + totalEnergy * (1.0 - decay);
cannam@0 318
cannam@0 319 // System.err.println(Format.d(ltAverage,4) + " " +
cannam@0 320 // Format.d(totalEnergy) + " " +
cannam@0 321 // Format.d(frameRMS));
cannam@0 322
cannam@0 323 // std::cerr << "ltAverage: " << ltAverage << ", totalEnergy: " << totalEnergy << ", frameRMS: " << rms << std::endl;
cannam@0 324
cannam@0 325 if (rms <= 0.01) //!!! silenceThreshold)
cannam@0 326 for (int i = 0; i < freqMapSize; i++)
cannam@0 327 frames[frameIndex][i] = 0;
cannam@0 328 else if (normalise1)
cannam@0 329 for (int i = 0; i < freqMapSize; i++)
cannam@0 330 frames[frameIndex][i] /= totalEnergy;
cannam@0 331 else if (normalise3)
cannam@0 332 for (int i = 0; i < freqMapSize; i++)
cannam@0 333 frames[frameIndex][i] /= ltAverage;
cannam@0 334
cannam@0 335 int stop = otherMatcher->frameCount;
cannam@0 336 int index = stop - blockSize;
cannam@0 337 if (index < 0)
cannam@0 338 index = 0;
cannam@0 339 first[frameCount] = index;
cannam@0 340 last[frameCount] = stop;
cannam@0 341
cannam@0 342 bool overflow = false;
cannam@0 343 int mn= -1;
cannam@0 344 int mx= -1;
cannam@0 345 for ( ; index < stop; index++) {
cannam@0 346 int dMN = calcDistance(frames[frameIndex],
cannam@0 347 otherMatcher->frames[index % blockSize]);
cannam@0 348 if (mx<0)
cannam@0 349 mx = mn = dMN;
cannam@0 350 else if (dMN > mx)
cannam@0 351 mx = dMN;
cannam@0 352 else if (dMN < mn)
cannam@0 353 mn = dMN;
cannam@0 354 if (dMN >= 255) {
cannam@0 355 overflow = true;
cannam@0 356 dMN = 255;
cannam@0 357 }
cannam@0 358 if ((frameCount == 0) && (index == 0)) // first element
cannam@0 359 setValue(0, 0, 0, 0, dMN);
cannam@0 360 else if (frameCount == 0) // first row
cannam@0 361 setValue(0, index, ADVANCE_OTHER,
cannam@0 362 getValue(0, index-1, true), dMN);
cannam@0 363 else if (index == 0) // first column
cannam@0 364 setValue(frameCount, index, ADVANCE_THIS,
cannam@0 365 getValue(frameCount - 1, 0, true), dMN);
cannam@0 366 else if (index == otherMatcher->frameCount - blockSize) {
cannam@0 367 // missing value(s) due to cutoff
cannam@0 368 // - no previous value in current row (resp. column)
cannam@0 369 // - no diagonal value if prev. dir. == curr. dirn
cannam@0 370 int min2 = getValue(frameCount - 1, index, true);
cannam@0 371 // if ((firstPM && (first[frameCount - 1] == index)) ||
cannam@0 372 // (!firstPM && (last[index-1] < frameCount)))
cannam@0 373 if (first[frameCount - 1] == index)
cannam@0 374 setValue(frameCount, index, ADVANCE_THIS, min2, dMN);
cannam@0 375 else {
cannam@0 376 int min1 = getValue(frameCount - 1, index - 1, true);
cannam@0 377 if (min1 + dMN <= min2)
cannam@0 378 setValue(frameCount, index, ADVANCE_BOTH, min1,dMN);
cannam@0 379 else
cannam@0 380 setValue(frameCount, index, ADVANCE_THIS, min2,dMN);
cannam@0 381 }
cannam@0 382 } else {
cannam@0 383 int min1 = getValue(frameCount, index-1, true);
cannam@0 384 int min2 = getValue(frameCount - 1, index, true);
cannam@0 385 int min3 = getValue(frameCount - 1, index-1, true);
cannam@0 386 if (min1 <= min2) {
cannam@0 387 if (min3 + dMN <= min1)
cannam@0 388 setValue(frameCount, index, ADVANCE_BOTH, min3,dMN);
cannam@0 389 else
cannam@0 390 setValue(frameCount, index, ADVANCE_OTHER,min1,dMN);
cannam@0 391 } else {
cannam@0 392 if (min3 + dMN <= min2)
cannam@0 393 setValue(frameCount, index, ADVANCE_BOTH, min3,dMN);
cannam@0 394 else
cannam@0 395 setValue(frameCount, index, ADVANCE_THIS, min2,dMN);
cannam@0 396 }
cannam@0 397 }
cannam@0 398 otherMatcher->last[index]++;
cannam@0 399 } // loop for row (resp. column)
cannam@0 400
cannam@0 401 vector<double> tmp = prevFrame;
cannam@0 402 prevFrame = newFrame;
cannam@0 403 newFrame = tmp;
cannam@0 404
cannam@0 405 frameCount++;
cannam@0 406 runCount++;
cannam@0 407
cannam@0 408 otherMatcher->runCount = 0;
cannam@0 409
cannam@0 410 if (overflow && !silent)
cannam@0 411 cerr << "WARNING: overflow in distance metric: "
cannam@0 412 << "frame " << frameCount << ", val = " << mx << endl;
cannam@0 413
cannam@0 414 if (!silent)
cannam@0 415 std::cerr << "Frame " << frameCount << ", d = " << (mx-mn) << std::endl;
cannam@0 416
cannam@0 417 if ((frameCount % 100) == 0) {
cannam@0 418 if (!silent) {
cannam@0 419 cerr << "Progress:" << frameCount << " " << ltAverage << endl;
cannam@0 420 // Profile.report();
cannam@0 421 }
cannam@0 422 }
cannam@0 423 //!!! if (frameCount == maxFrames)
cannam@0 424 // closeStreams();
cannam@0 425 // }
cannam@0 426 } // processFrame()
cannam@0 427
cannam@0 428 int
cannam@0 429 Matcher::calcDistance(const vector<double> &f1, const vector<double> &f2)
cannam@0 430 {
cannam@0 431 double d = 0;
cannam@0 432 double sum = 0;
cannam@0 433 for (int i = 0; i < freqMapSize; i++) {
cannam@0 434 d += fabs(f1[i] - f2[i]);
cannam@0 435 sum += f1[i] + f2[i];
cannam@0 436 }
cannam@0 437 // System.err.print(" " + Format.d(d,3));
cannam@0 438 if (sum == 0)
cannam@0 439 return 0;
cannam@0 440 if (normalise2)
cannam@0 441 return (int)(scale * d / sum); // 0 <= d/sum <= 2
cannam@0 442 if (!normalise4)
cannam@0 443 return (int)(scale * d);
cannam@0 444 // double weight = (5 + Math.log(f1[freqMapSize] + f2[freqMapSize]))/10.0;
cannam@0 445 double weight = (8 + log(sum)) / 10.0;
cannam@0 446 // if (weight < mins) {
cannam@0 447 // mins = weight;
cannam@0 448 // System.err.println(Format.d(mins,3) + " " + Format.d(maxs));
cannam@0 449 // }
cannam@0 450 // if (weight > maxs) {
cannam@0 451 // maxs = weight;
cannam@0 452 // System.err.println(Format.d(mins,3) + " " + Format.d(maxs));
cannam@0 453 // }
cannam@0 454 if (weight < 0)
cannam@0 455 weight = 0;
cannam@0 456 else if (weight > 1)
cannam@0 457 weight = 1;
cannam@0 458 return (int)(scale * d / sum * weight);
cannam@0 459 } // calcDistance()
cannam@0 460
cannam@0 461 int
cannam@0 462 Matcher::getValue(int i, int j, bool firstAttempt)
cannam@0 463 {
cannam@0 464 if (firstPM)
cannam@0 465 return bestPathCost[i][j - first[i]];
cannam@0 466 else
cannam@0 467 return otherMatcher->bestPathCost[j][i - otherMatcher->first[j]];
cannam@0 468 } // getValue()
cannam@0 469
cannam@0 470 void
cannam@0 471 Matcher::setValue(int i, int j, int dir, int value, int dMN)
cannam@0 472 {
cannam@0 473 if (firstPM) {
cannam@0 474 distance[i][j - first[i]] = (unsigned char)((dMN & MASK) | dir);
cannam@0 475 bestPathCost[i][j - first[i]] =
cannam@0 476 (value + (dir==ADVANCE_BOTH? dMN*2: dMN));
cannam@0 477 } else {
cannam@0 478 if (dir == ADVANCE_THIS)
cannam@0 479 dir = ADVANCE_OTHER;
cannam@0 480 else if (dir == ADVANCE_OTHER)
cannam@0 481 dir = ADVANCE_THIS;
cannam@0 482 int idx = i - otherMatcher->first[j];
cannam@0 483 if (idx == (int)otherMatcher->distYSizes[j]) {
cannam@0 484 // This should never happen, but if we allow arbitrary
cannam@0 485 // pauses in either direction, and arbitrary lengths at
cannam@0 486 // end, it is better than a segmentation fault.
cannam@0 487 std::cerr << "Emergency resize: " << idx << " -> " << idx * 2 << std::endl;
cannam@0 488 otherMatcher->distYSizes[j] = idx * 2;
cannam@0 489 otherMatcher->bestPathCost[j] =
cannam@0 490 (int *)realloc(otherMatcher->bestPathCost[j],
cannam@0 491 idx * 2 * sizeof(int));
cannam@0 492 otherMatcher->distance[j] =
cannam@0 493 (unsigned char *)realloc(otherMatcher->distance[j],
cannam@0 494 idx * 2 * sizeof(unsigned char));
cannam@0 495 }
cannam@0 496 otherMatcher->distance[j][idx] = (unsigned char)((dMN & MASK) | dir);
cannam@0 497 otherMatcher->bestPathCost[j][idx] =
cannam@0 498 (value + (dir==ADVANCE_BOTH? dMN*2: dMN));
cannam@0 499 }
cannam@0 500 } // setValue()
cannam@0 501