Mercurial > hg > svgui
diff layer/SpectrumLayer.cpp @ 1400:decb7741d036
Different approach to x-coord calculation in slice layer - let's acknowledge that we really do have two different types of model, those whose "bins" are actually at a single value (frequency in the case of the spectrum) and those whose bins are just labels.
author | Chris Cannam |
---|---|
date | Thu, 15 Nov 2018 13:06:38 +0000 |
parents | ba1f0234efa7 |
children | 10e768adaee5 |
line wrap: on
line diff
--- a/layer/SpectrumLayer.cpp Wed Nov 14 15:47:21 2018 +0000 +++ b/layer/SpectrumLayer.cpp Thu Nov 15 13:06:38 2018 +0000 @@ -43,6 +43,8 @@ m_showPeaks(false), m_newFFTNeeded(true) { + m_binAlignment = BinsCentredOnScalePoints; + Preferences *prefs = Preferences::getInstance(); connect(prefs, SIGNAL(propertyChanged(PropertyContainer::PropertyName)), this, SLOT(preferenceChanged(PropertyContainer::PropertyName))); @@ -126,7 +128,7 @@ m_minbin = 1; m_maxbin = newFFT->getHeight(); } - + setSliceableModel(newFFT); m_biasCurve.clear(); @@ -296,13 +298,19 @@ SVDEBUG << "setWindowSize: from " << m_windowSize << " to " << ws << ": updating min and max bins from " << m_minbin << " and " << m_maxbin << " to "; - + /* m_minbin = int(round((double(m_minbin) / m_windowSize) * ws)); + */ m_maxbin = int(round((double(m_maxbin) / m_windowSize) * ws)); + m_windowSize = ws; + + int h = getFFTSize() / 2 + 1; + if (m_minbin > h) m_minbin = h; + if (m_maxbin > h) m_maxbin = h; + SVDEBUG << m_minbin << " and " << m_maxbin << endl; - m_windowSize = ws; m_newFFTNeeded = true; emit layerParametersChanged(); } @@ -333,13 +341,19 @@ SVDEBUG << "setOversampling: from " << m_oversampling << " to " << oversampling << ": updating min and max bins from " << m_minbin << " and " << m_maxbin << " to "; - +/* m_minbin = int(round((double(m_minbin) / m_oversampling) * oversampling)); +*/ m_maxbin = int(round((double(m_maxbin) / m_oversampling) * oversampling)); + m_oversampling = oversampling; + + int h = getFFTSize() / 2 + 1; + if (m_minbin > h) m_minbin = h; + if (m_maxbin > h) m_maxbin = h; + SVDEBUG << m_minbin << " and " << m_maxbin << endl; - m_oversampling = oversampling; m_newFFTNeeded = true; emit layerParametersChanged(); @@ -376,9 +390,6 @@ { if (!m_sliceableModel) return 0; double bin = (freq * getFFTSize()) / m_sliceableModel->getSampleRate(); - // we assume the frequency of a bin corresponds to the centre of - // its visual range - bin += 0.5; return bin; } @@ -396,17 +407,6 @@ if (!m_sliceableModel) return 0; double fmin = getFrequencyForBin(m_minbin); - - if (m_binScale == LogBins && m_minbin == 0) { - // Avoid too much space going to the first bin, but do so in a - // way that usually avoids us shifting left/right as the - // window size or oversampling ratio change - i.e. base this - // on frequency rather than bin number unless we have a lot of - // very low-resolution content - fmin = getFrequencyForBin(0.8); - if (fmin > 6.0) fmin = 6.0; - } - double fmax = getFrequencyForBin(m_maxbin); double freq = getScalePointForX(v, x, fmin, fmax); @@ -417,9 +417,6 @@ SpectrumLayer::getFrequencyForBin(double bin) const { if (!m_sliceableModel) return 0; - // we assume the frequency of a bin corresponds to the centre of - // its visual range - bin -= 0.5; double freq = (bin * m_sliceableModel->getSampleRate()) / getFFTSize(); return freq; } @@ -438,13 +435,6 @@ if (!m_sliceableModel) return 0; double fmin = getFrequencyForBin(m_minbin); - - if (m_binScale == LogBins && m_minbin == 0) { - // See comment in getFrequencyForX above - fmin = getFrequencyForBin(0.8); - if (fmin > 6.0) fmin = 6.0; - } - double fmax = getFrequencyForBin(m_maxbin); double x = getXForScalePoint(v, freq, fmin, fmax);