comparison data/model/ReadOnlyWaveFileModel.cpp @ 1406:09751743647e

Untabify!
author Chris Cannam
date Tue, 07 Mar 2017 13:52:37 +0000
parents d40246df828b
children 87ae75da6527
comparison
equal deleted inserted replaced
1405:91231350ee22 1406:09751743647e
362 362
363 int channels = getChannelCount(); 363 int channels = getChannelCount();
364 364
365 if (cacheType != 0 && cacheType != 1) { 365 if (cacheType != 0 && cacheType != 1) {
366 366
367 // We need to read directly from the file. We haven't got 367 // We need to read directly from the file. We haven't got
368 // this cached. Hope the requested area is small. This is 368 // this cached. Hope the requested area is small. This is
369 // not optimal -- we'll end up reading the same frames twice 369 // not optimal -- we'll end up reading the same frames twice
370 // for stereo files, in two separate calls to this method. 370 // for stereo files, in two separate calls to this method.
371 // We could fairly trivially handle this for most cases that 371 // We could fairly trivially handle this for most cases that
372 // matter by putting a single cache in getInterleavedFrames 372 // matter by putting a single cache in getInterleavedFrames
373 // for short queries. 373 // for short queries.
374 374
375 m_directReadMutex.lock(); 375 m_directReadMutex.lock();
376 376
377 if (m_lastDirectReadStart != start || 377 if (m_lastDirectReadStart != start ||
378 m_lastDirectReadCount != count || 378 m_lastDirectReadCount != count ||
381 m_directRead = m_reader->getInterleavedFrames(start, count); 381 m_directRead = m_reader->getInterleavedFrames(start, count);
382 m_lastDirectReadStart = start; 382 m_lastDirectReadStart = start;
383 m_lastDirectReadCount = count; 383 m_lastDirectReadCount = count;
384 } 384 }
385 385
386 float max = 0.0, min = 0.0, total = 0.0; 386 float max = 0.0, min = 0.0, total = 0.0;
387 sv_frame_t i = 0, got = 0; 387 sv_frame_t i = 0, got = 0;
388 388
389 while (i < count) { 389 while (i < count) {
390 390
391 sv_frame_t index = i * channels + channel; 391 sv_frame_t index = i * channels + channel;
392 if (index >= (sv_frame_t)m_directRead.size()) break; 392 if (index >= (sv_frame_t)m_directRead.size()) break;
393 393
394 float sample = m_directRead[index]; 394 float sample = m_directRead[index];
395 if (sample > max || got == 0) max = sample; 395 if (sample > max || got == 0) max = sample;
396 if (sample < min || got == 0) min = sample; 396 if (sample < min || got == 0) min = sample;
397 total += fabsf(sample); 397 total += fabsf(sample);
398 398
399 ++i; 399 ++i;
400 ++got; 400 ++got;
401 401
402 if (got == blockSize) { 402 if (got == blockSize) {
403 ranges.push_back(Range(min, max, total / float(got))); 403 ranges.push_back(Range(min, max, total / float(got)));
404 min = max = total = 0.0f; 404 min = max = total = 0.0f;
405 got = 0; 405 got = 0;
406 } 406 }
407 } 407 }
408 408
409 m_directReadMutex.unlock(); 409 m_directReadMutex.unlock();
410 410
411 if (got > 0) { 411 if (got > 0) {
412 ranges.push_back(Range(min, max, total / float(got))); 412 ranges.push_back(Range(min, max, total / float(got)));
413 } 413 }
414 414
415 return; 415 return;
416 416
417 } else { 417 } else {
418 418
419 QMutexLocker locker(&m_mutex); 419 QMutexLocker locker(&m_mutex);
420 420
421 const RangeBlock &cache = m_cache[cacheType]; 421 const RangeBlock &cache = m_cache[cacheType];
422 422
423 blockSize = roundedBlockSize; 423 blockSize = roundedBlockSize;
424 424
425 sv_frame_t cacheBlock, div; 425 sv_frame_t cacheBlock, div;
426 426
427 cacheBlock = (sv_frame_t(1) << m_zoomConstraint.getMinCachePower()); 427 cacheBlock = (sv_frame_t(1) << m_zoomConstraint.getMinCachePower());
428 if (cacheType == 1) { 428 if (cacheType == 1) {
429 cacheBlock = sv_frame_t(double(cacheBlock) * sqrt(2.) + 0.01); 429 cacheBlock = sv_frame_t(double(cacheBlock) * sqrt(2.) + 0.01);
430 } 430 }
431 div = blockSize / cacheBlock; 431 div = blockSize / cacheBlock;
432 432
433 sv_frame_t startIndex = start / cacheBlock; 433 sv_frame_t startIndex = start / cacheBlock;
434 sv_frame_t endIndex = (start + count) / cacheBlock; 434 sv_frame_t endIndex = (start + count) / cacheBlock;
435 435
436 float max = 0.0, min = 0.0, total = 0.0; 436 float max = 0.0, min = 0.0, total = 0.0;
437 sv_frame_t i = 0, got = 0; 437 sv_frame_t i = 0, got = 0;
438 438
439 #ifdef DEBUG_WAVE_FILE_MODEL 439 #ifdef DEBUG_WAVE_FILE_MODEL
440 cerr << "blockSize is " << blockSize << ", cacheBlock " << cacheBlock << ", start " << start << ", count " << count << " (frame count " << getFrameCount() << "), power is " << power << ", div is " << div << ", startIndex " << startIndex << ", endIndex " << endIndex << endl; 440 cerr << "blockSize is " << blockSize << ", cacheBlock " << cacheBlock << ", start " << start << ", count " << count << " (frame count " << getFrameCount() << "), power is " << power << ", div is " << div << ", startIndex " << startIndex << ", endIndex " << endIndex << endl;
441 #endif 441 #endif
442 442
443 for (i = 0; i <= endIndex - startIndex; ) { 443 for (i = 0; i <= endIndex - startIndex; ) {
444 444
445 sv_frame_t index = (i + startIndex) * channels + channel; 445 sv_frame_t index = (i + startIndex) * channels + channel;
446 if (!in_range_for(cache, index)) break; 446 if (!in_range_for(cache, index)) break;
447 447
448 const Range &range = cache[index]; 448 const Range &range = cache[index];
449 if (range.max() > max || got == 0) max = range.max(); 449 if (range.max() > max || got == 0) max = range.max();
450 if (range.min() < min || got == 0) min = range.min(); 450 if (range.min() < min || got == 0) min = range.min();
451 total += range.absmean(); 451 total += range.absmean();
452 452
453 ++i; 453 ++i;
454 ++got; 454 ++got;
455 455
456 if (got == div) { 456 if (got == div) {
457 ranges.push_back(Range(min, max, total / float(got))); 457 ranges.push_back(Range(min, max, total / float(got)));
458 min = max = total = 0.0f; 458 min = max = total = 0.0f;
459 got = 0; 459 got = 0;
460 } 460 }
461 } 461 }
462 462
463 if (got > 0) { 463 if (got > 0) {
464 ranges.push_back(Range(min, max, total / float(got))); 464 ranges.push_back(Range(min, max, total / float(got)));
465 } 465 }
466 } 466 }
467 467
468 #ifdef DEBUG_WAVE_FILE_MODEL 468 #ifdef DEBUG_WAVE_FILE_MODEL
469 cerr << "returning " << ranges.size() << " ranges" << endl; 469 cerr << "returning " << ranges.size() << " ranges" << endl;
470 #endif 470 #endif
545 545
546 void 546 void
547 ReadOnlyWaveFileModel::fillTimerTimedOut() 547 ReadOnlyWaveFileModel::fillTimerTimedOut()
548 { 548 {
549 if (m_fillThread) { 549 if (m_fillThread) {
550 sv_frame_t fillExtent = m_fillThread->getFillExtent(); 550 sv_frame_t fillExtent = m_fillThread->getFillExtent();
551 #ifdef DEBUG_WAVE_FILE_MODEL 551 #ifdef DEBUG_WAVE_FILE_MODEL
552 SVDEBUG << "ReadOnlyWaveFileModel::fillTimerTimedOut: extent = " << fillExtent << endl; 552 SVDEBUG << "ReadOnlyWaveFileModel::fillTimerTimedOut: extent = " << fillExtent << endl;
553 #endif 553 #endif
554 if (fillExtent > m_lastFillExtent) { 554 if (fillExtent > m_lastFillExtent) {
555 emit modelChangedWithin(m_lastFillExtent, fillExtent); 555 emit modelChangedWithin(m_lastFillExtent, fillExtent);
556 m_lastFillExtent = fillExtent; 556 m_lastFillExtent = fillExtent;
557 } 557 }
558 } else { 558 } else {
559 #ifdef DEBUG_WAVE_FILE_MODEL 559 #ifdef DEBUG_WAVE_FILE_MODEL
560 SVDEBUG << "ReadOnlyWaveFileModel::fillTimerTimedOut: no thread" << endl; 560 SVDEBUG << "ReadOnlyWaveFileModel::fillTimerTimedOut: no thread" << endl;
561 #endif 561 #endif
562 emit modelChanged(); 562 emit modelChanged();
563 } 563 }
564 } 564 }
565 565
566 void 566 void
567 ReadOnlyWaveFileModel::cacheFilled() 567 ReadOnlyWaveFileModel::cacheFilled()
644 sv_frame_t gotBlockSize = block.size() / channels; 644 sv_frame_t gotBlockSize = block.size() / channels;
645 645
646 m_model.m_mutex.lock(); 646 m_model.m_mutex.lock();
647 647
648 for (sv_frame_t i = 0; i < gotBlockSize; ++i) { 648 for (sv_frame_t i = 0; i < gotBlockSize; ++i) {
649 649
650 for (int ch = 0; ch < channels; ++ch) { 650 for (int ch = 0; ch < channels; ++ch) {
651 651
652 sv_frame_t index = channels * i + ch; 652 sv_frame_t index = channels * i + ch;
653 float sample = block[index]; 653 float sample = block[index];
654 654