Mercurial > hg > svgui
comparison layer/SpectrogramLayer.cpp @ 485:3f9fddc890e0
* fix deadlock in fft memory cache usage
author | Chris Cannam |
---|---|
date | Wed, 04 Feb 2009 20:39:11 +0000 |
parents | a926fca1f280 |
children | c860cab85904 |
comparison
equal
deleted
inserted
replaced
484:a926fca1f280 | 485:3f9fddc890e0 |
---|---|
43 using std::cerr; | 43 using std::cerr; |
44 using std::endl; | 44 using std::endl; |
45 #include <cassert> | 45 #include <cassert> |
46 #include <cmath> | 46 #include <cmath> |
47 | 47 |
48 #define DEBUG_SPECTROGRAM_REPAINT 1 | 48 //#define DEBUG_SPECTROGRAM_REPAINT 1 |
49 | 49 |
50 SpectrogramLayer::SpectrogramLayer(Configuration config) : | 50 SpectrogramLayer::SpectrogramLayer(Configuration config) : |
51 m_model(0), | 51 m_model(0), |
52 m_channel(0), | 52 m_channel(0), |
53 m_windowSize(1024), | 53 m_windowSize(1024), |
2214 if ((f / increment) * increment == f) { | 2214 if ((f / increment) * increment == f) { |
2215 if (rightCropFrame == -1) rightCropFrame = f; | 2215 if (rightCropFrame == -1) rightCropFrame = f; |
2216 else if (x > x0 + w + 2) { rightBoundaryFrame = f; break; } | 2216 else if (x > x0 + w + 2) { rightBoundaryFrame = f; break; } |
2217 } | 2217 } |
2218 } | 2218 } |
2219 #ifdef DEBUG_SPECTROGRAM_REPAINT | |
2219 cerr << "Left: crop: " << leftCropFrame << " (bin " << leftCropFrame/increment << "); boundary: " << leftBoundaryFrame << " (bin " << leftBoundaryFrame/increment << ")" << endl; | 2220 cerr << "Left: crop: " << leftCropFrame << " (bin " << leftCropFrame/increment << "); boundary: " << leftBoundaryFrame << " (bin " << leftBoundaryFrame/increment << ")" << endl; |
2220 cerr << "Right: crop: " << rightCropFrame << " (bin " << rightCropFrame/increment << "); boundary: " << rightBoundaryFrame << " (bin " << rightBoundaryFrame/increment << ")" << endl; | 2221 cerr << "Right: crop: " << rightCropFrame << " (bin " << rightCropFrame/increment << "); boundary: " << rightBoundaryFrame << " (bin " << rightBoundaryFrame/increment << ")" << endl; |
2222 #endif | |
2221 | 2223 |
2222 bufwid = (rightBoundaryFrame - leftBoundaryFrame) / increment; | 2224 bufwid = (rightBoundaryFrame - leftBoundaryFrame) / increment; |
2223 | 2225 |
2224 } else { | 2226 } else { |
2225 | 2227 |
2327 QPainter cachePainter(&cache.image); | 2329 QPainter cachePainter(&cache.image); |
2328 | 2330 |
2329 if (bufferBinResolution) { | 2331 if (bufferBinResolution) { |
2330 int scaledLeft = v->getXForFrame(leftBoundaryFrame); | 2332 int scaledLeft = v->getXForFrame(leftBoundaryFrame); |
2331 int scaledRight = v->getXForFrame(rightBoundaryFrame); | 2333 int scaledRight = v->getXForFrame(rightBoundaryFrame); |
2334 #ifdef DEBUG_SPECTROGRAM_REPAINT | |
2332 cerr << "Rescaling image from " << bufwid | 2335 cerr << "Rescaling image from " << bufwid |
2333 << "x" << h << " to " | 2336 << "x" << h << " to " |
2334 << scaledRight-scaledLeft << "x" << h << endl; | 2337 << scaledRight-scaledLeft << "x" << h << endl; |
2338 #endif | |
2335 QImage scaled = m_drawBuffer.scaled | 2339 QImage scaled = m_drawBuffer.scaled |
2336 (scaledRight - scaledLeft, h, | 2340 (scaledRight - scaledLeft, h, |
2337 Qt::IgnoreAspectRatio, Qt::SmoothTransformation); | 2341 Qt::IgnoreAspectRatio, Qt::SmoothTransformation); |
2338 // cachePainter.setRenderHint(QPainter::SmoothPixmapTransform, true); | 2342 // cachePainter.setRenderHint(QPainter::SmoothPixmapTransform, true); |
2339 int scaledLeftCrop = v->getXForFrame(leftCropFrame); | 2343 int scaledLeftCrop = v->getXForFrame(leftCropFrame); |
2340 int scaledRightCrop = v->getXForFrame(rightCropFrame); | 2344 int scaledRightCrop = v->getXForFrame(rightCropFrame); |
2345 #ifdef DEBUG_SPECTROGRAM_REPAINT | |
2341 cerr << "Drawing image region of width " << scaledRightCrop - scaledLeftCrop << " to " | 2346 cerr << "Drawing image region of width " << scaledRightCrop - scaledLeftCrop << " to " |
2342 << scaledLeftCrop << " from " << scaledLeftCrop - scaledLeft << endl; | 2347 << scaledLeftCrop << " from " << scaledLeftCrop - scaledLeft << endl; |
2348 #endif | |
2343 cachePainter.drawImage | 2349 cachePainter.drawImage |
2344 (QRect(scaledLeftCrop, 0, | 2350 (QRect(scaledLeftCrop, 0, |
2345 scaledRightCrop - scaledLeftCrop, h), | 2351 scaledRightCrop - scaledLeftCrop, h), |
2346 scaled, | 2352 scaled, |
2347 QRect(scaledLeftCrop - scaledLeft, 0, | 2353 QRect(scaledLeftCrop - scaledLeft, 0, |
2434 Profiler profiler("SpectrogramLayer::paintDrawBuffer"); | 2440 Profiler profiler("SpectrogramLayer::paintDrawBuffer"); |
2435 | 2441 |
2436 int minbin = binfory[0]; | 2442 int minbin = binfory[0]; |
2437 int maxbin = binfory[h-1]; | 2443 int maxbin = binfory[h-1]; |
2438 | 2444 |
2445 #ifdef DEBUG_SPECTROGRAM_REPAINT | |
2439 cerr << "minbin " << minbin << ", maxbin " << maxbin << "; w " << w << ", h " << h << endl; | 2446 cerr << "minbin " << minbin << ", maxbin " << maxbin << "; w " << w << ", h " << h << endl; |
2447 #endif | |
2440 if (minbin < 0) minbin = 0; | 2448 if (minbin < 0) minbin = 0; |
2441 if (maxbin < 0) maxbin = minbin+1; | 2449 if (maxbin < 0) maxbin = minbin+1; |
2442 | 2450 |
2443 DenseThreeDimensionalModel *sourceModel = 0; | 2451 DenseThreeDimensionalModel *sourceModel = 0; |
2444 FFTModel *fft = 0; | 2452 FFTModel *fft = 0; |
2445 int divisor = 1; | 2453 int divisor = 1; |
2454 #ifdef DEBUG_SPECTROGRAM_REPAINT | |
2446 cerr << "Note: bin display = " << m_binDisplay << ", w = " << w << ", binforx[" << w-1 << "] = " << binforx[w-1] << ", binforx[0] = " << binforx[0] << endl; | 2455 cerr << "Note: bin display = " << m_binDisplay << ", w = " << w << ", binforx[" << w-1 << "] = " << binforx[w-1] << ", binforx[0] = " << binforx[0] << endl; |
2456 #endif | |
2447 if (usePeaksCache) { //!!! | 2457 if (usePeaksCache) { //!!! |
2448 sourceModel = getPeakCache(v); | 2458 sourceModel = getPeakCache(v); |
2449 divisor = 8;//!!! | 2459 divisor = 8;//!!! |
2450 minbin = 0; | 2460 minbin = 0; |
2451 maxbin = sourceModel->getHeight(); | 2461 maxbin = sourceModel->getHeight(); |
2486 } | 2496 } |
2487 } | 2497 } |
2488 | 2498 |
2489 if (sx != psx) { | 2499 if (sx != psx) { |
2490 if (fft) { | 2500 if (fft) { |
2501 #ifdef DEBUG_SPECTROGRAM_REPAINT | |
2491 cerr << "Retrieving column " << sx << " from fft directly" << endl; | 2502 cerr << "Retrieving column " << sx << " from fft directly" << endl; |
2503 #endif | |
2492 fft->getMagnitudesAt(sx, values, minbin, maxbin - minbin + 1); | 2504 fft->getMagnitudesAt(sx, values, minbin, maxbin - minbin + 1); |
2493 } else { | 2505 } else { |
2506 #ifdef DEBUG_SPECTROGRAM_REPAINT | |
2494 cerr << "Retrieving column " << sx << " from peaks cache" << endl; | 2507 cerr << "Retrieving column " << sx << " from peaks cache" << endl; |
2508 #endif | |
2495 c = sourceModel->getColumn(sx); | 2509 c = sourceModel->getColumn(sx); |
2496 } | 2510 } |
2497 psx = sx; | 2511 psx = sx; |
2498 } | 2512 } |
2499 | 2513 |