Mercurial > hg > svgui
comparison layer/SpectrogramLayer.cpp @ 1027:dade9bfc7695 spectrogram-minor-refactor
Fix return value from paintDrawBuffer in rightToLeft case; propagate timing change to PeakFrequencies version as well
author | Chris Cannam |
---|---|
date | Tue, 26 Jan 2016 14:44:26 +0000 |
parents | 53110ace211f |
children | 78ece8cdfaee |
comparison
equal
deleted
inserted
replaced
1026:53110ace211f | 1027:dade9bfc7695 |
---|---|
2290 float values[maxbin - minbin + 1]; | 2290 float values[maxbin - minbin + 1]; |
2291 #else | 2291 #else |
2292 float *values = (float *)alloca((maxbin - minbin + 1) * sizeof(float)); | 2292 float *values = (float *)alloca((maxbin - minbin + 1) * sizeof(float)); |
2293 #endif | 2293 #endif |
2294 | 2294 |
2295 int minColumns = 4; | |
2296 double maxTime = 0.15; // seconds; only for non-synchronous drawing | |
2297 auto startTime = chrono::steady_clock::now(); | |
2298 | |
2295 int start = 0; | 2299 int start = 0; |
2296 int finish = w; | 2300 int finish = w; |
2297 int step = 1; | 2301 int step = 1; |
2298 | 2302 |
2299 if (rightToLeft) { | 2303 if (rightToLeft) { |
2300 start = w-1; | 2304 start = w-1; |
2301 finish = -1; | 2305 finish = -1; |
2302 step = -1; | 2306 step = -1; |
2303 } | 2307 } |
2304 | 2308 |
2309 int columnCount = 0; | |
2310 | |
2305 for (int x = start; x != finish; x += step) { | 2311 for (int x = start; x != finish; x += step) { |
2312 | |
2313 ++columnCount; | |
2306 | 2314 |
2307 if (binforx[x] < 0) continue; | 2315 if (binforx[x] < 0) continue; |
2308 | 2316 |
2309 int sx0 = binforx[x]; | 2317 int sx0 = binforx[x]; |
2310 int sx1 = sx0; | 2318 int sx1 = sx0; |
2380 m_columnMags[sx].sample(mag); | 2388 m_columnMags[sx].sample(mag); |
2381 if (overallMag.sample(mag)) overallMagChanged = true; | 2389 if (overallMag.sample(mag)) overallMagChanged = true; |
2382 } | 2390 } |
2383 } | 2391 } |
2384 } | 2392 } |
2385 } | 2393 |
2386 | 2394 if (!m_synchronous) { |
2387 return w; | 2395 if (columnCount >= minColumns) { |
2396 auto t = chrono::steady_clock::now(); | |
2397 double diff = chrono::duration<double>(t - startTime).count(); | |
2398 if (diff > maxTime) { | |
2399 #ifdef DEBUG_SPECTROGRAM_REPAINT | |
2400 cerr << "SpectrogramLayer::paintDrawBufferPeakFrequencies: Max time " << maxTime << " sec exceeded after " | |
2401 << x << " columns with time " << diff << endl; | |
2402 #endif | |
2403 return columnCount; | |
2404 } | |
2405 } | |
2406 } | |
2407 } | |
2408 | |
2409 return columnCount; | |
2388 } | 2410 } |
2389 | 2411 |
2390 int | 2412 int |
2391 SpectrogramLayer::paintDrawBuffer(LayerGeometryProvider *v, | 2413 SpectrogramLayer::paintDrawBuffer(LayerGeometryProvider *v, |
2392 int w, | 2414 int w, |
2398 bool &overallMagChanged, | 2420 bool &overallMagChanged, |
2399 bool rightToLeft) const | 2421 bool rightToLeft) const |
2400 { | 2422 { |
2401 Profiler profiler("SpectrogramLayer::paintDrawBuffer"); | 2423 Profiler profiler("SpectrogramLayer::paintDrawBuffer"); |
2402 | 2424 |
2403 //!!! todo: propagate to paintDrawBufferPeakFrequencies | |
2404 | |
2405 int minColumns = 4; | |
2406 double maxTime = 0.1; // seconds; only for non-synchronous drawing | |
2407 | |
2408 auto startTime = chrono::steady_clock::now(); | |
2409 | |
2410 int minbin = int(binfory[0] + 0.0001); | 2425 int minbin = int(binfory[0] + 0.0001); |
2411 int maxbin = int(binfory[h-1]); | 2426 int maxbin = int(binfory[h-1]); |
2412 | 2427 |
2413 #ifdef DEBUG_SPECTROGRAM_REPAINT | 2428 #ifdef DEBUG_SPECTROGRAM_REPAINT |
2414 cerr << "SpectrogramLayer::paintDrawBuffer: minbin " << minbin << ", maxbin " << maxbin << "; w " << w << ", h " << h << endl; | 2429 cerr << "SpectrogramLayer::paintDrawBuffer: minbin " << minbin << ", maxbin " << maxbin << "; w " << w << ", h " << h << endl; |
2455 #endif | 2470 #endif |
2456 | 2471 |
2457 const float *values = autoarray; | 2472 const float *values = autoarray; |
2458 DenseThreeDimensionalModel::Column c; | 2473 DenseThreeDimensionalModel::Column c; |
2459 | 2474 |
2475 int minColumns = 4; | |
2476 double maxTime = 0.1; // seconds; only for non-synchronous drawing | |
2477 auto startTime = chrono::steady_clock::now(); | |
2478 | |
2460 int start = 0; | 2479 int start = 0; |
2461 int finish = w; | 2480 int finish = w; |
2462 int step = 1; | 2481 int step = 1; |
2463 | 2482 |
2464 if (rightToLeft) { | 2483 if (rightToLeft) { |
2465 start = w-1; | 2484 start = w-1; |
2466 finish = -1; | 2485 finish = -1; |
2467 step = -1; | 2486 step = -1; |
2468 } | 2487 } |
2488 | |
2489 int columnCount = 0; | |
2469 | 2490 |
2470 for (int x = start; x != finish; x += step) { | 2491 for (int x = start; x != finish; x += step) { |
2492 | |
2493 ++columnCount; | |
2471 | 2494 |
2472 if (binforx[x] < 0) continue; | 2495 if (binforx[x] < 0) continue; |
2473 | 2496 |
2474 // float columnGain = m_gain; | 2497 // float columnGain = m_gain; |
2475 float columnMax = 0.f; | 2498 float columnMax = 0.f; |
2636 | 2659 |
2637 m_drawBuffer.setPixel(x, h-y-1, peakpix); | 2660 m_drawBuffer.setPixel(x, h-y-1, peakpix); |
2638 } | 2661 } |
2639 | 2662 |
2640 if (!m_synchronous) { | 2663 if (!m_synchronous) { |
2641 if (x >= minColumns) { | 2664 if (columnCount >= minColumns) { |
2642 auto t = chrono::steady_clock::now(); | 2665 auto t = chrono::steady_clock::now(); |
2643 double diff = chrono::duration<double>(t - startTime).count(); | 2666 double diff = chrono::duration<double>(t - startTime).count(); |
2644 if (diff > maxTime) { | 2667 if (diff > maxTime) { |
2645 #ifdef DEBUG_SPECTROGRAM_REPAINT | 2668 #ifdef DEBUG_SPECTROGRAM_REPAINT |
2646 cerr << "SpectrogramLayer::paintDrawBuffer: Max time " << maxTime << " sec exceeded after " | 2669 cerr << "SpectrogramLayer::paintDrawBuffer: Max time " << maxTime << " sec exceeded after " |
2647 << x << " columns with time " << diff << endl; | 2670 << x << " columns with time " << diff << endl; |
2648 #endif | 2671 #endif |
2649 return x; | 2672 return columnCount; |
2650 } | 2673 } |
2651 } | 2674 } |
2652 } | 2675 } |
2653 } | 2676 } |
2654 | 2677 |
2655 return w; | 2678 return columnCount; |
2656 } | 2679 } |
2657 | 2680 |
2658 void | 2681 void |
2659 SpectrogramLayer::illuminateLocalFeatures(LayerGeometryProvider *v, QPainter &paint) const | 2682 SpectrogramLayer::illuminateLocalFeatures(LayerGeometryProvider *v, QPainter &paint) const |
2660 { | 2683 { |