comparison layer/SpectrogramLayer.cpp @ 483:18f38f564d7c

* reorganise function for faster data retrieval
author Chris Cannam
date Wed, 04 Feb 2009 13:09:02 +0000
parents 7f1ed4bfea1e
children a926fca1f280
comparison
equal deleted inserted replaced
482:7f1ed4bfea1e 483:18f38f564d7c
2419 if (minbin < 0) minbin = 0; 2419 if (minbin < 0) minbin = 0;
2420 if (maxbin < 0) maxbin = minbin+1; 2420 if (maxbin < 0) maxbin = minbin+1;
2421 2421
2422 int psx = -1; 2422 int psx = -1;
2423 float values[maxbin - minbin + 1]; 2423 float values[maxbin - minbin + 1];
2424 float peaks[h];
2424 2425
2425 for (int x = 0; x < w; ++x) { 2426 for (int x = 0; x < w; ++x) {
2426 2427
2427 if (binforx[x] < 0) continue; 2428 if (binforx[x] < 0) continue;
2428 2429
2429 for (int y = 0; y < h; ++y) { 2430 int sx0 = binforx[x];
2430 2431 int sx1 = sx0;
2431 unsigned char peakpix = 0; 2432 if (x+1 < w) sx1 = binforx[x+1];
2432 2433 if (sx0 < 0) sx0 = sx1 - 1;
2433 int sx0 = binforx[x]; 2434 if (sx0 < 0) continue;
2434 int sx1 = sx0; 2435 if (sx1 <= sx0) sx1 = sx0 + 1;
2435 if (x+1 < w) sx1 = binforx[x+1]; 2436
2436 if (sx0 < 0) sx0 = sx1 - 1; 2437 for (int y = 0; y < h; ++y) peaks[y] = 0.f;
2437 if (sx0 < 0) continue;
2438 if (sx1 <= sx0) sx1 = sx0 + 1;
2439 2438
2440 for (int sx = sx0; sx < sx1; ++sx) { 2439 for (int sx = sx0; sx < sx1; ++sx) {
2441 2440
2442 if (sx < 0 || sx >= int(fft->getWidth())) continue; 2441 if (sx < 0 || sx >= int(fft->getWidth())) continue;
2443 2442
2444 if (!m_synchronous) { 2443 if (!m_synchronous) {
2445 if (!fft->isColumnAvailable(sx)) { 2444 if (!fft->isColumnAvailable(sx)) {
2446 #ifdef DEBUG_SPECTROGRAM_REPAINT 2445 #ifdef DEBUG_SPECTROGRAM_REPAINT
2447 std::cerr << "Met unavailable column at col " << sx << std::endl; 2446 std::cerr << "Met unavailable column at col " << sx << std::endl;
2448 #endif 2447 #endif
2449 return false; 2448 return false;
2450 }
2451 } 2449 }
2452 2450 }
2453 if (sx != psx) { 2451
2454 fft->getMagnitudesAt(sx, values, minbin, maxbin - minbin + 1); 2452 if (sx != psx) {
2455 psx = sx; 2453 cerr << "Retrieving column " << sx << endl;
2456 } 2454 fft->getMagnitudesAt(sx, values, minbin, maxbin - minbin + 1);
2455 psx = sx;
2456 }
2457
2458 for (int y = 0; y < h; ++y) {
2457 2459
2458 int sy0 = binfory[y]; 2460 int sy0 = binfory[y];
2459 int sy1 = sy0; 2461 int sy1 = sy0;
2460 if (y+1 < h) sy1 = binfory[y+1]; 2462 if (y+1 < h) sy1 = binfory[y+1];
2461 if (sy0 < 0) sy0 = sy1 - 1; 2463 if (sy0 < 0) sy0 = sy1 - 1;
2466 2468
2467 //!!! review -- if we know we're dealing with 2469 //!!! review -- if we know we're dealing with
2468 //!!! magnitudes here, we can just use peak of the 2470 //!!! magnitudes here, we can just use peak of the
2469 //!!! float values 2471 //!!! float values
2470 2472
2471 float peak = 0.f;
2472
2473 for (int sy = sy0; sy < sy1; ++sy) { 2473 for (int sy = sy0; sy < sy1; ++sy) {
2474 2474
2475 float value = values[sy - minbin]; 2475 float value = values[sy - minbin];
2476 /* 2476 /*
2477 if (m_colourScale != PhaseColourScale) { 2477 if (m_colourScale != PhaseColourScale) {
2484 2484
2485 unsigned char pix = getDisplayValue(v, value); 2485 unsigned char pix = getDisplayValue(v, value);
2486 if (pix > peakpix) peakpix = pix; 2486 if (pix > peakpix) peakpix = pix;
2487 // cerr <<x<<","<<y<<" -> "<<sx<<","<<sy<<" -> "<<values[sy]<<" -> "<<(int)pix<< endl; 2487 // cerr <<x<<","<<y<<" -> "<<sx<<","<<sy<<" -> "<<values[sy]<<" -> "<<(int)pix<< endl;
2488 */ 2488 */
2489 if (value > peak) peak = value; //!!! not right for phase! 2489 if (value > peaks[y]) peaks[y] = value; //!!! not right for phase!
2490 } 2490 }
2491 2491 }
2492 if (m_colourScale != PhaseColourScale) { 2492 }
2493 if (!m_normalizeColumns) { 2493
2494 peak /= (m_fftSize/2.f); 2494 for (int y = 0; y < h; ++y) {
2495 } 2495
2496 float peak = peaks[y];
2497
2498 if (m_colourScale != PhaseColourScale) {
2499 if (!m_normalizeColumns) {
2500 peak /= (m_fftSize/2.f);
2501 }
2496 //!!! mag.sample(value); 2502 //!!! mag.sample(value);
2497 peak *= m_gain; 2503 peak *= m_gain;
2498 } 2504 }
2499 2505
2500 peakpix = getDisplayValue(v, peak); 2506 unsigned char peakpix = getDisplayValue(v, peak);
2501 }
2502 2507
2503 m_drawBuffer.setPixel(x, h-y-1, peakpix); 2508 m_drawBuffer.setPixel(x, h-y-1, peakpix);
2504 } 2509 }
2505 } 2510 }
2506 2511