comparison data/fft/FFTDataServer.cpp @ 183:146eb9e35baa

* Improve output from Profiler class and make it incur less (no) overhead in release builds with NO_TIMING defined * Fix a lock contention issue in spectrogram * Marginal optimisations elsewhere
author Chris Cannam
date Tue, 10 Oct 2006 14:51:17 +0000
parents a2a8a2b6653a
children bf1f256864de
comparison
equal deleted inserted replaced
182:f75f8a1cd7b1 183:146eb9e35baa
21 #include "model/DenseTimeValueModel.h" 21 #include "model/DenseTimeValueModel.h"
22 22
23 #include "system/System.h" 23 #include "system/System.h"
24 24
25 #include "base/StorageAdviser.h" 25 #include "base/StorageAdviser.h"
26 #include "base/Profiler.h"
26 27
27 28
28 #define DEBUG_FFT_SERVER 1 29 #define DEBUG_FFT_SERVER 1
29 //#define DEBUG_FFT_SERVER_FILL 1 30 //#define DEBUG_FFT_SERVER_FILL 1
30 31
311 m_windower(windowType, windowSize), 312 m_windower(windowType, windowSize),
312 m_windowSize(windowSize), 313 m_windowSize(windowSize),
313 m_windowIncrement(windowIncrement), 314 m_windowIncrement(windowIncrement),
314 m_fftSize(fftSize), 315 m_fftSize(fftSize),
315 m_polar(polar), 316 m_polar(polar),
317 m_width(0),
318 m_height(0),
319 m_cacheWidth(0),
316 m_memoryCache(false), 320 m_memoryCache(false),
317 m_compactCache(false), 321 m_compactCache(false),
318 m_lastUsedCache(-1), 322 m_lastUsedCache(-1),
319 m_fftInput(0), 323 m_fftInput(0),
320 m_exiting(false), 324 m_exiting(false),
437 FFTDataServer::suspend() 441 FFTDataServer::suspend()
438 { 442 {
439 #ifdef DEBUG_FFT_SERVER 443 #ifdef DEBUG_FFT_SERVER
440 std::cerr << "FFTDataServer(" << this << "): suspend" << std::endl; 444 std::cerr << "FFTDataServer(" << this << "): suspend" << std::endl;
441 #endif 445 #endif
446 Profiler profiler("FFTDataServer::suspend", false);
447
442 QMutexLocker locker(&m_writeMutex); 448 QMutexLocker locker(&m_writeMutex);
443 m_suspended = true; 449 m_suspended = true;
444 for (CacheVector::iterator i = m_caches.begin(); i != m_caches.end(); ++i) { 450 for (CacheVector::iterator i = m_caches.begin(); i != m_caches.end(); ++i) {
445 if (*i) (*i)->suspend(); 451 if (*i) (*i)->suspend();
446 } 452 }
450 FFTDataServer::suspendWrites() 456 FFTDataServer::suspendWrites()
451 { 457 {
452 #ifdef DEBUG_FFT_SERVER 458 #ifdef DEBUG_FFT_SERVER
453 std::cerr << "FFTDataServer(" << this << "): suspendWrites" << std::endl; 459 std::cerr << "FFTDataServer(" << this << "): suspendWrites" << std::endl;
454 #endif 460 #endif
461 Profiler profiler("FFTDataServer::suspendWrites", false);
462
455 m_suspended = true; 463 m_suspended = true;
456 } 464 }
457 465
458 void 466 void
459 FFTDataServer::resume() 467 FFTDataServer::resume()
460 { 468 {
461 #ifdef DEBUG_FFT_SERVER 469 #ifdef DEBUG_FFT_SERVER
462 std::cerr << "FFTDataServer(" << this << "): resume" << std::endl; 470 std::cerr << "FFTDataServer(" << this << "): resume" << std::endl;
463 #endif 471 #endif
472 Profiler profiler("FFTDataServer::resume", false);
473
464 m_suspended = false; 474 m_suspended = false;
465 if (m_fillThread) { 475 if (m_fillThread) {
466 if (m_fillThread->isFinished()) { 476 if (m_fillThread->isFinished()) {
467 delete m_fillThread; 477 delete m_fillThread;
468 m_fillThread = 0; 478 m_fillThread = 0;
474 } 484 }
475 485
476 FFTCache * 486 FFTCache *
477 FFTDataServer::getCacheAux(size_t c) 487 FFTDataServer::getCacheAux(size_t c)
478 { 488 {
489 Profiler profiler("FFTDataServer::getCacheAux", false);
490
479 QMutexLocker locker(&m_writeMutex); 491 QMutexLocker locker(&m_writeMutex);
480 492
481 if (m_lastUsedCache == -1) { 493 if (m_lastUsedCache == -1) {
482 m_fillThread->start(); 494 m_fillThread->start();
483 } 495 }
555 } 567 }
556 568
557 float 569 float
558 FFTDataServer::getMagnitudeAt(size_t x, size_t y) 570 FFTDataServer::getMagnitudeAt(size_t x, size_t y)
559 { 571 {
572 Profiler profiler("FFTDataServer::getMagnitudeAt", false);
573
560 size_t col; 574 size_t col;
561 FFTCache *cache = getCache(x, col); 575 FFTCache *cache = getCache(x, col);
562 576
563 if (!cache->haveSetColumnAt(col)) { 577 if (!cache->haveSetColumnAt(col)) {
578 std::cerr << "FFTDataServer::getMagnitudeAt: calling fillColumn("
579 << x << ")" << std::endl;
564 fillColumn(x); 580 fillColumn(x);
565 } 581 }
566 return cache->getMagnitudeAt(col, y); 582 return cache->getMagnitudeAt(col, y);
567 } 583 }
568 584
569 float 585 float
570 FFTDataServer::getNormalizedMagnitudeAt(size_t x, size_t y) 586 FFTDataServer::getNormalizedMagnitudeAt(size_t x, size_t y)
571 { 587 {
588 Profiler profiler("FFTDataServer::getNormalizedMagnitudeAt", false);
589
572 size_t col; 590 size_t col;
573 FFTCache *cache = getCache(x, col); 591 FFTCache *cache = getCache(x, col);
574 592
575 if (!cache->haveSetColumnAt(col)) { 593 if (!cache->haveSetColumnAt(col)) {
576 fillColumn(x); 594 fillColumn(x);
579 } 597 }
580 598
581 float 599 float
582 FFTDataServer::getMaximumMagnitudeAt(size_t x) 600 FFTDataServer::getMaximumMagnitudeAt(size_t x)
583 { 601 {
602 Profiler profiler("FFTDataServer::getMaximumMagnitudeAt", false);
603
584 size_t col; 604 size_t col;
585 FFTCache *cache = getCache(x, col); 605 FFTCache *cache = getCache(x, col);
586 606
587 if (!cache->haveSetColumnAt(col)) { 607 if (!cache->haveSetColumnAt(col)) {
588 fillColumn(x); 608 fillColumn(x);
591 } 611 }
592 612
593 float 613 float
594 FFTDataServer::getPhaseAt(size_t x, size_t y) 614 FFTDataServer::getPhaseAt(size_t x, size_t y)
595 { 615 {
616 Profiler profiler("FFTDataServer::getPhaseAt", false);
617
596 size_t col; 618 size_t col;
597 FFTCache *cache = getCache(x, col); 619 FFTCache *cache = getCache(x, col);
598 620
599 if (!cache->haveSetColumnAt(col)) { 621 if (!cache->haveSetColumnAt(col)) {
600 fillColumn(x); 622 fillColumn(x);
603 } 625 }
604 626
605 void 627 void
606 FFTDataServer::getValuesAt(size_t x, size_t y, float &real, float &imaginary) 628 FFTDataServer::getValuesAt(size_t x, size_t y, float &real, float &imaginary)
607 { 629 {
630 Profiler profiler("FFTDataServer::getValuesAt", false);
631
608 size_t col; 632 size_t col;
609 FFTCache *cache = getCache(x, col); 633 FFTCache *cache = getCache(x, col);
610 634
611 if (!cache->haveSetColumnAt(col)) { 635 if (!cache->haveSetColumnAt(col)) {
612 #ifdef DEBUG_FFT_SERVER 636 #ifdef DEBUG_FFT_SERVER
621 } 645 }
622 646
623 bool 647 bool
624 FFTDataServer::isColumnReady(size_t x) 648 FFTDataServer::isColumnReady(size_t x)
625 { 649 {
650 Profiler profiler("FFTDataServer::isColumnReady", false);
651
626 if (!haveCache(x)) { 652 if (!haveCache(x)) {
627 if (m_lastUsedCache == -1) { 653 if (m_lastUsedCache == -1) {
628 if (m_suspended) resume(); 654 if (m_suspended) {
655 std::cerr << "FFTDataServer::isColumnReady(" << x << "): no cache, calling resume" << std::endl;
656 resume();
657 }
629 m_fillThread->start(); 658 m_fillThread->start();
630 } 659 }
631 return false; 660 return false;
632 } 661 }
633 662
638 } 667 }
639 668
640 void 669 void
641 FFTDataServer::fillColumn(size_t x) 670 FFTDataServer::fillColumn(size_t x)
642 { 671 {
672 Profiler profiler("FFTDataServer::fillColumn", false);
673
643 size_t col; 674 size_t col;
644 #ifdef DEBUG_FFT_SERVER_FILL 675 #ifdef DEBUG_FFT_SERVER_FILL
645 std::cout << "FFTDataServer::fillColumn(" << x << ")" << std::endl; 676 std::cout << "FFTDataServer::fillColumn(" << x << ")" << std::endl;
646 #endif 677 #endif
647 FFTCache *cache = getCache(x, col); 678 FFTCache *cache = getCache(x, col);
718 cache->setColumnAt(col, 749 cache->setColumnAt(col,
719 m_workbuffer, 750 m_workbuffer,
720 m_workbuffer + m_fftSize/2, 751 m_workbuffer + m_fftSize/2,
721 factor); 752 factor);
722 753
723 if (m_suspended) resume(); 754 if (m_suspended) {
755 // std::cerr << "FFTDataServer::fillColumn(" << x << "): calling resume" << std::endl;
756 // resume();
757 }
724 } 758 }
725 759
726 size_t 760 size_t
727 FFTDataServer::getFillCompletion() const 761 FFTDataServer::getFillCompletion() const
728 { 762 {