Mercurial > hg > svgui
comparison layer/SpectrogramLayer.cpp @ 1041:fcedcc7f0d87 3.0-integration
Merge from branch "tony-2.0-integration"
author | Chris Cannam |
---|---|
date | Thu, 04 Feb 2016 11:17:23 +0000 |
parents | 96cf499fad62 |
children | fccee028a522 |
comparison
equal
deleted
inserted
replaced
1011:7242fe160c19 | 1041:fcedcc7f0d87 |
---|---|
1885 if (paintBlockWidth == 0) { | 1885 if (paintBlockWidth == 0) { |
1886 paintBlockWidth = (300000 / zoomLevel); | 1886 paintBlockWidth = (300000 / zoomLevel); |
1887 } else { | 1887 } else { |
1888 RealTime lastTime = m_lastPaintTime; | 1888 RealTime lastTime = m_lastPaintTime; |
1889 while (lastTime > RealTime::fromMilliseconds(200) && | 1889 while (lastTime > RealTime::fromMilliseconds(200) && |
1890 paintBlockWidth > 50) { | 1890 paintBlockWidth > 100) { |
1891 paintBlockWidth /= 2; | 1891 paintBlockWidth /= 2; |
1892 lastTime = lastTime / 2; | 1892 lastTime = lastTime / 2; |
1893 } | 1893 } |
1894 while (lastTime < RealTime::fromMilliseconds(90) && | 1894 while (lastTime < RealTime::fromMilliseconds(90) && |
1895 paintBlockWidth < 1500) { | 1895 paintBlockWidth < 1500) { |
1896 paintBlockWidth *= 2; | 1896 paintBlockWidth *= 2; |
1897 lastTime = lastTime * 2; | 1897 lastTime = lastTime * 2; |
1898 } | 1898 } |
1899 } | 1899 } |
1900 | 1900 |
1901 if (paintBlockWidth < 20) paintBlockWidth = 20; | 1901 if (paintBlockWidth < 50) paintBlockWidth = 50; |
1902 } | 1902 } |
1903 | 1903 |
1904 #ifdef DEBUG_SPECTROGRAM_REPAINT | 1904 #ifdef DEBUG_SPECTROGRAM_REPAINT |
1905 cerr << "[" << this << "]: last paint width: " << m_lastPaintBlockWidth << ", last paint time: " << m_lastPaintTime << ", new paint width: " << paintBlockWidth << endl; | 1905 cerr << "[" << this << "]: last paint width: " << m_lastPaintBlockWidth << ", last paint time: " << m_lastPaintTime << ", new paint width: " << paintBlockWidth << endl; |
1906 #endif | 1906 #endif |
2399 if (m_colourScale == PhaseColourScale) { | 2399 if (m_colourScale == PhaseColourScale) { |
2400 fft->getPhasesAt(sx, values, minbin, maxbin - minbin + 1); | 2400 fft->getPhasesAt(sx, values, minbin, maxbin - minbin + 1); |
2401 } else if (m_normalization == NormalizeColumns) { | 2401 } else if (m_normalization == NormalizeColumns) { |
2402 fft->getNormalizedMagnitudesAt(sx, values, minbin, maxbin - minbin + 1); | 2402 fft->getNormalizedMagnitudesAt(sx, values, minbin, maxbin - minbin + 1); |
2403 } else if (m_normalization == NormalizeHybrid) { | 2403 } else if (m_normalization == NormalizeHybrid) { |
2404 fft->getNormalizedMagnitudesAt(sx, values, minbin, maxbin - minbin + 1); | 2404 float max = fft->getNormalizedMagnitudesAt(sx, values, minbin, maxbin - minbin + 1); |
2405 double max = fft->getMaximumMagnitudeAt(sx); | |
2406 if (max > 0.f) { | 2405 if (max > 0.f) { |
2407 for (int i = minbin; i <= maxbin; ++i) { | 2406 for (int i = minbin; i <= maxbin; ++i) { |
2408 values[i - minbin] = float(values[i - minbin] * log10(max)); | 2407 values[i - minbin] = float(values[i - minbin] * |
2408 log10f(max)); | |
2409 } | 2409 } |
2410 } | 2410 } |
2411 } else { | 2411 } else { |
2412 fft->getMagnitudesAt(sx, values, minbin, maxbin - minbin + 1); | 2412 fft->getMagnitudesAt(sx, values, minbin, maxbin - minbin + 1); |
2413 } | 2413 } |
2566 if (m_colourScale == PhaseColourScale) { | 2566 if (m_colourScale == PhaseColourScale) { |
2567 fft->getPhasesAt(sx, autoarray, minbin, maxbin - minbin + 1); | 2567 fft->getPhasesAt(sx, autoarray, minbin, maxbin - minbin + 1); |
2568 } else if (m_normalization == NormalizeColumns) { | 2568 } else if (m_normalization == NormalizeColumns) { |
2569 fft->getNormalizedMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1); | 2569 fft->getNormalizedMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1); |
2570 } else if (m_normalization == NormalizeHybrid) { | 2570 } else if (m_normalization == NormalizeHybrid) { |
2571 fft->getNormalizedMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1); | 2571 float max = fft->getNormalizedMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1); |
2572 float max = fft->getMaximumMagnitudeAt(sx); | |
2573 float scale = log10f(max + 1.f); | 2572 float scale = log10f(max + 1.f); |
2574 // cout << "sx = " << sx << ", max = " << max << ", log10(max) = " << log10(max) << ", scale = " << scale << endl; | 2573 // cout << "sx = " << sx << ", max = " << max << ", log10(max) = " << log10(max) << ", scale = " << scale << endl; |
2575 for (int i = minbin; i <= maxbin; ++i) { | 2574 for (int i = minbin; i <= maxbin; ++i) { |
2576 autoarray[i - minbin] *= scale; | 2575 autoarray[i - minbin] *= scale; |
2577 } | 2576 } |
3543 .arg(m_colourMap) | 3542 .arg(m_colourMap) |
3544 .arg(m_colourRotation) | 3543 .arg(m_colourRotation) |
3545 .arg(m_frequencyScale) | 3544 .arg(m_frequencyScale) |
3546 .arg(m_binDisplay); | 3545 .arg(m_binDisplay); |
3547 | 3546 |
3548 s += QString("normalizeColumns=\"%1\" " | 3547 // New-style normalization attributes, allowing for more types of |
3549 "normalizeVisibleArea=\"%2\" " | 3548 // normalization in future: write out the column normalization |
3550 "normalizeHybrid=\"%3\" ") | 3549 // type separately, and then whether we are normalizing visible |
3551 .arg(m_normalization == NormalizeColumns ? "true" : "false") | 3550 // area as well afterwards |
3552 .arg(m_normalization == NormalizeVisibleArea ? "true" : "false") | 3551 |
3553 .arg(m_normalization == NormalizeHybrid ? "true" : "false"); | 3552 s += QString("columnNormalization=\"%1\" ") |
3554 | 3553 .arg(m_normalization == NormalizeColumns ? "peak" : |
3554 m_normalization == NormalizeHybrid ? "hybrid" : "none"); | |
3555 | |
3556 // Old-style normalization attribute. We *don't* write out | |
3557 // normalizeHybrid here because the only release that would accept | |
3558 // it (Tony v1.0) has a totally different scale factor for | |
3559 // it. We'll just have to accept that session files from Tony | |
3560 // v2.0+ will look odd in Tony v1.0 | |
3561 | |
3562 s += QString("normalizeColumns=\"%1\" ") | |
3563 .arg(m_normalization == NormalizeColumns ? "true" : "false"); | |
3564 | |
3565 // And this applies to both old- and new-style attributes | |
3566 | |
3567 s += QString("normalizeVisibleArea=\"%1\" ") | |
3568 .arg(m_normalization == NormalizeVisibleArea ? "true" : "false"); | |
3569 | |
3555 Layer::toXml(stream, indent, extraAttributes + " " + s); | 3570 Layer::toXml(stream, indent, extraAttributes + " " + s); |
3556 } | 3571 } |
3557 | 3572 |
3558 void | 3573 void |
3559 SpectrogramLayer::setProperties(const QXmlAttributes &attributes) | 3574 SpectrogramLayer::setProperties(const QXmlAttributes &attributes) |
3614 | 3629 |
3615 BinDisplay binDisplay = (BinDisplay) | 3630 BinDisplay binDisplay = (BinDisplay) |
3616 attributes.value("binDisplay").toInt(&ok); | 3631 attributes.value("binDisplay").toInt(&ok); |
3617 if (ok) setBinDisplay(binDisplay); | 3632 if (ok) setBinDisplay(binDisplay); |
3618 | 3633 |
3619 bool normalizeColumns = | 3634 bool haveNewStyleNormalization = false; |
3620 (attributes.value("normalizeColumns").trimmed() == "true"); | 3635 |
3621 if (normalizeColumns) { | 3636 QString columnNormalization = attributes.value("columnNormalization"); |
3622 setNormalization(NormalizeColumns); | 3637 |
3638 if (columnNormalization != "") { | |
3639 | |
3640 haveNewStyleNormalization = true; | |
3641 | |
3642 if (columnNormalization == "peak") { | |
3643 setNormalization(NormalizeColumns); | |
3644 } else if (columnNormalization == "hybrid") { | |
3645 setNormalization(NormalizeHybrid); | |
3646 } else if (columnNormalization == "none") { | |
3647 // do nothing | |
3648 } else { | |
3649 cerr << "NOTE: Unknown or unsupported columnNormalization attribute \"" | |
3650 << columnNormalization << "\"" << endl; | |
3651 } | |
3652 } | |
3653 | |
3654 if (!haveNewStyleNormalization) { | |
3655 | |
3656 bool normalizeColumns = | |
3657 (attributes.value("normalizeColumns").trimmed() == "true"); | |
3658 if (normalizeColumns) { | |
3659 setNormalization(NormalizeColumns); | |
3660 } | |
3661 | |
3662 bool normalizeHybrid = | |
3663 (attributes.value("normalizeHybrid").trimmed() == "true"); | |
3664 if (normalizeHybrid) { | |
3665 setNormalization(NormalizeHybrid); | |
3666 } | |
3623 } | 3667 } |
3624 | 3668 |
3625 bool normalizeVisibleArea = | 3669 bool normalizeVisibleArea = |
3626 (attributes.value("normalizeVisibleArea").trimmed() == "true"); | 3670 (attributes.value("normalizeVisibleArea").trimmed() == "true"); |
3627 if (normalizeVisibleArea) { | 3671 if (normalizeVisibleArea) { |
3628 setNormalization(NormalizeVisibleArea); | 3672 setNormalization(NormalizeVisibleArea); |
3629 } | 3673 } |
3630 | 3674 |
3631 bool normalizeHybrid = | 3675 if (!haveNewStyleNormalization && m_normalization == NormalizeHybrid) { |
3632 (attributes.value("normalizeHybrid").trimmed() == "true"); | 3676 // Tony v1.0 is (and hopefully will remain!) the only released |
3633 if (normalizeHybrid) { | 3677 // SV-a-like to use old-style attributes when saving sessions |
3634 setNormalization(NormalizeHybrid); | 3678 // that ask for hybrid normalization. It saves them with the |
3635 } | 3679 // wrong gain factor, so hack in a fix for that here -- this |
3636 } | 3680 // gives us backward but not forward compatibility. |
3637 | 3681 setGain(m_gain / float(m_fftSize / 2)); |
3682 } | |
3683 } | |
3684 |