Mercurial > hg > svcore
comparison data/fft/FFTDataServer.cpp @ 193:bf1f256864de
* A start to a panner widget to go with thumbwheels
author | Chris Cannam |
---|---|
date | Wed, 18 Oct 2006 16:38:30 +0000 |
parents | 146eb9e35baa |
children | 10e897e6dcba |
comparison
equal
deleted
inserted
replaced
192:900ac6667eab | 193:bf1f256864de |
---|---|
25 #include "base/StorageAdviser.h" | 25 #include "base/StorageAdviser.h" |
26 #include "base/Profiler.h" | 26 #include "base/Profiler.h" |
27 | 27 |
28 | 28 |
29 #define DEBUG_FFT_SERVER 1 | 29 #define DEBUG_FFT_SERVER 1 |
30 //#define DEBUG_FFT_SERVER_FILL 1 | 30 #define DEBUG_FFT_SERVER_FILL 1 |
31 | 31 |
32 #ifdef DEBUG_FFT_SERVER_FILL | 32 #ifdef DEBUG_FFT_SERVER_FILL |
33 #ifndef DEBUG_FFT_SERVER | 33 #ifndef DEBUG_FFT_SERVER |
34 #define DEBUG_FFT_SERVER 1 | 34 #define DEBUG_FFT_SERVER 1 |
35 #endif | 35 #endif |
323 m_fftInput(0), | 323 m_fftInput(0), |
324 m_exiting(false), | 324 m_exiting(false), |
325 m_suspended(true), //!!! or false? | 325 m_suspended(true), //!!! or false? |
326 m_fillThread(0) | 326 m_fillThread(0) |
327 { | 327 { |
328 #ifdef DEBUG_FFT_SERVER | |
329 std::cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "])::FFTDataServer" << std::endl; | |
330 #endif | |
331 | |
328 size_t start = m_model->getStartFrame(); | 332 size_t start = m_model->getStartFrame(); |
329 size_t end = m_model->getEndFrame(); | 333 size_t end = m_model->getEndFrame(); |
330 | 334 |
331 m_width = (end - start) / m_windowIncrement + 1; | 335 m_width = (end - start) / m_windowIncrement + 1; |
332 m_height = m_fftSize / 2; | 336 m_height = m_fftSize / 2; |
403 } | 407 } |
404 | 408 |
405 FFTDataServer::~FFTDataServer() | 409 FFTDataServer::~FFTDataServer() |
406 { | 410 { |
407 #ifdef DEBUG_FFT_SERVER | 411 #ifdef DEBUG_FFT_SERVER |
408 std::cerr << "FFTDataServer(" << this << ")::~FFTDataServer()" << std::endl; | 412 std::cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "])::~FFTDataServer()" << std::endl; |
409 #endif | 413 #endif |
410 | 414 |
411 m_suspended = false; | 415 m_suspended = false; |
412 m_exiting = true; | 416 m_exiting = true; |
413 m_condition.wakeAll(); | 417 m_condition.wakeAll(); |
426 } | 430 } |
427 | 431 |
428 void | 432 void |
429 FFTDataServer::deleteProcessingData() | 433 FFTDataServer::deleteProcessingData() |
430 { | 434 { |
435 #ifdef DEBUG_FFT_SERVER | |
436 std::cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "]): deleteProcessingData" << std::endl; | |
437 #endif | |
431 if (m_fftInput) { | 438 if (m_fftInput) { |
432 fftwf_destroy_plan(m_fftPlan); | 439 fftwf_destroy_plan(m_fftPlan); |
433 fftwf_free(m_fftInput); | 440 fftwf_free(m_fftInput); |
434 fftwf_free(m_fftOutput); | 441 fftwf_free(m_fftOutput); |
435 fftwf_free(m_workbuffer); | 442 fftwf_free(m_workbuffer); |
439 | 446 |
440 void | 447 void |
441 FFTDataServer::suspend() | 448 FFTDataServer::suspend() |
442 { | 449 { |
443 #ifdef DEBUG_FFT_SERVER | 450 #ifdef DEBUG_FFT_SERVER |
444 std::cerr << "FFTDataServer(" << this << "): suspend" << std::endl; | 451 std::cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "]): suspend" << std::endl; |
445 #endif | 452 #endif |
446 Profiler profiler("FFTDataServer::suspend", false); | 453 Profiler profiler("FFTDataServer::suspend", false); |
447 | 454 |
448 QMutexLocker locker(&m_writeMutex); | 455 QMutexLocker locker(&m_writeMutex); |
449 m_suspended = true; | 456 m_suspended = true; |
454 | 461 |
455 void | 462 void |
456 FFTDataServer::suspendWrites() | 463 FFTDataServer::suspendWrites() |
457 { | 464 { |
458 #ifdef DEBUG_FFT_SERVER | 465 #ifdef DEBUG_FFT_SERVER |
459 std::cerr << "FFTDataServer(" << this << "): suspendWrites" << std::endl; | 466 std::cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "]): suspendWrites" << std::endl; |
460 #endif | 467 #endif |
461 Profiler profiler("FFTDataServer::suspendWrites", false); | 468 Profiler profiler("FFTDataServer::suspendWrites", false); |
462 | 469 |
463 m_suspended = true; | 470 m_suspended = true; |
464 } | 471 } |
465 | 472 |
466 void | 473 void |
467 FFTDataServer::resume() | 474 FFTDataServer::resume() |
468 { | 475 { |
469 #ifdef DEBUG_FFT_SERVER | 476 #ifdef DEBUG_FFT_SERVER |
470 std::cerr << "FFTDataServer(" << this << "): resume" << std::endl; | 477 std::cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "]): resume" << std::endl; |
471 #endif | 478 #endif |
472 Profiler profiler("FFTDataServer::resume", false); | 479 Profiler profiler("FFTDataServer::resume", false); |
473 | 480 |
474 m_suspended = false; | 481 m_suspended = false; |
475 if (m_fillThread) { | 482 if (m_fillThread) { |
485 | 492 |
486 FFTCache * | 493 FFTCache * |
487 FFTDataServer::getCacheAux(size_t c) | 494 FFTDataServer::getCacheAux(size_t c) |
488 { | 495 { |
489 Profiler profiler("FFTDataServer::getCacheAux", false); | 496 Profiler profiler("FFTDataServer::getCacheAux", false); |
497 #ifdef DEBUG_FFT_SERVER | |
498 std::cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "])::getCacheAux" << std::endl; | |
499 #endif | |
490 | 500 |
491 QMutexLocker locker(&m_writeMutex); | 501 QMutexLocker locker(&m_writeMutex); |
492 | 502 |
493 if (m_lastUsedCache == -1) { | 503 if (m_lastUsedCache == -1) { |
494 m_fillThread->start(); | 504 m_fillThread->start(); |
700 for (size_t i = 0; i < pfx; ++i) { | 710 for (size_t i = 0; i < pfx; ++i) { |
701 m_fftInput[off + i] = 0.0; | 711 m_fftInput[off + i] = 0.0; |
702 } | 712 } |
703 } | 713 } |
704 | 714 |
715 std::cerr << "FFTDataServer::fillColumn: requesting frames " | |
716 << startFrame + pfx << " -> " << endFrame << " ( = " | |
717 << endFrame - (startFrame + pfx) << ") at index " | |
718 << off + pfx << " in buffer of size " << m_fftSize | |
719 << " with window size " << m_windowSize | |
720 << " from channel " << m_channel << std::endl; | |
721 | |
705 size_t got = m_model->getValues(m_channel, startFrame + pfx, | 722 size_t got = m_model->getValues(m_channel, startFrame + pfx, |
706 endFrame, m_fftInput + off + pfx); | 723 endFrame, m_fftInput + off + pfx); |
707 | 724 |
708 while (got + pfx < m_windowSize) { | 725 while (got + pfx < m_windowSize) { |
709 m_fftInput[off + got + pfx] = 0.0; | 726 m_fftInput[off + got + pfx] = 0.0; |
824 | 841 |
825 if (m_server.m_exiting) return; | 842 if (m_server.m_exiting) return; |
826 | 843 |
827 while (m_server.m_suspended) { | 844 while (m_server.m_suspended) { |
828 #ifdef DEBUG_FFT_SERVER | 845 #ifdef DEBUG_FFT_SERVER |
829 std::cerr << "FFTDataServer(" << this << "): suspended, waiting..." << std::endl; | 846 std::cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "]): suspended, waiting..." << std::endl; |
830 #endif | 847 #endif |
831 m_server.m_writeMutex.lock(); | 848 m_server.m_writeMutex.lock(); |
832 m_server.m_condition.wait(&m_server.m_writeMutex, 10000); | 849 m_server.m_condition.wait(&m_server.m_writeMutex, 10000); |
833 m_server.m_writeMutex.unlock(); | 850 m_server.m_writeMutex.unlock(); |
834 #ifdef DEBUG_FFT_SERVER | 851 #ifdef DEBUG_FFT_SERVER |
835 std::cerr << "FFTDataServer(" << this << "): waited" << std::endl; | 852 std::cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "]): waited" << std::endl; |
836 #endif | 853 #endif |
837 if (m_server.m_exiting) return; | 854 if (m_server.m_exiting) return; |
838 } | 855 } |
839 | 856 |
840 if (++counter == updateAt) { | 857 if (++counter == updateAt) { |
858 | 875 |
859 if (m_server.m_exiting) return; | 876 if (m_server.m_exiting) return; |
860 | 877 |
861 while (m_server.m_suspended) { | 878 while (m_server.m_suspended) { |
862 #ifdef DEBUG_FFT_SERVER | 879 #ifdef DEBUG_FFT_SERVER |
863 std::cerr << "FFTDataServer(" << this << "): suspended, waiting..." << std::endl; | 880 std::cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "]): suspended, waiting..." << std::endl; |
864 #endif | 881 #endif |
865 m_server.m_writeMutex.lock(); | 882 m_server.m_writeMutex.lock(); |
866 m_server.m_condition.wait(&m_server.m_writeMutex, 10000); | 883 m_server.m_condition.wait(&m_server.m_writeMutex, 10000); |
867 m_server.m_writeMutex.unlock(); | 884 m_server.m_writeMutex.unlock(); |
868 if (m_server.m_exiting) return; | 885 if (m_server.m_exiting) return; |