annotate Matcher.cpp @ 1:de792b8c2801

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