comparison data/model/ReadOnlyWaveFileModel.cpp @ 1809:73447d746db3

Comments and debug-related bits
author Chris Cannam
date Tue, 29 Oct 2019 12:46:43 +0000
parents 6d09d68165a4
children 14747f24ad04
comparison
equal deleted inserted replaced
1808:871a2050236b 1809:73447d746db3
33 #include <cassert> 33 #include <cassert>
34 34
35 using namespace std; 35 using namespace std;
36 36
37 //#define DEBUG_WAVE_FILE_MODEL 1 37 //#define DEBUG_WAVE_FILE_MODEL 1
38 //#define DEBUG_WAVE_FILE_MODEL_READ 1
38 39
39 PowerOfSqrtTwoZoomConstraint 40 PowerOfSqrtTwoZoomConstraint
40 ReadOnlyWaveFileModel::m_zoomConstraint; 41 ReadOnlyWaveFileModel::m_zoomConstraint;
41 42
42 ReadOnlyWaveFileModel::ReadOnlyWaveFileModel(FileSource source, sv_samplerate_t targetRate) : 43 ReadOnlyWaveFileModel::ReadOnlyWaveFileModel(FileSource source, sv_samplerate_t targetRate) :
163 m_prevCompletion = *completion; 164 m_prevCompletion = *completion;
164 } 165 }
165 166
166 #ifdef DEBUG_WAVE_FILE_MODEL 167 #ifdef DEBUG_WAVE_FILE_MODEL
167 if (completion) { 168 if (completion) {
168 SVDEBUG << "ReadOnlyWaveFileModel(" << objectName() << ")::isReady(): ready = " << ready << ", m_fillThread = " << m_fillThread << ", m_lastFillExtent = " << m_lastFillExtent << ", end frame = " << getEndFrame() << ", start frame = " << getStartFrame() << ", c = " << c << ", completion = " << *completion << endl; 169 SVCERR << "ReadOnlyWaveFileModel(" << objectName() << ")::isReady(): ready = " << ready << ", m_fillThread = " << m_fillThread << ", m_lastFillExtent = " << m_lastFillExtent << ", end frame = " << getEndFrame() << ", start frame = " << getStartFrame() << ", c = " << c << ", completion = " << *completion << endl;
169 } else { 170 } else {
170 SVDEBUG << "ReadOnlyWaveFileModel(" << objectName() << ")::isReady(): ready = " << ready << ", m_fillThread = " << m_fillThread << ", m_lastFillExtent = " << m_lastFillExtent << ", end frame = " << getEndFrame() << ", start frame = " << getStartFrame() << ", c = " << c << ", completion not requested" << endl; 171 SVCERR << "ReadOnlyWaveFileModel(" << objectName() << ")::isReady(): ready = " << ready << ", m_fillThread = " << m_fillThread << ", m_lastFillExtent = " << m_lastFillExtent << ", end frame = " << getEndFrame() << ", start frame = " << getStartFrame() << ", c = " << c << ", completion not requested" << endl;
171 } 172 }
172 #endif 173 #endif
173 return ready; 174 return ready;
174 } 175 }
175 176
227 } 228 }
228 229
229 QString 230 QString
230 ReadOnlyWaveFileModel::getLocalFilename() const 231 ReadOnlyWaveFileModel::getLocalFilename() const
231 { 232 {
233 #ifdef DEBUG_WAVE_FILE_MODEL
234 SVCERR << "ReadOnlyWaveFileModel::getLocalFilename: reader is "
235 << m_reader << ", returning "
236 << (m_reader ? m_reader->getLocalFilename() : "(none)") << endl;
237 #endif
232 if (m_reader) return m_reader->getLocalFilename(); 238 if (m_reader) return m_reader->getLocalFilename();
233 return ""; 239 return "";
234 } 240 }
235 241
236 floatvec_t 242 floatvec_t
243 // channels (if channel == -1) directly from the file. This is 249 // channels (if channel == -1) directly from the file. This is
244 // used for e.g. audio playback or input to transforms. 250 // used for e.g. audio playback or input to transforms.
245 251
246 Profiler profiler("ReadOnlyWaveFileModel::getData"); 252 Profiler profiler("ReadOnlyWaveFileModel::getData");
247 253
248 #ifdef DEBUG_WAVE_FILE_MODEL 254 #ifdef DEBUG_WAVE_FILE_MODEL_READ
249 cout << "ReadOnlyWaveFileModel::getData[" << this << "]: " << channel << ", " << start << ", " << count << endl; 255 cout << "ReadOnlyWaveFileModel::getData[" << this << "]: " << channel << ", " << start << ", " << count << endl;
250 #endif 256 #endif
251 257
252 int channels = getChannelCount(); 258 int channels = getChannelCount();
253 259
304 // Read a set of channels directly from the file. This is used 310 // Read a set of channels directly from the file. This is used
305 // for e.g. audio playback or input to transforms. 311 // for e.g. audio playback or input to transforms.
306 312
307 Profiler profiler("ReadOnlyWaveFileModel::getMultiChannelData"); 313 Profiler profiler("ReadOnlyWaveFileModel::getMultiChannelData");
308 314
309 #ifdef DEBUG_WAVE_FILE_MODEL 315 #ifdef DEBUG_WAVE_FILE_MODEL_READ
310 cout << "ReadOnlyWaveFileModel::getData[" << this << "]: " << fromchannel << "," << tochannel << ", " << start << ", " << count << endl; 316 cout << "ReadOnlyWaveFileModel::getData[" << this << "]: " << fromchannel << "," << tochannel << ", " << start << ", " << count << endl;
311 #endif 317 #endif
312 318
313 int channels = getChannelCount(); 319 int channels = getChannelCount();
314 320
472 sv_frame_t endIndex = (start + count) / cacheBlock; 478 sv_frame_t endIndex = (start + count) / cacheBlock;
473 479
474 float max = 0.0, min = 0.0, total = 0.0; 480 float max = 0.0, min = 0.0, total = 0.0;
475 sv_frame_t i = 0, got = 0; 481 sv_frame_t i = 0, got = 0;
476 482
477 #ifdef DEBUG_WAVE_FILE_MODEL 483 #ifdef DEBUG_WAVE_FILE_MODEL_READ
478 cerr << "blockSize is " << blockSize << ", cacheBlock " << cacheBlock << ", start " << start << ", count " << count << " (frame count " << getFrameCount() << "), power is " << power << ", div is " << div << ", startIndex " << startIndex << ", endIndex " << endIndex << endl; 484 cerr << "blockSize is " << blockSize << ", cacheBlock " << cacheBlock << ", start " << start << ", count " << count << " (frame count " << getFrameCount() << "), power is " << power << ", div is " << div << ", startIndex " << startIndex << ", endIndex " << endIndex << endl;
479 #endif 485 #endif
480 486
481 for (i = 0; i <= endIndex - startIndex; ) { 487 for (i = 0; i <= endIndex - startIndex; ) {
482 488
501 if (got > 0) { 507 if (got > 0) {
502 ranges.push_back(Range(min, max, total / float(got))); 508 ranges.push_back(Range(min, max, total / float(got)));
503 } 509 }
504 } 510 }
505 511
506 #ifdef DEBUG_WAVE_FILE_MODEL 512 #ifdef DEBUG_WAVE_FILE_MODEL_READ
507 cerr << "returning " << ranges.size() << " ranges" << endl; 513 cerr << "returning " << ranges.size() << " ranges" << endl;
508 #endif 514 #endif
509 return; 515 return;
510 } 516 }
511 517
575 581
576 m_mutex.unlock(); 582 m_mutex.unlock();
577 m_fillThread->start(); 583 m_fillThread->start();
578 584
579 #ifdef DEBUG_WAVE_FILE_MODEL 585 #ifdef DEBUG_WAVE_FILE_MODEL
580 SVDEBUG << "ReadOnlyWaveFileModel(" << objectName() << ")::fillCache: started fill thread" << endl; 586 SVCERR << "ReadOnlyWaveFileModel(" << objectName() << ")::fillCache: started fill thread" << endl;
581 #endif 587 #endif
582 } 588 }
583 589
584 void 590 void
585 ReadOnlyWaveFileModel::fillTimerTimedOut() 591 ReadOnlyWaveFileModel::fillTimerTimedOut()
586 { 592 {
587 if (m_fillThread) { 593 if (m_fillThread) {
588 sv_frame_t fillExtent = m_fillThread->getFillExtent(); 594 sv_frame_t fillExtent = m_fillThread->getFillExtent();
589 #ifdef DEBUG_WAVE_FILE_MODEL 595 #ifdef DEBUG_WAVE_FILE_MODEL
590 SVDEBUG << "ReadOnlyWaveFileModel(" << objectName() << ")::fillTimerTimedOut: extent = " << fillExtent << endl; 596 SVCERR << "ReadOnlyWaveFileModel(" << objectName() << ")::fillTimerTimedOut: extent = " << fillExtent << endl;
591 #endif 597 #endif
592 if (fillExtent > m_lastFillExtent) { 598 if (fillExtent > m_lastFillExtent) {
593 emit modelChangedWithin(getId(), m_lastFillExtent, fillExtent); 599 emit modelChangedWithin(getId(), m_lastFillExtent, fillExtent);
594 m_lastFillExtent = fillExtent; 600 m_lastFillExtent = fillExtent;
595 } 601 }
596 } else { 602 } else {
597 #ifdef DEBUG_WAVE_FILE_MODEL 603 #ifdef DEBUG_WAVE_FILE_MODEL
598 SVDEBUG << "ReadOnlyWaveFileModel(" << objectName() << ")::fillTimerTimedOut: no thread" << endl; 604 SVCERR << "ReadOnlyWaveFileModel(" << objectName() << ")::fillTimerTimedOut: no thread" << endl;
599 #endif 605 #endif
600 emit modelChanged(getId()); 606 emit modelChanged(getId());
601 } 607 }
602 } 608 }
603 609
611 m_updateTimer = nullptr; 617 m_updateTimer = nullptr;
612 auto prevFillExtent = m_lastFillExtent; 618 auto prevFillExtent = m_lastFillExtent;
613 m_lastFillExtent = getEndFrame(); 619 m_lastFillExtent = getEndFrame();
614 m_mutex.unlock(); 620 m_mutex.unlock();
615 #ifdef DEBUG_WAVE_FILE_MODEL 621 #ifdef DEBUG_WAVE_FILE_MODEL
616 SVDEBUG << "ReadOnlyWaveFileModel(" << objectName() << ")::cacheFilled, about to emit things" << endl; 622 SVCERR << "ReadOnlyWaveFileModel(" << objectName() << ")::cacheFilled, about to emit things" << endl;
617 #endif 623 #endif
618 if (getEndFrame() > prevFillExtent) { 624 if (getEndFrame() > prevFillExtent) {
619 emit modelChangedWithin(getId(), prevFillExtent, getEndFrame()); 625 emit modelChangedWithin(getId(), prevFillExtent, getEndFrame());
620 } 626 }
621 emit modelChanged(getId()); 627 emit modelChanged(getId());
640 bool updating = m_model.m_reader->isUpdating(); 646 bool updating = m_model.m_reader->isUpdating();
641 647
642 if (updating) { 648 if (updating) {
643 while (channels == 0 && !m_model.m_exiting) { 649 while (channels == 0 && !m_model.m_exiting) {
644 #ifdef DEBUG_WAVE_FILE_MODEL 650 #ifdef DEBUG_WAVE_FILE_MODEL
645 cerr << "ReadOnlyWaveFileModel(" << objectName() << ")::fill: Waiting for channels..." << endl; 651 SVCERR << "ReadOnlyWaveFileModel(" << objectName() << ")::fill: Waiting for channels..." << endl;
646 #endif 652 #endif
647 sleep(1); 653 sleep(1);
648 channels = m_model.getChannelCount(); 654 channels = m_model.getChannelCount();
649 } 655 }
650 } 656 }
668 674
669 while (frame < m_frameCount) { 675 while (frame < m_frameCount) {
670 676
671 m_model.m_mutex.unlock(); 677 m_model.m_mutex.unlock();
672 678
673 #ifdef DEBUG_WAVE_FILE_MODEL 679 #ifdef DEBUG_WAVE_FILE_MODEL_READ
674 SVDEBUG << "ReadOnlyWaveFileModel(" << m_model.objectName() << ")::fill inner loop: frame = " << frame << ", count = " << m_frameCount << ", blocksize " << readBlockSize << endl; 680 cout << "ReadOnlyWaveFileModel(" << m_model.objectName() << ")::fill inner loop: frame = " << frame << ", count = " << m_frameCount << ", blocksize " << readBlockSize << endl;
675 #endif 681 #endif
676 682
677 if (updating && (frame + readBlockSize > m_frameCount)) { 683 if (updating && (frame + readBlockSize > m_frameCount)) {
678 m_model.m_mutex.lock(); // must be locked on exiting loop 684 m_model.m_mutex.lock(); // must be locked on exiting loop
679 break; 685 break;
762 768
763 m_fillExtent = m_frameCount; 769 m_fillExtent = m_frameCount;
764 770
765 #ifdef DEBUG_WAVE_FILE_MODEL 771 #ifdef DEBUG_WAVE_FILE_MODEL
766 for (int cacheType = 0; cacheType < 2; ++cacheType) { 772 for (int cacheType = 0; cacheType < 2; ++cacheType) {
767 SVDEBUG << "ReadOnlyWaveFileModel(" << m_model.objectName() << "): Cache type " << cacheType << " now contains " << m_model.m_cache[cacheType].size() << " ranges" << endl; 773 SVCERR << "ReadOnlyWaveFileModel(" << m_model.objectName() << "): Cache type " << cacheType << " now contains " << m_model.m_cache[cacheType].size() << " ranges" << endl;
768 } 774 }
769 #endif 775 #endif
770 } 776 }
771 777
772 void 778 void