Mercurial > hg > svgui
comparison layer/SpectrogramLayer.cpp @ 1037:6f7a471826d1 spectrogram-minor-refactor
Timing tweaks to reduce the number of repaints
author | Chris Cannam |
---|---|
date | Tue, 02 Feb 2016 15:32:57 +0000 |
parents | 55ac6ac1982e |
children | 6d4fa45a271d |
comparison
equal
deleted
inserted
replaced
1036:bc9b4a163926 | 1037:6f7a471826d1 |
---|---|
46 | 46 |
47 #ifndef __GNUC__ | 47 #ifndef __GNUC__ |
48 #include <alloca.h> | 48 #include <alloca.h> |
49 #endif | 49 #endif |
50 | 50 |
51 #define DEBUG_SPECTROGRAM_REPAINT 1 | 51 //#define DEBUG_SPECTROGRAM_REPAINT 1 |
52 | 52 |
53 using namespace std; | 53 using namespace std; |
54 | 54 |
55 SpectrogramLayer::SpectrogramLayer(Configuration config) : | 55 SpectrogramLayer::SpectrogramLayer(Configuration config) : |
56 m_model(0), | 56 m_model(0), |
961 invalidateImageCaches(); | 961 invalidateImageCaches(); |
962 invalidateMagnitudes(); | 962 invalidateMagnitudes(); |
963 } | 963 } |
964 | 964 |
965 void | 965 void |
966 SpectrogramLayer::cacheInvalid(sv_frame_t from, sv_frame_t to) | 966 SpectrogramLayer::cacheInvalid( |
967 #ifdef DEBUG_SPECTROGRAM_REPAINT | |
968 sv_frame_t from, sv_frame_t to | |
969 #else | |
970 sv_frame_t , sv_frame_t | |
971 #endif | |
972 ) | |
967 { | 973 { |
968 #ifdef DEBUG_SPECTROGRAM_REPAINT | 974 #ifdef DEBUG_SPECTROGRAM_REPAINT |
969 cerr << "SpectrogramLayer::cacheInvalid(" << from << ", " << to << ")" << endl; | 975 cerr << "SpectrogramLayer::cacheInvalid(" << from << ", " << to << ")" << endl; |
970 #endif | 976 #endif |
971 | 977 |
1729 if (!cache.isValid()) { | 1735 if (!cache.isValid()) { |
1730 if (!m_synchronous) { | 1736 if (!m_synchronous) { |
1731 // When rendering the whole thing, start from somewhere near | 1737 // When rendering the whole thing, start from somewhere near |
1732 // the middle so that the region of interest appears first | 1738 // the middle so that the region of interest appears first |
1733 if (x0 == 0 && x1 == v->getPaintWidth()) { | 1739 if (x0 == 0 && x1 == v->getPaintWidth()) { |
1734 x0 = int(x1 * 0.4); | 1740 x0 = int(x1 * 0.3); |
1735 } | 1741 } |
1736 } | 1742 } |
1737 } else { | 1743 } else { |
1738 // When rendering only a part of the cache, we need to make | 1744 // When rendering only a part of the cache, we need to make |
1739 // sure that the part we're rendering is adjacent to (or | 1745 // sure that the part we're rendering is adjacent to (or |
2150 #else | 2156 #else |
2151 float *values = (float *)alloca((maxbin - minbin + 1) * sizeof(float)); | 2157 float *values = (float *)alloca((maxbin - minbin + 1) * sizeof(float)); |
2152 #endif | 2158 #endif |
2153 | 2159 |
2154 int minColumns = 4; | 2160 int minColumns = 4; |
2155 double maxTime = 0.15; // seconds; only for non-synchronous drawing | 2161 double softTimeLimit = 0.15; // seconds; only for non-synchronous drawing |
2162 double hardTimeLimit = softTimeLimit * 2.0; | |
2163 bool overridingSoftLimit = false; | |
2156 auto startTime = chrono::steady_clock::now(); | 2164 auto startTime = chrono::steady_clock::now(); |
2157 | 2165 |
2158 int start = 0; | 2166 int start = 0; |
2159 int finish = w; | 2167 int finish = w; |
2160 int step = 1; | 2168 int step = 1; |
2252 | 2260 |
2253 if (!m_synchronous) { | 2261 if (!m_synchronous) { |
2254 if (columnCount >= minColumns) { | 2262 if (columnCount >= minColumns) { |
2255 auto t = chrono::steady_clock::now(); | 2263 auto t = chrono::steady_clock::now(); |
2256 double diff = chrono::duration<double>(t - startTime).count(); | 2264 double diff = chrono::duration<double>(t - startTime).count(); |
2257 if (diff > maxTime) { | 2265 if (diff > hardTimeLimit) { |
2258 #ifdef DEBUG_SPECTROGRAM_REPAINT | 2266 #ifdef DEBUG_SPECTROGRAM_REPAINT |
2259 cerr << "SpectrogramLayer::paintDrawBufferPeakFrequencies: Max time " << maxTime << " sec exceeded after " | 2267 cerr << "SpectrogramLayer::paintDrawBufferPeakFrequencies: hard limit " << hardTimeLimit << " sec exceeded after " |
2260 << columnCount << " columns with time " << diff << endl; | 2268 << columnCount << " columns with time " << diff << endl; |
2261 #endif | 2269 #endif |
2262 return columnCount; | 2270 return columnCount; |
2263 } | 2271 } else if (diff > softTimeLimit && !overridingSoftLimit) { |
2272 // If we're more than half way through by the time | |
2273 // we reach the soft limit, ignore it (though | |
2274 // still respect the hard limit, above). Otherwise | |
2275 // respect the soft limit and return now. | |
2276 if (columnCount > w/2) { | |
2277 overridingSoftLimit = true; | |
2278 } else { | |
2279 #ifdef DEBUG_SPECTROGRAM_REPAINT | |
2280 cerr << "SpectrogramLayer::paintDrawBufferPeakFrequencies: soft limit " << softTimeLimit << " sec exceeded after " | |
2281 << columnCount << " columns with time " << diff << endl; | |
2282 #endif | |
2283 return columnCount; | |
2284 } | |
2285 } | |
2264 } | 2286 } |
2265 } | 2287 } |
2266 } | 2288 } |
2267 | 2289 |
2268 return columnCount; | 2290 return columnCount; |
2330 | 2352 |
2331 const float *values = autoarray; | 2353 const float *values = autoarray; |
2332 DenseThreeDimensionalModel::Column c; | 2354 DenseThreeDimensionalModel::Column c; |
2333 | 2355 |
2334 int minColumns = 4; | 2356 int minColumns = 4; |
2335 double maxTime = 0.1; // seconds; only for non-synchronous drawing | 2357 double softTimeLimit = 0.1; // seconds; only for non-synchronous drawing |
2358 double hardTimeLimit = softTimeLimit * 2.0; | |
2359 bool overridingSoftLimit = false; | |
2336 auto startTime = chrono::steady_clock::now(); | 2360 auto startTime = chrono::steady_clock::now(); |
2337 | 2361 |
2338 int start = 0; | 2362 int start = 0; |
2339 int finish = w; | 2363 int finish = w; |
2340 int step = 1; | 2364 int step = 1; |
2521 | 2545 |
2522 if (!m_synchronous) { | 2546 if (!m_synchronous) { |
2523 if (columnCount >= minColumns) { | 2547 if (columnCount >= minColumns) { |
2524 auto t = chrono::steady_clock::now(); | 2548 auto t = chrono::steady_clock::now(); |
2525 double diff = chrono::duration<double>(t - startTime).count(); | 2549 double diff = chrono::duration<double>(t - startTime).count(); |
2526 if (diff > maxTime) { | 2550 if (diff > hardTimeLimit) { |
2527 #ifdef DEBUG_SPECTROGRAM_REPAINT | 2551 #ifdef DEBUG_SPECTROGRAM_REPAINT |
2528 cerr << "SpectrogramLayer::paintDrawBuffer: Max time " << maxTime << " sec exceeded after " | 2552 cerr << "SpectrogramLayer::paintDrawBuffer: hard limit " << hardTimeLimit << " sec exceeded after " |
2529 << columnCount << " columns with time " << diff << endl; | 2553 << columnCount << " columns with time " << diff << endl; |
2530 #endif | 2554 #endif |
2531 return columnCount; | 2555 return columnCount; |
2532 } | 2556 } else if (diff > softTimeLimit && !overridingSoftLimit) { |
2557 // If we're more than half way through by the time | |
2558 // we reach the soft limit, ignore it (though | |
2559 // still respect the hard limit, above). Otherwise | |
2560 // respect the soft limit and return now. | |
2561 if (columnCount > w/2) { | |
2562 overridingSoftLimit = true; | |
2563 } else { | |
2564 #ifdef DEBUG_SPECTROGRAM_REPAINT | |
2565 cerr << "SpectrogramLayer::paintDrawBuffer: soft limit " << softTimeLimit << " sec exceeded after " | |
2566 << columnCount << " columns with time " << diff << endl; | |
2567 #endif | |
2568 return columnCount; | |
2569 } | |
2570 } | |
2533 } | 2571 } |
2534 } | 2572 } |
2535 } | 2573 } |
2536 | 2574 |
2537 return columnCount; | 2575 return columnCount; |