comparison layer/SpectrogramLayer.cpp @ 487:6a5327c0a40f

* Re-enable column normalization
author Chris Cannam
date Thu, 05 Feb 2009 13:31:27 +0000
parents c860cab85904
children 5cd6f0d3f42d
comparison
equal deleted inserted replaced
486:c860cab85904 487:6a5327c0a40f
2279 for (int x = 0; x < bufwid; ++x) { 2279 for (int x = 0; x < bufwid; ++x) {
2280 float s0 = 0, s1 = 0; 2280 float s0 = 0, s1 = 0;
2281 if (getXBinRange(v, x + x0, s0, s1)) { 2281 if (getXBinRange(v, x + x0, s0, s1)) {
2282 binforx[x] = int(s0 + 0.0001); 2282 binforx[x] = int(s0 + 0.0001);
2283 } else { 2283 } else {
2284 binforx[x] = 0; //??? 2284 binforx[x] = -1; //???
2285 } 2285 }
2286 } 2286 }
2287 if (m_drawBuffer.width() < bufwid || m_drawBuffer.height() < h) { 2287 if (m_drawBuffer.width() < bufwid || m_drawBuffer.height() < h) {
2288 m_drawBuffer = QImage(bufwid, h, QImage::Format_Indexed8); 2288 m_drawBuffer = QImage(bufwid, h, QImage::Format_Indexed8);
2289 } 2289 }
2290 usePeaksCache = (increment * 8) < zoomLevel; 2290 usePeaksCache = (increment * 8) < zoomLevel;
2291 if (m_colourScale == PhaseColourScale) usePeaksCache = false;
2291 } 2292 }
2292 2293
2293 m_drawBuffer.setNumColors(256); 2294 m_drawBuffer.setNumColors(256);
2294 for (int pixel = 0; pixel < 256; ++pixel) { 2295 for (int pixel = 0; pixel < 256; ++pixel) {
2295 m_drawBuffer.setColor(pixel, m_palette.getColour(pixel).rgb()); 2296 m_drawBuffer.setColor(pixel, m_palette.getColour(pixel).rgb());
2509 2510
2510 for (int x = 0; x < w; ++x) { 2511 for (int x = 0; x < w; ++x) {
2511 2512
2512 if (binforx[x] < 0) continue; 2513 if (binforx[x] < 0) continue;
2513 2514
2515 float columnGain = m_gain;
2516 float columnMax = 0.f;
2517
2514 int sx0 = binforx[x] / divisor; 2518 int sx0 = binforx[x] / divisor;
2515 int sx1 = sx0; 2519 int sx1 = sx0;
2516 if (x+1 < w) sx1 = binforx[x+1] / divisor; 2520 if (x+1 < w) sx1 = binforx[x+1] / divisor;
2517 if (sx0 < 0) sx0 = sx1 - 1; 2521 if (sx0 < 0) sx0 = sx1 - 1;
2518 if (sx0 < 0) continue; 2522 if (sx0 < 0) continue;
2536 if (sx != psx) { 2540 if (sx != psx) {
2537 if (fft) { 2541 if (fft) {
2538 #ifdef DEBUG_SPECTROGRAM_REPAINT 2542 #ifdef DEBUG_SPECTROGRAM_REPAINT
2539 cerr << "Retrieving column " << sx << " from fft directly" << endl; 2543 cerr << "Retrieving column " << sx << " from fft directly" << endl;
2540 #endif 2544 #endif
2541 fft->getMagnitudesAt(sx, values, minbin, maxbin - minbin + 1); 2545 if (m_colourScale == PhaseColourScale) {
2546 fft->getPhasesAt(sx, values, minbin, maxbin - minbin + 1);
2547 } else if (m_normalizeColumns) {
2548 fft->getNormalizedMagnitudesAt(sx, values, minbin, maxbin - minbin + 1);
2549 } else {
2550 fft->getMagnitudesAt(sx, values, minbin, maxbin - minbin + 1);
2551 }
2542 } else { 2552 } else {
2543 #ifdef DEBUG_SPECTROGRAM_REPAINT 2553 #ifdef DEBUG_SPECTROGRAM_REPAINT
2544 cerr << "Retrieving column " << sx << " from peaks cache" << endl; 2554 cerr << "Retrieving column " << sx << " from peaks cache" << endl;
2545 #endif 2555 #endif
2546 c = sourceModel->getColumn(sx); 2556 c = sourceModel->getColumn(sx);
2557 if (m_normalizeColumns) {
2558 for (int y = 0; y < h; ++y) {
2559 if (c[y] > columnMax) columnMax = c[y];
2560 }
2561 }
2547 } 2562 }
2548 psx = sx; 2563 psx = sx;
2549 } 2564 }
2550 2565
2551 for (int y = 0; y < h; ++y) { 2566 for (int y = 0; y < h; ++y) {
2585 if (value > peaks[y]) peaks[y] = value; //!!! not right for phase! 2600 if (value > peaks[y]) peaks[y] = value; //!!! not right for phase!
2586 } 2601 }
2587 } 2602 }
2588 } 2603 }
2589 2604
2605 if (m_normalizeColumns && columnMax > 0.f) {
2606 columnGain /= columnMax;
2607 }
2608
2590 for (int y = 0; y < h; ++y) { 2609 for (int y = 0; y < h; ++y) {
2591 2610
2592 float peak = peaks[y]; 2611 float peak = peaks[y];
2593 2612
2594 if (m_colourScale != PhaseColourScale) { 2613 if (m_colourScale != PhaseColourScale) {
2595 if (!m_normalizeColumns) { 2614 if (!m_normalizeColumns) {
2596 peak /= (m_fftSize/2.f); 2615 peak /= (m_fftSize/2.f);
2597 } 2616 }
2598 //!!! mag.sample(value); 2617 //!!! mag.sample(value);
2599 peak *= m_gain; 2618 peak *= columnGain;
2600 } 2619 }
2601 2620
2602 unsigned char peakpix = getDisplayValue(v, peak); 2621 unsigned char peakpix = getDisplayValue(v, peak);
2603 2622
2604 m_drawBuffer.setPixel(x, h-y-1, peakpix); 2623 m_drawBuffer.setPixel(x, h-y-1, peakpix);