comparison layer/SpectrogramLayer.cpp @ 1450:6cf3cb6641e1 single-point

Tweak peak-cache allocations etc in the hope of making long spectrograms a little faster to re-render
author Chris Cannam
date Wed, 01 May 2019 14:41:28 +0100
parents e2b6a13a1f69
children 66bf1abfefc1
comparison
equal deleted inserted replaced
1449:ce5f80a7c697 1450:6cf3cb6641e1
1409 } 1409 }
1410 1410
1411 FFTModel *oldModel = m_fftModel; 1411 FFTModel *oldModel = m_fftModel;
1412 m_fftModel = newModel; 1412 m_fftModel = newModel;
1413 1413
1414 if (canStoreWholeCache()) { // i.e. if enough memory 1414 bool createWholeCache = false;
1415 checkCacheSpace(&m_peakCacheDivisor, &createWholeCache);
1416
1417 if (createWholeCache) {
1415 m_wholeCache = new Dense3DModelPeakCache(m_fftModel, 1); 1418 m_wholeCache = new Dense3DModelPeakCache(m_fftModel, 1);
1416 m_peakCache = new Dense3DModelPeakCache(m_wholeCache, m_peakCacheDivisor); 1419 m_peakCache = new Dense3DModelPeakCache(m_wholeCache, m_peakCacheDivisor);
1417 } else { 1420 } else {
1418 m_peakCache = new Dense3DModelPeakCache(m_fftModel, m_peakCacheDivisor); 1421 m_peakCache = new Dense3DModelPeakCache(m_fftModel, m_peakCacheDivisor);
1419 } 1422 }
1420 1423
1421 emit sliceableModelReplaced(oldModel, m_fftModel); 1424 emit sliceableModelReplaced(oldModel, m_fftModel);
1422 delete oldModel; 1425 delete oldModel;
1423 } 1426 }
1424 1427
1425 bool 1428 void
1426 SpectrogramLayer::canStoreWholeCache() const 1429 SpectrogramLayer::checkCacheSpace(int *suggestedPeakDivisor,
1427 { 1430 bool *createWholeCache) const
1428 if (!m_fftModel) { 1431 {
1429 return false; // or true, doesn't really matter 1432 *suggestedPeakDivisor = 8;
1430 } 1433 *createWholeCache = false;
1434
1435 if (!m_fftModel) return;
1431 1436
1432 size_t sz = 1437 size_t sz =
1433 size_t(m_fftModel->getWidth()) * 1438 size_t(m_fftModel->getWidth()) *
1434 size_t(m_fftModel->getHeight()) * 1439 size_t(m_fftModel->getHeight()) *
1435 sizeof(float); 1440 sizeof(float);
1436 1441
1437 try { 1442 try {
1438 SVDEBUG << "Requesting advice from StorageAdviser on whether to create whole-model cache" << endl; 1443 SVDEBUG << "Requesting advice from StorageAdviser on whether to create whole-model cache" << endl;
1444 // The lower amount here is the amount required for the
1445 // slightly higher-resolution version of the peak cache
1446 // without a whole-model cache; the higher amount is that for
1447 // the whole-model cache. The factors of 1024 are because
1448 // StorageAdviser rather stupidly works in kilobytes
1439 StorageAdviser::Recommendation recommendation = 1449 StorageAdviser::Recommendation recommendation =
1440 StorageAdviser::recommend 1450 StorageAdviser::recommend
1441 (StorageAdviser::Criteria(StorageAdviser::SpeedCritical | 1451 (StorageAdviser::Criteria(StorageAdviser::SpeedCritical |
1442 StorageAdviser::PrecisionCritical | 1452 StorageAdviser::PrecisionCritical |
1443 StorageAdviser::FrequentLookupLikely), 1453 StorageAdviser::FrequentLookupLikely),
1444 sz / 1024, sz / 1024); 1454 (sz / 8) / 1024, sz / 1024);
1445 if ((recommendation & StorageAdviser::UseDisc) || 1455 if (recommendation & StorageAdviser::UseDisc) {
1446 (recommendation & StorageAdviser::ConserveSpace)) {
1447 SVDEBUG << "Seems inadvisable to create whole-model cache" << endl; 1456 SVDEBUG << "Seems inadvisable to create whole-model cache" << endl;
1448 return false; 1457 } else if (recommendation & StorageAdviser::ConserveSpace) {
1449 } else { 1458 SVDEBUG << "Seems inadvisable to create whole-model cache but acceptable to use the slightly higher-resolution peak cache" << endl;
1459 *suggestedPeakDivisor = 4;
1460 } else {
1450 SVDEBUG << "Seems fine to create whole-model cache" << endl; 1461 SVDEBUG << "Seems fine to create whole-model cache" << endl;
1451 return true; 1462 *createWholeCache = true;
1452 } 1463 }
1453 } catch (const InsufficientDiscSpace &) { 1464 } catch (const InsufficientDiscSpace &) {
1454 SVDEBUG << "Seems like a terrible idea to create whole-model cache" << endl; 1465 SVDEBUG << "Seems like a terrible idea to create whole-model cache" << endl;
1455 return false;
1456 } 1466 }
1457 } 1467 }
1458 1468
1459 const Model * 1469 const Model *
1460 SpectrogramLayer::getSliceableModel() const 1470 SpectrogramLayer::getSliceableModel() const