# HG changeset patch # User Chris Cannam # Date 1454584643 0 # Node ID fcedcc7f0d87e6bcd4e93d6f71a5c55ab4fa3e11 # Parent 7242fe160c19015cf79440223b2f998236ea205f# Parent 96cf499fad621fb15e4d9d4103da1dfd7f73d9e9 Merge from branch "tony-2.0-integration" diff -r 7242fe160c19 -r fcedcc7f0d87 layer/SpectrogramLayer.cpp --- a/layer/SpectrogramLayer.cpp Wed Nov 18 12:08:33 2015 +0000 +++ b/layer/SpectrogramLayer.cpp Thu Feb 04 11:17:23 2016 +0000 @@ -1887,7 +1887,7 @@ } else { RealTime lastTime = m_lastPaintTime; while (lastTime > RealTime::fromMilliseconds(200) && - paintBlockWidth > 50) { + paintBlockWidth > 100) { paintBlockWidth /= 2; lastTime = lastTime / 2; } @@ -1898,7 +1898,7 @@ } } - if (paintBlockWidth < 20) paintBlockWidth = 20; + if (paintBlockWidth < 50) paintBlockWidth = 50; } #ifdef DEBUG_SPECTROGRAM_REPAINT @@ -2401,11 +2401,11 @@ } else if (m_normalization == NormalizeColumns) { fft->getNormalizedMagnitudesAt(sx, values, minbin, maxbin - minbin + 1); } else if (m_normalization == NormalizeHybrid) { - fft->getNormalizedMagnitudesAt(sx, values, minbin, maxbin - minbin + 1); - double max = fft->getMaximumMagnitudeAt(sx); + float max = fft->getNormalizedMagnitudesAt(sx, values, minbin, maxbin - minbin + 1); if (max > 0.f) { for (int i = minbin; i <= maxbin; ++i) { - values[i - minbin] = float(values[i - minbin] * log10(max)); + values[i - minbin] = float(values[i - minbin] * + log10f(max)); } } } else { @@ -2568,8 +2568,7 @@ } else if (m_normalization == NormalizeColumns) { fft->getNormalizedMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1); } else if (m_normalization == NormalizeHybrid) { - fft->getNormalizedMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1); - float max = fft->getMaximumMagnitudeAt(sx); + float max = fft->getNormalizedMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1); float scale = log10f(max + 1.f); // cout << "sx = " << sx << ", max = " << max << ", log10(max) = " << log10(max) << ", scale = " << scale << endl; for (int i = minbin; i <= maxbin; ++i) { @@ -3545,13 +3544,29 @@ .arg(m_frequencyScale) .arg(m_binDisplay); - s += QString("normalizeColumns=\"%1\" " - "normalizeVisibleArea=\"%2\" " - "normalizeHybrid=\"%3\" ") - .arg(m_normalization == NormalizeColumns ? "true" : "false") - .arg(m_normalization == NormalizeVisibleArea ? "true" : "false") - .arg(m_normalization == NormalizeHybrid ? "true" : "false"); - + // New-style normalization attributes, allowing for more types of + // normalization in future: write out the column normalization + // type separately, and then whether we are normalizing visible + // area as well afterwards + + s += QString("columnNormalization=\"%1\" ") + .arg(m_normalization == NormalizeColumns ? "peak" : + m_normalization == NormalizeHybrid ? "hybrid" : "none"); + + // Old-style normalization attribute. We *don't* write out + // normalizeHybrid here because the only release that would accept + // it (Tony v1.0) has a totally different scale factor for + // it. We'll just have to accept that session files from Tony + // v2.0+ will look odd in Tony v1.0 + + s += QString("normalizeColumns=\"%1\" ") + .arg(m_normalization == NormalizeColumns ? "true" : "false"); + + // And this applies to both old- and new-style attributes + + s += QString("normalizeVisibleArea=\"%1\" ") + .arg(m_normalization == NormalizeVisibleArea ? "true" : "false"); + Layer::toXml(stream, indent, extraAttributes + " " + s); } @@ -3616,10 +3631,39 @@ attributes.value("binDisplay").toInt(&ok); if (ok) setBinDisplay(binDisplay); - bool normalizeColumns = - (attributes.value("normalizeColumns").trimmed() == "true"); - if (normalizeColumns) { - setNormalization(NormalizeColumns); + bool haveNewStyleNormalization = false; + + QString columnNormalization = attributes.value("columnNormalization"); + + if (columnNormalization != "") { + + haveNewStyleNormalization = true; + + if (columnNormalization == "peak") { + setNormalization(NormalizeColumns); + } else if (columnNormalization == "hybrid") { + setNormalization(NormalizeHybrid); + } else if (columnNormalization == "none") { + // do nothing + } else { + cerr << "NOTE: Unknown or unsupported columnNormalization attribute \"" + << columnNormalization << "\"" << endl; + } + } + + if (!haveNewStyleNormalization) { + + bool normalizeColumns = + (attributes.value("normalizeColumns").trimmed() == "true"); + if (normalizeColumns) { + setNormalization(NormalizeColumns); + } + + bool normalizeHybrid = + (attributes.value("normalizeHybrid").trimmed() == "true"); + if (normalizeHybrid) { + setNormalization(NormalizeHybrid); + } } bool normalizeVisibleArea = @@ -3628,10 +3672,13 @@ setNormalization(NormalizeVisibleArea); } - bool normalizeHybrid = - (attributes.value("normalizeHybrid").trimmed() == "true"); - if (normalizeHybrid) { - setNormalization(NormalizeHybrid); + if (!haveNewStyleNormalization && m_normalization == NormalizeHybrid) { + // Tony v1.0 is (and hopefully will remain!) the only released + // SV-a-like to use old-style attributes when saving sessions + // that ask for hybrid normalization. It saves them with the + // wrong gain factor, so hack in a fix for that here -- this + // gives us backward but not forward compatibility. + setGain(m_gain / float(m_fftSize / 2)); } }