comparison data/fft/FFTDataServer.cpp @ 1038:cc27f35aa75c cxx11

Introducing the signed 64-bit frame index type, and fixing build failures from inclusion of -Wconversion with -Werror. Not finished yet.
author Chris Cannam
date Tue, 03 Mar 2015 15:18:24 +0000
parents e8e6c4e7437b
children 1a73618b0b67
comparison
equal deleted inserted replaced
1037:bf0e5944289b 1038:cc27f35aa75c
27 #include "base/Exceptions.h" 27 #include "base/Exceptions.h"
28 #include "base/Profiler.h" 28 #include "base/Profiler.h"
29 #include "base/Thread.h" // for debug mutex locker 29 #include "base/Thread.h" // for debug mutex locker
30 30
31 #include <QWriteLocker> 31 #include <QWriteLocker>
32
33 #include <stdexcept>
32 34
33 //#define DEBUG_FFT_SERVER 1 35 //#define DEBUG_FFT_SERVER 1
34 //#define DEBUG_FFT_SERVER_FILL 1 36 //#define DEBUG_FFT_SERVER_FILL 1
35 37
36 #ifdef DEBUG_FFT_SERVER_FILL 38 #ifdef DEBUG_FFT_SERVER_FILL
512 cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "])::FFTDataServer" << endl; 514 cerr << "FFTDataServer(" << this << " [" << (void *)QThread::currentThreadId() << "])::FFTDataServer" << endl;
513 #endif 515 #endif
514 516
515 //!!! end is not correct until model finished reading -- what to do??? 517 //!!! end is not correct until model finished reading -- what to do???
516 518
517 int start = m_model->getStartFrame(); 519 sv_frame_t start = m_model->getStartFrame();
518 int end = m_model->getEndFrame(); 520 sv_frame_t end = m_model->getEndFrame();
519 521
520 m_width = (end - start) / m_windowIncrement + 1; 522 m_width = int((end - start) / m_windowIncrement) + 1;
521 m_height = m_fftSize / 2 + 1; // DC == 0, Nyquist == fftsize/2 523 m_height = m_fftSize / 2 + 1; // DC == 0, Nyquist == fftsize/2
522 524
523 #ifdef DEBUG_FFT_SERVER 525 #ifdef DEBUG_FFT_SERVER
524 cerr << "FFTDataServer(" << this << "): dimensions are " 526 cerr << "FFTDataServer(" << this << "): dimensions are "
525 << m_width << "x" << m_height << endl; 527 << m_width << "x" << m_height << endl;
526 #endif 528 #endif
527 529
528 int maxCacheSize = 20 * 1024 * 1024; 530 int maxCacheSize = 20 * 1024 * 1024;
529 int columnSize = m_height * sizeof(fftsample) * 2 + sizeof(fftsample); 531 int columnSize = int(m_height * sizeof(fftsample) * 2 + sizeof(fftsample));
530 if (m_width * columnSize < maxCacheSize * 2) m_cacheWidth = m_width; 532 if (m_width * columnSize < maxCacheSize * 2) m_cacheWidth = m_width;
531 else m_cacheWidth = maxCacheSize / columnSize; 533 else m_cacheWidth = maxCacheSize / columnSize;
532 534
533 #ifdef DEBUG_FFT_SERVER 535 #ifdef DEBUG_FFT_SERVER
534 cerr << "FFTDataServer(" << this << "): cache width nominal " 536 cerr << "FFTDataServer(" << this << "): cache width nominal "
679 681
680 void 682 void
681 FFTDataServer::getStorageAdvice(int w, int h, 683 FFTDataServer::getStorageAdvice(int w, int h,
682 bool &memoryCache, bool &compactCache) 684 bool &memoryCache, bool &compactCache)
683 { 685 {
684 int cells = w * h; 686 if (w < 0 || h < 0) throw std::domain_error("width & height must be non-negative");
685 int minimumSize = (cells / 1024) * sizeof(uint16_t); // kb 687 size_t cells = size_t(w) * h;
686 int maximumSize = (cells / 1024) * sizeof(float); // kb 688 size_t minimumSize = (cells / 1024) * sizeof(uint16_t); // kb
689 size_t maximumSize = (cells / 1024) * sizeof(float); // kb
687 690
688 // We don't have a compact rectangular representation, and compact 691 // We don't have a compact rectangular representation, and compact
689 // of course is never precision-critical 692 // of course is never precision-critical
690 693
691 bool canCompact = true; 694 bool canCompact = true;
1246 1249
1247 int winsize = m_windowSize; 1250 int winsize = m_windowSize;
1248 int fftsize = m_fftSize; 1251 int fftsize = m_fftSize;
1249 int hs = fftsize/2; 1252 int hs = fftsize/2;
1250 1253
1251 int pfx = 0; 1254 sv_frame_t pfx = 0;
1252 int off = (fftsize - winsize) / 2; 1255 int off = (fftsize - winsize) / 2;
1253 1256
1254 int startFrame = m_windowIncrement * x; 1257 sv_frame_t startFrame = m_windowIncrement * sv_frame_t(x);
1255 int endFrame = startFrame + m_windowSize; 1258 sv_frame_t endFrame = startFrame + m_windowSize;
1256 1259
1257 startFrame -= winsize / 2; 1260 startFrame -= winsize / 2;
1258 endFrame -= winsize / 2; 1261 endFrame -= winsize / 2;
1259 1262
1260 #ifdef DEBUG_FFT_SERVER_FILL 1263 #ifdef DEBUG_FFT_SERVER_FILL
1298 for (int i = 0; i < pfx; ++i) { 1301 for (int i = 0; i < pfx; ++i) {
1299 m_fftInput[off + i] = 0.0; 1302 m_fftInput[off + i] = 0.0;
1300 } 1303 }
1301 } 1304 }
1302 1305
1303 int count = 0; 1306 sv_frame_t count = 0;
1304 if (endFrame > startFrame + pfx) count = endFrame - (startFrame + pfx); 1307 if (endFrame > startFrame + pfx) count = endFrame - (startFrame + pfx);
1305 1308
1306 int got = m_model->getData(m_channel, startFrame + pfx, 1309 sv_frame_t got = m_model->getData(m_channel, startFrame + pfx,
1307 count, m_fftInput + off + pfx); 1310 count, m_fftInput + off + pfx);
1308 1311
1309 while (got + pfx < winsize) { 1312 while (got + pfx < winsize) {
1310 m_fftInput[off + got + pfx] = 0.0; 1313 m_fftInput[off + got + pfx] = 0.0;
1311 ++got; 1314 ++got;
1312 } 1315 }
1313 1316
1314 if (m_channel == -1) { 1317 if (m_channel == -1) {
1315 int channels = m_model->getChannelCount(); 1318 int channels = m_model->getChannelCount();
1316 if (channels > 1) { 1319 if (channels > 1) {
1317 for (int i = 0; i < winsize; ++i) { 1320 for (int i = 0; i < winsize; ++i) {
1318 m_fftInput[off + i] /= channels; 1321 m_fftInput[off + i] /= float(channels);
1319 } 1322 }
1320 } 1323 }
1321 } 1324 }
1322 1325
1323 m_windower.cut(m_fftInput + off); 1326 m_windower.cut(m_fftInput + off);
1402 { 1405 {
1403 if (m_fillThread) return m_fillThread->getCompletion(); 1406 if (m_fillThread) return m_fillThread->getCompletion();
1404 else return 100; 1407 else return 100;
1405 } 1408 }
1406 1409
1407 int 1410 sv_frame_t
1408 FFTDataServer::getFillExtent() const 1411 FFTDataServer::getFillExtent() const
1409 { 1412 {
1410 if (m_fillThread) return m_fillThread->getExtent(); 1413 if (m_fillThread) return m_fillThread->getExtent();
1411 else return m_model->getEndFrame(); 1414 else return m_model->getEndFrame();
1412 } 1415 }
1454 #endif 1457 #endif
1455 sleep(1); 1458 sleep(1);
1456 } 1459 }
1457 if (m_server.m_exiting) return; 1460 if (m_server.m_exiting) return;
1458 1461
1459 int start = m_server.m_model->getStartFrame(); 1462 sv_frame_t start = m_server.m_model->getStartFrame();
1460 int end = m_server.m_model->getEndFrame(); 1463 sv_frame_t end = m_server.m_model->getEndFrame();
1461 int remainingEnd = end; 1464 sv_frame_t remainingEnd = end;
1462 1465
1463 int counter = 0; 1466 int counter = 0;
1464 int updateAt = 1; 1467 int updateAt = 1;
1465 int maxUpdateAt = (end / m_server.m_windowIncrement) / 20; 1468 int maxUpdateAt = int(end / m_server.m_windowIncrement) / 20;
1466 if (maxUpdateAt < 100) maxUpdateAt = 100; 1469 if (maxUpdateAt < 100) maxUpdateAt = 100;
1467 1470
1468 if (m_fillFrom > start) { 1471 if (m_fillFrom > start) {
1469 1472
1470 for (int f = m_fillFrom; f < end; f += m_server.m_windowIncrement) { 1473 for (sv_frame_t f = m_fillFrom; f < end; f += m_server.m_windowIncrement) {
1471 1474
1472 try { 1475 try {
1473 m_server.fillColumn(int((f - start) / m_server.m_windowIncrement)); 1476 m_server.fillColumn(int((f - start) / m_server.m_windowIncrement));
1474 } catch (std::exception &e) { 1477 } catch (std::exception &e) {
1475 std::cerr << "FFTDataServer::FillThread::run: exception: " << e.what() << std::endl; 1478 std::cerr << "FFTDataServer::FillThread::run: exception: " << e.what() << std::endl;
1514 else remainingEnd = start; 1517 else remainingEnd = start;
1515 } 1518 }
1516 1519
1517 int baseCompletion = m_completion; 1520 int baseCompletion = m_completion;
1518 1521
1519 for (int f = start; f < remainingEnd; f += m_server.m_windowIncrement) { 1522 for (sv_frame_t f = start; f < remainingEnd; f += m_server.m_windowIncrement) {
1520 1523
1521 try { 1524 try {
1522 m_server.fillColumn(int((f - start) / m_server.m_windowIncrement)); 1525 m_server.fillColumn(int((f - start) / m_server.m_windowIncrement));
1523 } catch (std::exception &e) { 1526 } catch (std::exception &e) {
1524 std::cerr << "FFTDataServer::FillThread::run: exception: " << e.what() << std::endl; 1527 std::cerr << "FFTDataServer::FillThread::run: exception: " << e.what() << std::endl;