annotate query.cpp @ 434:7af140bf8a0a api-inversion

adb_t-ize most of audioDB::set_up_db. All of this "adding code" nonsense (mostly because of the conversion from C++ non-local exits using audioDB::error into lame C "must return and check integer error code") has to have a payoff sometime. That day will come. That day will come.
author mas01cr
date Wed, 24 Dec 2008 10:55:52 +0000
parents 681837f7c903
children 53c487885b2c
rev   line source
mas01cr@239 1 #include "audioDB.h"
mas01cr@239 2 #include "reporter.h"
mas01cr@239 3
mas01cr@422 4 #include "audioDB-internals.h"
mas01cr@422 5 #include "accumulators.h"
mas01cr@422 6
mas01cr@425 7 static bool audiodb_powers_acceptable(adb_query_refine_t *r, double p1, double p2) {
mas01cr@425 8 if (r->flags & ADB_REFINE_ABSOLUTE_THRESHOLD) {
mas01cr@425 9 if ((p1 < r->absolute_threshold) || (p2 < r->absolute_threshold)) {
mas01cr@239 10 return false;
mas01cr@239 11 }
mas01cr@239 12 }
mas01cr@425 13 if (r->flags & ADB_REFINE_RELATIVE_THRESHOLD) {
mas01cr@425 14 if (fabs(p1-p2) > fabs(r->relative_threshold)) {
mas01cr@239 15 return false;
mas01cr@239 16 }
mas01cr@239 17 }
mas01cr@239 18 return true;
mas01cr@239 19 }
mas01cr@239 20
mas01cr@239 21 void audioDB::query(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse) {
mas01cr@425 22
mas01cr@431 23 // init database tables and dbH first
mas01cr@431 24 if(query_from_key)
mas01cr@431 25 initTables(dbName);
mas01cr@431 26 else
mas01cr@431 27 initTables(dbName, inFile);
mas01cr@431 28
mas01cr@425 29 adb_query_refine_t refine;
mas01cr@431 30 adb_query_parameters_t params;
mas01cr@425 31 refine.flags = 0;
mas01cr@425 32 /* FIXME: trackFile / ADB_REFINE_KEYLIST */
mas01cr@425 33 if(radius) {
mas01cr@425 34 refine.flags |= ADB_REFINE_RADIUS;
mas01cr@425 35 refine.radius = radius;
mas01cr@425 36 }
mas01cr@425 37 if(use_absolute_threshold) {
mas01cr@425 38 refine.flags |= ADB_REFINE_ABSOLUTE_THRESHOLD;
mas01cr@425 39 refine.absolute_threshold = absolute_threshold;
mas01cr@425 40 }
mas01cr@425 41 if(use_relative_threshold) {
mas01cr@425 42 refine.flags |= ADB_REFINE_RELATIVE_THRESHOLD;
mas01cr@425 43 refine.relative_threshold = relative_threshold;
mas01cr@425 44 }
mas01cr@425 45 if(usingTimes) {
mas01cr@425 46 refine.flags |= ADB_REFINE_DURATION_RATIO;
mas01cr@425 47 refine.duration_ratio = timesTol;
mas01cr@425 48 }
mas01cr@425 49 /* FIXME: not sure about this any more; maybe it belongs in query_id */
mas01cr@425 50 if(sequenceHop != 1) {
mas01cr@425 51 refine.flags |= ADB_REFINE_HOP_SIZE;
mas01cr@425 52 refine.hopsize = sequenceHop;
mas01cr@425 53 }
mas01cr@425 54
mas01cr@431 55 switch(queryType) {
mas01cr@431 56 case O2_POINT_QUERY:
mas01cr@431 57 sequenceLength = 1;
mas01cr@431 58 params.accumulation = ADB_ACCUMULATION_DB;
mas01cr@431 59 params.distance = ADB_DISTANCE_DOT_PRODUCT;
mas01cr@431 60 params.npoints = pointNN;
mas01cr@431 61 params.ntracks = 0;
mas01cr@431 62 reporter = new pointQueryReporter< std::greater < NNresult > >(pointNN);
mas01cr@431 63 break;
mas01cr@431 64 case O2_TRACK_QUERY:
mas01cr@431 65 sequenceLength = 1;
mas01cr@431 66 params.accumulation = ADB_ACCUMULATION_PER_TRACK;
mas01cr@431 67 params.distance = ADB_DISTANCE_DOT_PRODUCT;
mas01cr@431 68 params.npoints = pointNN;
mas01cr@431 69 params.ntracks = trackNN;
mas01cr@431 70 reporter = new trackAveragingReporter< std::greater< NNresult > >(pointNN, trackNN, dbH->numFiles);
mas01cr@431 71 break;
mas01cr@431 72 case O2_SEQUENCE_QUERY:
mas01cr@431 73 case O2_N_SEQUENCE_QUERY:
mas01cr@431 74 params.accumulation = ADB_ACCUMULATION_PER_TRACK;
mas01cr@431 75 params.distance = no_unit_norming ? ADB_DISTANCE_EUCLIDEAN : ADB_DISTANCE_EUCLIDEAN_NORMED;
mas01cr@431 76 params.npoints = pointNN;
mas01cr@431 77 params.ntracks = trackNN;
mas01cr@431 78 switch(queryType) {
mas01cr@431 79 case O2_SEQUENCE_QUERY:
mas01cr@431 80 if(!(refine.flags & ADB_REFINE_RADIUS)) {
mas01cr@431 81 reporter = new trackAveragingReporter< std::less< NNresult > >(pointNN, trackNN, dbH->numFiles);
mas01cr@431 82 } else if (index_exists(dbName, radius, sequenceLength)) {
mas01cr@431 83 char* indexName = index_get_name(dbName, radius, sequenceLength);
mas01cr@431 84 lsh = index_allocate(indexName, false);
mas01cr@431 85 reporter = new trackSequenceQueryRadReporter(trackNN, index_to_trackID(lsh->get_maxp(), lsh_n_point_bits)+1);
mas01cr@431 86 delete[] indexName;
mas01cr@431 87 } else {
mas01cr@431 88 reporter = new trackSequenceQueryRadReporter(trackNN, dbH->numFiles);
mas01cr@431 89 }
mas01cr@431 90 break;
mas01cr@431 91 case O2_N_SEQUENCE_QUERY:
mas01cr@431 92 if(!(refine.flags & ADB_REFINE_RADIUS)) {
mas01cr@431 93 reporter = new trackSequenceQueryNNReporter< std::less < NNresult > >(pointNN, trackNN, dbH->numFiles);
mas01cr@431 94 } else if (index_exists(dbName, radius, sequenceLength)){
mas01cr@431 95 char* indexName = index_get_name(dbName, radius, sequenceLength);
mas01cr@431 96 lsh = index_allocate(indexName, false);
mas01cr@431 97 reporter = new trackSequenceQueryRadNNReporter(pointNN,trackNN, index_to_trackID(lsh->get_maxp(), lsh_n_point_bits)+1);
mas01cr@431 98 delete[] indexName;
mas01cr@431 99 } else {
mas01cr@431 100 reporter = new trackSequenceQueryRadNNReporter(pointNN,trackNN, dbH->numFiles);
mas01cr@431 101 }
mas01cr@431 102 break;
mas01cr@431 103 }
mas01cr@431 104 break;
mas01cr@431 105 case O2_ONE_TO_ONE_N_SEQUENCE_QUERY:
mas01cr@431 106 params.accumulation = ADB_ACCUMULATION_ONE_TO_ONE;
mas01cr@431 107 params.distance = ADB_DISTANCE_EUCLIDEAN_NORMED;
mas01cr@431 108 params.npoints = 0;
mas01cr@431 109 params.ntracks = 0;
mas01cr@431 110 break;
mas01cr@431 111 default:
mas01cr@431 112 error("unrecognized queryType");
mas01cr@431 113 }
mas01mc@292 114
mas01mc@292 115 // keyKeyPos requires dbH to be initialized
mas01cr@430 116 if(query_from_key && (!key || (query_from_key_index = audiodb_key_index(adb, key)) == (uint32_t) -1))
mas01cr@430 117 error("Query key not found", key);
mas01cr@431 118
mas01cr@431 119 switch(params.distance) {
mas01cr@431 120 case ADB_DISTANCE_DOT_PRODUCT:
mas01cr@431 121 switch(params.accumulation) {
mas01cr@431 122 case ADB_ACCUMULATION_DB:
mas01cr@431 123 accumulator = new DBAccumulator<adb_result_dist_gt>(params.npoints);
mas01cr@431 124 break;
mas01cr@431 125 case ADB_ACCUMULATION_PER_TRACK:
mas01cr@431 126 accumulator = new PerTrackAccumulator<adb_result_dist_gt>(params.npoints, params.ntracks);
mas01cr@431 127 break;
mas01cr@431 128 case ADB_ACCUMULATION_ONE_TO_ONE:
mas01cr@431 129 accumulator = new NearestAccumulator<adb_result_dist_gt>();
mas01cr@431 130 break;
mas01cr@431 131 default:
mas01cr@431 132 error("unknown accumulation");
mas01cr@239 133 }
mas01cr@239 134 break;
mas01cr@431 135 case ADB_DISTANCE_EUCLIDEAN_NORMED:
mas01cr@431 136 case ADB_DISTANCE_EUCLIDEAN:
mas01cr@431 137 switch(params.accumulation) {
mas01cr@431 138 case ADB_ACCUMULATION_DB:
mas01cr@431 139 accumulator = new DBAccumulator<adb_result_dist_lt>(params.npoints);
mas01cr@431 140 break;
mas01cr@431 141 case ADB_ACCUMULATION_PER_TRACK:
mas01cr@431 142 accumulator = new PerTrackAccumulator<adb_result_dist_lt>(params.npoints, params.ntracks);
mas01cr@431 143 break;
mas01cr@431 144 case ADB_ACCUMULATION_ONE_TO_ONE:
mas01cr@431 145 accumulator = new NearestAccumulator<adb_result_dist_lt>();
mas01cr@431 146 break;
mas01cr@431 147 default:
mas01cr@431 148 error("unknown accumulation");
mas01mc@263 149 }
mas01mc@263 150 break;
mas01cr@239 151 default:
mas01cr@431 152 error("unknown distance function");
mas01cr@431 153 }
mas01cr@431 154
mas01mc@292 155 // Test for index (again) here
mas01cr@425 156 if((refine.flags & ADB_REFINE_RADIUS) && index_exists(dbName, radius, sequenceLength)){
mas01mc@329 157 VERB_LOG(1, "Calling indexed query on database %s, radius=%f, sequenceLength=%d\n", dbName, radius, sequenceLength);
mas01cr@431 158 index_query_loop(&params, &refine, dbName, query_from_key_index);
mas01mc@329 159 }
mas01mc@329 160 else{
mas01mc@329 161 VERB_LOG(1, "Calling brute-force query on database %s\n", dbName);
mas01cr@431 162 query_loop(&params, &refine, query_from_key_index);
mas01mc@329 163 }
mas01mc@292 164
mas01cr@423 165 adb_query_results_t *rs = accumulator->get_points();
mas01cr@423 166 for(unsigned int k = 0; k < rs->nresults; k++) {
mas01cr@423 167 adb_result_t r = rs->results[k];
mas01cr@430 168 reporter->add_point(audiodb_key_index(adb, r.key), r.qpos, r.ipos, r.dist);
mas01cr@423 169 }
mas01cr@423 170
mas01mc@292 171 reporter->report(fileTable, adbQueryResponse);
mas01cr@239 172 }
mas01cr@239 173
mas01cr@433 174 void audioDB::initialize_arrays(adb_t *adb, int track, unsigned int numVectors, double *query, double *data_buffer, double **D, double **DD) {
mas01cr@239 175 unsigned int j, k, l, w;
mas01cr@239 176 double *dp, *qp, *sp;
mas01cr@239 177
mas01cr@239 178 const unsigned HOP_SIZE = sequenceHop;
mas01cr@239 179 const unsigned wL = sequenceLength;
mas01cr@239 180
mas01cr@239 181 for(j = 0; j < numVectors; j++) {
mas01cr@239 182 // Sum products matrix
mas01cr@433 183 D[j] = new double[(*adb->track_lengths)[track]];
mas01cr@239 184 assert(D[j]);
mas01cr@239 185 // Matched filter matrix
mas01cr@433 186 DD[j]=new double[(*adb->track_lengths)[track]];
mas01cr@239 187 assert(DD[j]);
mas01cr@239 188 }
mas01cr@239 189
mas01cr@239 190 // Dot product
mas01cr@239 191 for(j = 0; j < numVectors; j++)
mas01cr@433 192 for(k = 0; k < (*adb->track_lengths)[track]; k++){
mas01cr@239 193 qp = query + j * dbH->dim;
mas01cr@239 194 sp = data_buffer + k * dbH->dim;
mas01cr@239 195 DD[j][k] = 0.0; // Initialize matched filter array
mas01cr@239 196 dp = &D[j][k]; // point to correlation cell j,k
mas01cr@239 197 *dp = 0.0; // initialize correlation cell
mas01cr@239 198 l = dbH->dim; // size of vectors
mas01cr@239 199 while(l--)
mas01cr@239 200 *dp += *qp++ * *sp++;
mas01cr@239 201 }
mas01cr@239 202
mas01cr@239 203 // Matched Filter
mas01cr@239 204 // HOP SIZE == 1
mas01cr@239 205 double* spd;
mas01cr@239 206 if(HOP_SIZE == 1) { // HOP_SIZE = shingleHop
mas01cr@239 207 for(w = 0; w < wL; w++) {
mas01cr@239 208 for(j = 0; j < numVectors - w; j++) {
mas01cr@239 209 sp = DD[j];
mas01cr@239 210 spd = D[j+w] + w;
mas01cr@433 211 k = (*adb->track_lengths)[track] - w;
mas01mc@292 212 while(k--)
mas01mc@292 213 *sp++ += *spd++;
mas01cr@239 214 }
mas01cr@239 215 }
mas01cr@239 216 } else { // HOP_SIZE != 1
mas01cr@239 217 for(w = 0; w < wL; w++) {
mas01cr@239 218 for(j = 0; j < numVectors - w; j += HOP_SIZE) {
mas01cr@239 219 sp = DD[j];
mas01cr@239 220 spd = D[j+w]+w;
mas01cr@433 221 for(k = 0; k < (*adb->track_lengths)[track] - w; k += HOP_SIZE) {
mas01cr@239 222 *sp += *spd;
mas01cr@239 223 sp += HOP_SIZE;
mas01cr@239 224 spd += HOP_SIZE;
mas01cr@239 225 }
mas01cr@239 226 }
mas01cr@239 227 }
mas01cr@239 228 }
mas01cr@239 229 }
mas01cr@239 230
mas01cr@433 231 static void audiodb_delete_arrays(int track, unsigned int numVectors, double **D, double **DD) {
mas01cr@239 232 if(D != NULL) {
mas01cr@239 233 for(unsigned int j = 0; j < numVectors; j++) {
mas01cr@239 234 delete[] D[j];
mas01cr@239 235 }
mas01cr@239 236 }
mas01cr@239 237 if(DD != NULL) {
mas01cr@239 238 for(unsigned int j = 0; j < numVectors; j++) {
mas01cr@239 239 delete[] DD[j];
mas01cr@239 240 }
mas01cr@239 241 }
mas01cr@239 242 }
mas01cr@239 243
mas01cr@433 244 int audiodb_read_data(adb_t *adb, int trkfid, int track, double **data_buffer_p, size_t *data_buffer_size_p) {
mas01cr@433 245 uint32_t track_length = (*adb->track_lengths)[track];
mas01cr@433 246 size_t track_size = track_length * sizeof(double) * adb->header->dim;
mas01cr@433 247 if (track_size > *data_buffer_size_p) {
mas01cr@239 248 if(*data_buffer_p) {
mas01cr@239 249 free(*data_buffer_p);
mas01cr@239 250 }
mas01cr@239 251 {
mas01cr@433 252 *data_buffer_size_p = track_size;
mas01cr@433 253 void *tmp = malloc(track_size);
mas01cr@239 254 if (tmp == NULL) {
mas01cr@433 255 goto error;
mas01cr@239 256 }
mas01cr@239 257 *data_buffer_p = (double *) tmp;
mas01cr@239 258 }
mas01cr@239 259 }
mas01cr@239 260
mas01cr@433 261 read_or_goto_error(trkfid, *data_buffer_p, track_size);
mas01cr@433 262 return 0;
mas01cr@433 263
mas01cr@433 264 error:
mas01cr@433 265 return 1;
mas01cr@239 266 }
mas01cr@239 267
mas01cr@405 268 void audioDB::insertTimeStamps(unsigned numVectors, std::ifstream *timesFile, double *timesdata) {
mas01cr@405 269 assert(usingTimes);
mas01cr@405 270
mas01cr@405 271 unsigned numtimes = 0;
mas01cr@405 272
mas01cr@405 273 if(!timesFile->is_open()) {
mas01cr@405 274 error("problem opening times file on timestamped database", timesFileName);
mas01cr@405 275 }
mas01cr@405 276
mas01cr@405 277 double timepoint, next;
mas01cr@405 278 *timesFile >> timepoint;
mas01cr@405 279 if (timesFile->eof()) {
mas01cr@405 280 error("no entries in times file", timesFileName);
mas01cr@405 281 }
mas01cr@405 282 numtimes++;
mas01cr@405 283 do {
mas01cr@405 284 *timesFile >> next;
mas01cr@405 285 if (timesFile->eof()) {
mas01cr@405 286 break;
mas01cr@405 287 }
mas01cr@405 288 numtimes++;
mas01cr@405 289 timesdata[0] = timepoint;
mas01cr@405 290 timepoint = (timesdata[1] = next);
mas01cr@405 291 timesdata += 2;
mas01cr@405 292 } while (numtimes < numVectors + 1);
mas01cr@405 293
mas01cr@405 294 if (numtimes < numVectors + 1) {
mas01cr@405 295 error("too few timepoints in times file", timesFileName);
mas01cr@405 296 }
mas01cr@405 297
mas01cr@405 298 *timesFile >> next;
mas01cr@405 299 if (!timesFile->eof()) {
mas01cr@405 300 error("too many timepoints in times file", timesFileName);
mas01cr@405 301 }
mas01cr@405 302 }
mas01cr@405 303
mas01cr@239 304 // These names deserve some unpicking. The names starting with a "q"
mas01cr@239 305 // are pointers to the query, norm and power vectors; the names
mas01cr@239 306 // starting with "v" are things that will end up pointing to the
mas01cr@239 307 // actual query point's information. -- CSR, 2007-12-05
mas01cr@239 308 void audioDB::set_up_query(double **qp, double **vqp, double **qnp, double **vqnp, double **qpp, double **vqpp, double *mqdp, unsigned *nvp) {
mas01cr@239 309 *nvp = (statbuf.st_size - sizeof(int)) / (dbH->dim * sizeof(double));
mas01mc@292 310
mas01cr@239 311 if(!(dbH->flags & O2_FLAG_L2NORM)) {
mas01cr@239 312 error("Database must be L2 normed for sequence query","use -L2NORM");
mas01cr@239 313 }
mas01cr@239 314
mas01cr@239 315 if(*nvp < sequenceLength) {
mas01cr@239 316 error("Query shorter than requested sequence length", "maybe use -l");
mas01cr@239 317 }
mas01cr@239 318
mas01cr@239 319 VERB_LOG(1, "performing norms... ");
mas01cr@239 320
mas01cr@239 321 *qp = new double[*nvp * dbH->dim];
mas01cr@239 322 memcpy(*qp, indata+sizeof(int), *nvp * dbH->dim * sizeof(double));
mas01cr@239 323 *qnp = new double[*nvp];
mas01cr@426 324 audiodb_l2norm_buffer(*qp, dbH->dim, *nvp, *qnp);
mas01cr@239 325
mas01cr@427 326 audiodb_sequence_sum(*qnp, *nvp, sequenceLength);
mas01cr@427 327 audiodb_sequence_sqrt(*qnp, *nvp, sequenceLength);
mas01cr@239 328
mas01cr@239 329 if (usingPower) {
mas01cr@239 330 *qpp = new double[*nvp];
mas01cr@239 331 if (lseek(powerfd, sizeof(int), SEEK_SET) == (off_t) -1) {
mas01cr@239 332 error("error seeking to data", powerFileName, "lseek");
mas01cr@239 333 }
mas01cr@239 334 int count = read(powerfd, *qpp, *nvp * sizeof(double));
mas01cr@239 335 if (count == -1) {
mas01cr@239 336 error("error reading data", powerFileName, "read");
mas01cr@239 337 }
mas01cr@239 338 if ((unsigned) count != *nvp * sizeof(double)) {
mas01cr@239 339 error("short read", powerFileName);
mas01cr@239 340 }
mas01cr@239 341
mas01cr@427 342 audiodb_sequence_sum(*qpp, *nvp, sequenceLength);
mas01cr@427 343 audiodb_sequence_average(*qpp, *nvp, sequenceLength);
mas01cr@239 344 }
mas01cr@239 345
mas01cr@239 346 if (usingTimes) {
mas01cr@239 347 unsigned int k;
mas01cr@239 348 *mqdp = 0.0;
mas01cr@239 349 double *querydurs = new double[*nvp];
mas01cr@239 350 double *timesdata = new double[*nvp*2];
mas01cr@239 351 insertTimeStamps(*nvp, timesFile, timesdata);
mas01cr@239 352 for(k = 0; k < *nvp; k++) {
mas01cr@239 353 querydurs[k] = timesdata[2*k+1] - timesdata[2*k];
mas01cr@239 354 *mqdp += querydurs[k];
mas01cr@239 355 }
mas01cr@239 356 *mqdp /= k;
mas01cr@239 357
mas01cr@239 358 VERB_LOG(1, "mean query file duration: %f\n", *mqdp);
mas01cr@239 359
mas01cr@239 360 delete [] querydurs;
mas01cr@239 361 delete [] timesdata;
mas01cr@239 362 }
mas01cr@239 363
mas01cr@239 364 // Defaults, for exhaustive search (!usingQueryPoint)
mas01cr@239 365 *vqp = *qp;
mas01cr@239 366 *vqnp = *qnp;
mas01cr@239 367 *vqpp = *qpp;
mas01cr@239 368
mas01cr@239 369 if(usingQueryPoint) {
mas01mc@341 370 if( !(queryPoint < *nvp && queryPoint < *nvp - sequenceLength + 1) ) {
mas01mc@342 371 error("queryPoint >= numVectors-sequenceLength+1 in query");
mas01cr@239 372 } else {
mas01cr@239 373 VERB_LOG(1, "query point: %u\n", queryPoint);
mas01cr@239 374 *vqp = *qp + queryPoint * dbH->dim;
mas01cr@239 375 *vqnp = *qnp + queryPoint;
mas01cr@239 376 if (usingPower) {
mas01cr@239 377 *vqpp = *qpp + queryPoint;
mas01cr@239 378 }
mas01cr@239 379 *nvp = sequenceLength;
mas01cr@239 380 }
mas01cr@239 381 }
mas01cr@239 382 }
mas01cr@239 383
mas01mc@292 384 // Does the same as set_up_query(...) but from database features instead of from a file
mas01mc@292 385 // Constructs the same outputs as set_up_query
mas01mc@292 386 void audioDB::set_up_query_from_key(double **qp, double **vqp, double **qnp, double **vqnp, double **qpp, double **vqpp, double *mqdp, unsigned *nvp, Uns32T queryIndex) {
mas01mc@292 387 if(!trackTable)
mas01mc@292 388 error("trackTable not initialized","set_up_query_from_key");
mas01mc@292 389
mas01mc@292 390 if(!(dbH->flags & O2_FLAG_L2NORM)) {
mas01mc@292 391 error("Database must be L2 normed for sequence query","use -L2NORM");
mas01mc@292 392 }
mas01mc@292 393
mas01mc@292 394 if(dbH->flags & O2_FLAG_POWER)
mas01mc@292 395 usingPower = true;
mas01mc@292 396
mas01mc@292 397 if(dbH->flags & O2_FLAG_TIMES)
mas01mc@292 398 usingTimes = true;
mas01mc@292 399
mas01mc@292 400 *nvp = trackTable[queryIndex];
mas01mc@292 401 if(*nvp < sequenceLength) {
mas01mc@292 402 error("Query shorter than requested sequence length", "maybe use -l");
mas01mc@292 403 }
mas01mc@292 404
mas01mc@292 405 VERB_LOG(1, "performing norms... ");
mas01mc@292 406
mas01mc@324 407 // For LARGE_ADB load query features from file
mas01mc@324 408 if( dbH->flags & O2_FLAG_LARGE_ADB ){
mas01mc@324 409 if(infid>0)
mas01mc@324 410 close(infid);
mas01mc@324 411 char* prefixedString = new char[O2_MAXFILESTR];
mas01mc@324 412 char* tmpStr = prefixedString;
mas01mc@324 413 strncpy(prefixedString, featureFileNameTable+queryIndex*O2_FILETABLE_ENTRY_SIZE, O2_MAXFILESTR);
mas01mc@324 414 prefix_name(&prefixedString, adb_feature_root);
mas01mc@324 415 if(tmpStr!=prefixedString)
mas01mc@324 416 delete[] tmpStr;
mas01mc@324 417 initInputFile(prefixedString, false); // nommap, file pointer at correct position
mas01mc@324 418 size_t allocatedSize = 0;
mas01cr@433 419 if(audiodb_read_data(adb, infid, queryIndex, qp, &allocatedSize))
mas01cr@433 420 error("failed to read data"); // over-writes qp and allocatedSize
mas01mc@324 421 // Consistency check on allocated memory and query feature size
mas01mc@324 422 if(*nvp*sizeof(double)*dbH->dim != allocatedSize)
mas01mc@324 423 error("Query memory allocation failed consitency check","set_up_query_from_key");
mas01mc@324 424 // Allocated and calculate auxillary sequences: l2norm and power
mas01mc@324 425 init_track_aux_data(queryIndex, *qp, qnp, vqnp, qpp, vqpp);
mas01mc@324 426 }
mas01mc@324 427 else{ // Load from self-contained ADB database
mas01mc@324 428 // Read query feature vectors from database
mas01mc@324 429 *qp = NULL;
mas01mc@324 430 lseek(dbfid, dbH->dataOffset + trackOffsetTable[queryIndex] * sizeof(double), SEEK_SET);
mas01mc@324 431 size_t allocatedSize = 0;
mas01cr@433 432 if(audiodb_read_data(adb, dbfid, queryIndex, qp, &allocatedSize))
mas01cr@433 433 error("failed to read data");
mas01mc@324 434 // Consistency check on allocated memory and query feature size
mas01mc@324 435 if(*nvp*sizeof(double)*dbH->dim != allocatedSize)
mas01mc@324 436 error("Query memory allocation failed consitency check","set_up_query_from_key");
mas01mc@324 437
mas01mc@324 438 Uns32T trackIndexOffset = trackOffsetTable[queryIndex]/dbH->dim; // Convert num data elements to num vectors
mas01mc@324 439 // Copy L2 norm partial-sum coefficients
mas01mc@324 440 assert(*qnp = new double[*nvp]);
mas01mc@324 441 memcpy(*qnp, l2normTable+trackIndexOffset, *nvp*sizeof(double));
mas01cr@427 442 audiodb_sequence_sum(*qnp, *nvp, sequenceLength);
mas01cr@427 443 audiodb_sequence_sqrt(*qnp, *nvp, sequenceLength);
mas01mc@324 444
mas01mc@324 445 if( usingPower ){
mas01mc@324 446 // Copy Power partial-sum coefficients
mas01mc@324 447 assert(*qpp = new double[*nvp]);
mas01mc@324 448 memcpy(*qpp, powerTable+trackIndexOffset, *nvp*sizeof(double));
mas01cr@427 449 audiodb_sequence_sum(*qpp, *nvp, sequenceLength);
mas01cr@427 450 audiodb_sequence_average(*qpp, *nvp, sequenceLength);
mas01mc@324 451 }
mas01mc@324 452
mas01mc@324 453 if (usingTimes) {
mas01mc@324 454 unsigned int k;
mas01mc@324 455 *mqdp = 0.0;
mas01mc@324 456 double *querydurs = new double[*nvp];
mas01mc@324 457 double *timesdata = new double[*nvp*2];
mas01mc@324 458 assert(querydurs && timesdata);
mas01mc@324 459 memcpy(timesdata, timesTable+trackIndexOffset, *nvp*sizeof(double));
mas01mc@324 460 for(k = 0; k < *nvp; k++) {
mas01mc@324 461 querydurs[k] = timesdata[2*k+1] - timesdata[2*k];
mas01mc@324 462 *mqdp += querydurs[k];
mas01mc@324 463 }
mas01mc@324 464 *mqdp /= k;
mas01mc@324 465
mas01mc@324 466 VERB_LOG(1, "mean query file duration: %f\n", *mqdp);
mas01mc@324 467
mas01mc@324 468 delete [] querydurs;
mas01mc@324 469 delete [] timesdata;
mas01mc@324 470 }
mas01mc@292 471 }
mas01mc@292 472
mas01mc@292 473 // Defaults, for exhaustive search (!usingQueryPoint)
mas01mc@292 474 *vqp = *qp;
mas01mc@292 475 *vqnp = *qnp;
mas01mc@292 476 *vqpp = *qpp;
mas01mc@292 477
mas01mc@292 478 if(usingQueryPoint) {
mas01mc@341 479 if( !(queryPoint < *nvp && queryPoint < *nvp - sequenceLength + 1) ) {
mas01mc@342 480 error("queryPoint >= numVectors-sequenceLength+1 in query");
mas01mc@292 481 } else {
mas01mc@292 482 VERB_LOG(1, "query point: %u\n", queryPoint);
mas01mc@292 483 *vqp = *qp + queryPoint * dbH->dim;
mas01mc@292 484 *vqnp = *qnp + queryPoint;
mas01mc@292 485 if (usingPower) {
mas01mc@292 486 *vqpp = *qpp + queryPoint;
mas01mc@292 487 }
mas01mc@292 488 *nvp = sequenceLength;
mas01mc@292 489 }
mas01mc@292 490 }
mas01mc@292 491 }
mas01mc@292 492
mas01mc@292 493
mas01cr@239 494 // FIXME: this is not the right name; we're not actually setting up
mas01cr@239 495 // the database, but copying various bits of it out of mmap()ed tables
mas01cr@239 496 // in order to reduce seeks.
mas01cr@434 497 int audioDB::set_up_db(adb_t *adb, double **snp, double **vsnp, double **spp, double **vspp, double **mddp, unsigned int *dvp) {
mas01cr@434 498 *dvp = adb->header->length / (adb->header->dim * sizeof(double));
mas01cr@239 499 *snp = new double[*dvp];
mas01cr@239 500
mas01cr@239 501 double *snpp = *snp, *sppp = 0;
mas01cr@434 502 lseek(adb->fd, adb->header->l2normTableOffset, SEEK_SET);
mas01cr@434 503 read_or_goto_error(adb->fd, *snp, *dvp * sizeof(double));
mas01cr@239 504
mas01cr@239 505 if (usingPower) {
mas01cr@434 506 if (!(adb->header->flags & O2_FLAG_POWER)) {
mas01cr@434 507 goto error;
mas01cr@239 508 }
mas01cr@239 509 *spp = new double[*dvp];
mas01cr@239 510 sppp = *spp;
mas01cr@434 511 lseek(adb->fd, adb->header->powerTableOffset, SEEK_SET);
mas01cr@434 512 read_or_goto_error(adb->fd, *spp, *dvp * sizeof(double));
mas01cr@239 513 }
mas01cr@239 514
mas01cr@434 515 for(unsigned int i = 0; i < adb->header->numFiles; i++){
mas01cr@434 516 size_t track_length = (*adb->track_lengths)[i];
mas01cr@434 517 if(track_length >= sequenceLength) {
mas01cr@434 518 audiodb_sequence_sum(snpp, track_length, sequenceLength);
mas01cr@434 519 audiodb_sequence_sqrt(snpp, track_length, sequenceLength);
mas01cr@239 520 if (usingPower) {
mas01cr@434 521 audiodb_sequence_sum(sppp, track_length, sequenceLength);
mas01cr@434 522 audiodb_sequence_average(sppp, track_length, sequenceLength);
mas01cr@239 523 }
mas01cr@239 524 }
mas01cr@434 525 snpp += track_length;
mas01cr@239 526 if (usingPower) {
mas01cr@434 527 sppp += track_length;
mas01cr@239 528 }
mas01cr@239 529 }
mas01cr@239 530
mas01cr@239 531 if (usingTimes) {
mas01cr@434 532 if(!(adb->header->flags & O2_FLAG_TIMES)) {
mas01cr@239 533 error("query timestamps provided for non-timed database", dbName);
mas01cr@239 534 }
mas01cr@239 535
mas01cr@434 536 *mddp = new double[adb->header->numFiles];
mas01cr@239 537
mas01cr@434 538 for(unsigned int k = 0; k < adb->header->numFiles; k++) {
mas01cr@434 539 size_t track_length = (*adb->track_lengths)[k];
mas01cr@239 540 unsigned int j;
mas01cr@239 541 (*mddp)[k] = 0.0;
mas01cr@434 542 for(j = 0; j < track_length; j++) {
mas01cr@239 543 (*mddp)[k] += timesTable[2*j+1] - timesTable[2*j];
mas01cr@239 544 }
mas01cr@239 545 (*mddp)[k] /= j;
mas01cr@239 546 }
mas01cr@239 547 }
mas01cr@239 548
mas01cr@239 549 *vsnp = *snp;
mas01cr@239 550 *vspp = *spp;
mas01cr@434 551 return 0;
mas01cr@434 552
mas01cr@434 553 error:
mas01cr@434 554 if(*snp) {
mas01cr@434 555 delete [] *snp;
mas01cr@434 556 }
mas01cr@434 557 if(*spp) {
mas01cr@434 558 delete [] *spp;
mas01cr@434 559 }
mas01cr@434 560 if(*mddp) {
mas01cr@434 561 delete [] *mddp;
mas01cr@434 562 }
mas01cr@434 563 return 1;
mas01cr@434 564
mas01cr@239 565 }
mas01cr@239 566
mas01mc@292 567 // query_points()
mas01mc@292 568 //
mas01mc@292 569 // using PointPairs held in the exact_evaluation_queue compute squared distance for each PointPair
mas01mc@292 570 // and insert result into the current reporter.
mas01mc@292 571 //
mas01mc@292 572 // Preconditions:
mas01mc@292 573 // A query inFile has been opened with setup_query(...) and query pointers initialized
mas01mc@292 574 // The database contains some points
mas01mc@292 575 // An exact_evaluation_queue has been allocated and populated
mas01mc@292 576 // A reporter has been allocated
mas01mc@292 577 //
mas01mc@292 578 // Postconditions:
mas01mc@292 579 // reporter contains the points and distances that meet the reporter constraints
mas01mc@292 580
mas01cr@431 581 void audioDB::query_loop_points(double* query, double* qnPtr, double* qpPtr, double meanQdur, Uns32T numVectors, adb_query_parameters_t *params, adb_query_refine_t *refine){
mas01mc@292 582 unsigned int dbVectors;
mas01mc@315 583 double *sNorm = 0, *snPtr, *sPower = 0, *spPtr = 0;
mas01mc@292 584 double *meanDBdur = 0;
mas01mc@292 585
mas01mc@292 586 // check pre-conditions
mas01mc@292 587 assert(exact_evaluation_queue&&reporter);
mas01mc@292 588 if(!exact_evaluation_queue->size()) // Exit if no points to evaluate
mas01mc@292 589 return;
mas01mc@292 590
mas01mc@292 591 // Compute database info
mas01mc@292 592 // FIXME: we more than likely don't need very much of the database
mas01mc@292 593 // so make a new method to build these values per-track or, even better, per-point
mas01mc@324 594 if( !( dbH->flags & O2_FLAG_LARGE_ADB) )
mas01cr@434 595 if(set_up_db(adb, &sNorm, &snPtr, &sPower, &spPtr, &meanDBdur, &dbVectors)) {
mas01cr@434 596 error("failed to set up db");
mas01cr@434 597 }
mas01mc@292 598
mas01mc@292 599 VERB_LOG(1, "matching points...");
mas01mc@292 600
mas01mc@292 601 // We are guaranteed that the order of points is sorted by:
mas01mc@324 602 // trackID, spos, qpos
mas01mc@292 603 // so we can be relatively efficient in initialization of track data.
mas01mc@292 604 // Here we assume that points don't overlap, so we will use exhaustive dot
mas01mc@324 605 // product evaluation instead of memoization of partial sums which is used
mas01mc@324 606 // for exhaustive brute-force evaluation from smaller databases: e.g. query_loop()
mas01mc@292 607 double dist;
mas01mc@292 608 size_t data_buffer_size = 0;
mas01mc@292 609 double *data_buffer = 0;
mas01mc@324 610 Uns32T trackOffset = 0;
mas01mc@324 611 Uns32T trackIndexOffset = 0;
mas01mc@292 612 Uns32T currentTrack = 0x80000000; // Initialize with a value outside of track index range
mas01mc@292 613 Uns32T npairs = exact_evaluation_queue->size();
mas01mc@292 614 while(npairs--){
mas01mc@292 615 PointPair pp = exact_evaluation_queue->top();
mas01mc@324 616 // Large ADB track data must be loaded here for sPower
mas01mc@324 617 if(dbH->flags & O2_FLAG_LARGE_ADB){
mas01mc@324 618 trackOffset=0;
mas01mc@324 619 trackIndexOffset=0;
mas01mc@292 620 if(currentTrack!=pp.trackID){
mas01mc@324 621 char* prefixedString = new char[O2_MAXFILESTR];
mas01mc@324 622 char* tmpStr = prefixedString;
mas01mc@324 623 // On currentTrack change, allocate and load track data
mas01mc@292 624 currentTrack=pp.trackID;
mas01mc@324 625 SAFE_DELETE_ARRAY(sNorm);
mas01mc@324 626 SAFE_DELETE_ARRAY(sPower);
mas01mc@324 627 if(infid>0)
mas01mc@324 628 close(infid);
mas01mc@324 629 // Open and check dimensions of feature file
mas01mc@324 630 strncpy(prefixedString, featureFileNameTable+pp.trackID*O2_FILETABLE_ENTRY_SIZE, O2_MAXFILESTR);
mas01mc@324 631 prefix_name((char ** const) &prefixedString, adb_feature_root);
mas01mc@324 632 if (prefixedString!=tmpStr)
mas01mc@324 633 delete[] tmpStr;
mas01mc@324 634 initInputFile(prefixedString, false); // nommap, file pointer at correct position
mas01mc@324 635 // Load the feature vector data for current track into data_buffer
mas01cr@433 636 if(audiodb_read_data(adb, infid, pp.trackID, &data_buffer, &data_buffer_size))
mas01cr@433 637 error("failed to read data");
mas01mc@324 638 // Load power and calculate power and l2norm sequence sums
mas01mc@324 639 init_track_aux_data(pp.trackID, data_buffer, &sNorm, &snPtr, &sPower, &spPtr);
mas01mc@292 640 }
mas01mc@324 641 }
mas01mc@324 642 else{
mas01mc@324 643 // These offsets are w.r.t. the entire database of feature vectors and auxillary variables
mas01mc@324 644 trackOffset=trackOffsetTable[pp.trackID]; // num data elements offset
mas01mc@324 645 trackIndexOffset=trackOffset/dbH->dim; // num vectors offset
mas01mc@324 646 }
mas01mc@324 647 Uns32T qPos = usingQueryPoint?0:pp.qpos;// index for query point
mas01mc@324 648 Uns32T sPos = trackIndexOffset+pp.spos; // index into l2norm table
mas01mc@324 649 // Test power thresholds before computing distance
mas01cr@425 650 if( ( !usingPower || audiodb_powers_acceptable(refine, qpPtr[qPos], sPower[sPos])) &&
mas01mc@324 651 ( qPos<numVectors-sequenceLength+1 && pp.spos<trackTable[pp.trackID]-sequenceLength+1 ) ){
mas01mc@324 652 // Non-large ADB track data is loaded inside power test for efficiency
mas01mc@324 653 if( !(dbH->flags & O2_FLAG_LARGE_ADB) && (currentTrack!=pp.trackID) ){
mas01mc@324 654 // On currentTrack change, allocate and load track data
mas01mc@324 655 currentTrack=pp.trackID;
mas01mc@324 656 lseek(dbfid, dbH->dataOffset + trackOffset * sizeof(double), SEEK_SET);
mas01cr@433 657 if(audiodb_read_data(adb, dbfid, currentTrack, &data_buffer, &data_buffer_size))
mas01cr@433 658 error("failed to read data");
mas01mc@324 659 }
mas01mc@324 660 // Compute distance
mas01cr@425 661 dist = audiodb_dot_product(query+qPos*dbH->dim, data_buffer+pp.spos*dbH->dim, dbH->dim*sequenceLength);
mas01mc@324 662 double qn = qnPtr[qPos];
mas01mc@324 663 double sn = sNorm[sPos];
mas01cr@431 664 switch(params->distance) {
mas01cr@431 665 case ADB_DISTANCE_EUCLIDEAN_NORMED:
mas01mc@324 666 dist = 2 - (2/(qn*sn))*dist;
mas01cr@431 667 break;
mas01cr@431 668 case ADB_DISTANCE_EUCLIDEAN:
mas01cr@431 669 dist = qn*qn + sn*sn - 2*dist;
mas01cr@431 670 break;
mas01cr@431 671 }
mas01cr@424 672 if((!radius) || dist <= (O2_LSH_EXACT_MULT*radius+O2_DISTANCE_TOLERANCE)) {
mas01cr@424 673 adb_result_t r;
mas01cr@424 674 r.key = fileTable + pp.trackID * O2_FILETABLE_ENTRY_SIZE;
mas01cr@424 675 r.dist = dist;
mas01cr@424 676 r.qpos = pp.qpos;
mas01cr@424 677 r.ipos = pp.spos;
mas01cr@424 678 accumulator->add_point(&r);
mas01cr@424 679 }
mas01mc@292 680 }
mas01mc@292 681 exact_evaluation_queue->pop();
mas01mc@292 682 }
mas01mc@315 683 // Cleanup
mas01mc@324 684 SAFE_DELETE_ARRAY(sNorm);
mas01mc@324 685 SAFE_DELETE_ARRAY(sPower);
mas01mc@324 686 SAFE_DELETE_ARRAY(meanDBdur);
mas01mc@292 687 }
mas01mc@292 688
mas01cr@431 689 void audioDB::query_loop(adb_query_parameters_t *params, adb_query_refine_t *refine, Uns32T queryIndex) {
mas01cr@239 690
mas01cr@239 691 unsigned int numVectors;
mas01cr@239 692 double *query, *query_data;
mas01cr@239 693 double *qNorm, *qnPtr, *qPower = 0, *qpPtr = 0;
mas01cr@239 694 double meanQdur;
mas01cr@239 695
mas01mc@324 696 if( dbH->flags & O2_FLAG_LARGE_ADB )
mas01mc@324 697 error("error: LARGE_ADB requires indexed query");
mas01mc@324 698
mas01mc@292 699 if(query_from_key)
mas01mc@292 700 set_up_query_from_key(&query_data, &query, &qNorm, &qnPtr, &qPower, &qpPtr, &meanQdur, &numVectors, queryIndex);
mas01mc@292 701 else
mas01mc@292 702 set_up_query(&query_data, &query, &qNorm, &qnPtr, &qPower, &qpPtr, &meanQdur, &numVectors);
mas01cr@239 703
mas01cr@239 704 unsigned int dbVectors;
mas01cr@239 705 double *sNorm, *snPtr, *sPower = 0, *spPtr = 0;
mas01cr@239 706 double *meanDBdur = 0;
mas01cr@239 707
mas01cr@434 708 if(set_up_db(adb, &sNorm, &snPtr, &sPower, &spPtr, &meanDBdur, &dbVectors)) {
mas01cr@434 709 error("failed to set up db");
mas01cr@434 710 }
mas01cr@239 711
mas01cr@239 712 VERB_LOG(1, "matching tracks...");
mas01cr@239 713
mas01cr@239 714 unsigned j,k,track,trackOffset=0, HOP_SIZE=sequenceHop, wL=sequenceLength;
mas01cr@239 715 double **D = 0; // Differences query and target
mas01cr@239 716 double **DD = 0; // Matched filter distance
mas01cr@239 717
mas01mc@292 718 D = new double*[numVectors]; // pre-allocate
mas01cr@239 719 DD = new double*[numVectors];
mas01cr@239 720
mas01cr@239 721 gettimeofday(&tv1, NULL);
mas01cr@239 722 unsigned processedTracks = 0;
mas01cr@239 723 off_t trackIndexOffset;
mas01cr@239 724 char nextKey[MAXSTR];
mas01cr@239 725
mas01cr@239 726 // Track loop
mas01cr@239 727 size_t data_buffer_size = 0;
mas01cr@239 728 double *data_buffer = 0;
mas01cr@239 729 lseek(dbfid, dbH->dataOffset, SEEK_SET);
mas01cr@239 730
mas01cr@239 731 for(processedTracks=0, track=0 ; processedTracks < dbH->numFiles ; track++, processedTracks++) {
mas01cr@239 732
mas01cr@239 733 trackOffset = trackOffsetTable[track]; // numDoubles offset
mas01cr@239 734
mas01cr@239 735 // get trackID from file if using a control file
mas01cr@239 736 if(trackFile) {
mas01cr@239 737 trackFile->getline(nextKey,MAXSTR);
mas01cr@239 738 if(!trackFile->eof()) {
mas01cr@430 739 track = audiodb_key_index(adb, nextKey);
mas01cr@430 740 if(track == (uint32_t) -1) {
mas01cr@430 741 error("key not found", nextKey);
mas01cr@430 742 }
mas01cr@239 743 trackOffset = trackOffsetTable[track];
mas01cr@239 744 lseek(dbfid, dbH->dataOffset + trackOffset * sizeof(double), SEEK_SET);
mas01cr@239 745 } else {
mas01cr@239 746 break;
mas01cr@239 747 }
mas01cr@239 748 }
mas01cr@239 749
mas01mc@292 750 // skip identity on query_from_key
mas01mc@292 751 if( query_from_key && (track == queryIndex) ) {
mas01mc@292 752 if(queryIndex!=dbH->numFiles-1){
mas01mc@292 753 track++;
mas01mc@292 754 trackOffset = trackOffsetTable[track];
mas01mc@292 755 lseek(dbfid, dbH->dataOffset + trackOffset * sizeof(double), SEEK_SET);
mas01mc@292 756 }
mas01mc@292 757 else{
mas01mc@292 758 break;
mas01mc@292 759 }
mas01mc@292 760 }
mas01mc@292 761
mas01cr@239 762 trackIndexOffset=trackOffset/dbH->dim; // numVectors offset
mas01cr@239 763
mas01cr@433 764 if(audiodb_read_data(adb, dbfid, track, &data_buffer, &data_buffer_size))
mas01cr@433 765 error("failed to read data");
mas01cr@239 766 if(sequenceLength <= trackTable[track]) { // test for short sequences
mas01cr@239 767
mas01cr@239 768 VERB_LOG(7,"%u.%jd.%u | ", track, (intmax_t) trackIndexOffset, trackTable[track]);
mas01cr@239 769
mas01cr@433 770 initialize_arrays(adb, track, numVectors, query, data_buffer, D, DD);
mas01cr@239 771
mas01cr@425 772 if(refine->flags & ADB_REFINE_DURATION_RATIO) {
mas01cr@239 773 VERB_LOG(3,"meanQdur=%f meanDBdur=%f\n", meanQdur, meanDBdur[track]);
mas01cr@239 774 }
mas01cr@239 775
mas01cr@425 776 if((!(refine->flags & ADB_REFINE_DURATION_RATIO)) || fabs(meanDBdur[track]-meanQdur) < meanQdur*refine->duration_ratio) {
mas01cr@425 777 if(refine->flags & ADB_REFINE_DURATION_RATIO) {
mas01cr@239 778 VERB_LOG(3,"within duration tolerance.\n");
mas01cr@239 779 }
mas01cr@239 780
mas01cr@239 781 // Search for minimum distance by shingles (concatenated vectors)
mas01cr@239 782 for(j = 0; j <= numVectors - wL; j += HOP_SIZE) {
mas01cr@239 783 for(k = 0; k <= trackTable[track] - wL; k += HOP_SIZE) {
mas01cr@431 784 double thisDist = 0;
mas01cr@431 785 switch(params->distance) {
mas01cr@431 786 case ADB_DISTANCE_EUCLIDEAN_NORMED:
mas01cr@239 787 thisDist = 2-(2/(qnPtr[j]*sNorm[trackIndexOffset+k]))*DD[j][k];
mas01cr@431 788 break;
mas01cr@431 789 case ADB_DISTANCE_EUCLIDEAN:
mas01cr@431 790 thisDist = qnPtr[j]*qnPtr[j]+sNorm[trackIndexOffset+k]*sNorm[trackIndexOffset+k] - 2*DD[j][k];
mas01cr@431 791 break;
mas01cr@431 792 case ADB_DISTANCE_DOT_PRODUCT:
mas01cr@431 793 thisDist = DD[j][k];
mas01cr@431 794 break;
mas01cr@431 795 }
mas01cr@239 796 // Power test
mas01cr@425 797 if ((!usingPower) || audiodb_powers_acceptable(refine, qpPtr[j], sPower[trackIndexOffset + k])) {
mas01cr@239 798 // radius test
mas01cr@425 799 if((!(refine->flags & ADB_REFINE_RADIUS)) ||
mas01cr@425 800 thisDist <= (refine->radius+O2_DISTANCE_TOLERANCE)) {
mas01cr@423 801 adb_result_t r;
mas01cr@423 802 r.key = fileTable + track * O2_FILETABLE_ENTRY_SIZE;
mas01cr@423 803 r.dist = thisDist;
mas01cr@423 804 r.qpos = usingQueryPoint ? queryPoint : j;
mas01cr@423 805 r.ipos = k;
mas01cr@423 806 accumulator->add_point(&r);
mas01cr@239 807 }
mas01cr@239 808 }
mas01cr@239 809 }
mas01cr@239 810 }
mas01cr@239 811 } // Duration match
mas01cr@433 812 audiodb_delete_arrays(track, numVectors, D, DD);
mas01cr@239 813 }
mas01cr@239 814 }
mas01cr@239 815
mas01cr@239 816 free(data_buffer);
mas01cr@239 817
mas01cr@239 818 gettimeofday(&tv2,NULL);
mas01cr@239 819 VERB_LOG(1,"elapsed time: %ld msec\n",
mas01cr@239 820 (tv2.tv_sec*1000 + tv2.tv_usec/1000) -
mas01cr@239 821 (tv1.tv_sec*1000 + tv1.tv_usec/1000))
mas01cr@239 822
mas01cr@239 823 // Clean up
mas01cr@239 824 if(query_data)
mas01cr@239 825 delete[] query_data;
mas01cr@239 826 if(qNorm)
mas01cr@239 827 delete[] qNorm;
mas01cr@239 828 if(sNorm)
mas01cr@239 829 delete[] sNorm;
mas01cr@239 830 if(qPower)
mas01cr@239 831 delete[] qPower;
mas01cr@239 832 if(sPower)
mas01cr@239 833 delete[] sPower;
mas01cr@239 834 if(D)
mas01cr@239 835 delete[] D;
mas01cr@239 836 if(DD)
mas01cr@239 837 delete[] DD;
mas01cr@239 838 if(meanDBdur)
mas01cr@239 839 delete[] meanDBdur;
mas01cr@239 840 }