# HG changeset patch # User Chris Cannam # Date 1542294488 0 # Node ID 10e768adaee5760d7d58066762c3744761f6b12a # Parent b0eeec95ab5b1d433f6d385d8095925cbb7f102f Retain consistent min freq (rather than min bin no) when changing fft parameters in spectrum; scale ffts by window size rather than fft size in case of oversampling, to avoid fading out because of scale factor including zero padding diff -r b0eeec95ab5b -r 10e768adaee5 layer/SliceLayer.cpp --- a/layer/SliceLayer.cpp Thu Nov 15 14:18:26 2018 +0000 +++ b/layer/SliceLayer.cpp Thu Nov 15 15:08:08 2018 +0000 @@ -1203,7 +1203,23 @@ m_minbin = int(lrint(min)); m_maxbin = int(lrint(max)); - + + if (m_minbin < 0) { + m_minbin = 0; + } + if (m_maxbin < 0) { + m_maxbin = 0; + } + if (m_minbin > m_sliceableModel->getHeight()) { + m_minbin = m_sliceableModel->getHeight(); + } + if (m_maxbin > m_sliceableModel->getHeight()) { + m_maxbin = m_sliceableModel->getHeight(); + } + if (m_maxbin < m_minbin) { + m_maxbin = m_minbin; + } + emit layerParametersChanged(); return true; } @@ -1238,14 +1254,9 @@ int dist = m_sliceableModel->getHeight() - step; if (dist < 1) dist = 1; double centre = m_minbin + (m_maxbin - m_minbin) / 2.0; - m_minbin = int(lrint(centre - dist/2.0)); - if (m_minbin < 0) m_minbin = 0; - m_maxbin = m_minbin + dist; - if (m_maxbin > m_sliceableModel->getHeight()) m_maxbin = m_sliceableModel->getHeight(); - -// SVDEBUG << "SliceLayer::setVerticalZoomStep(" < h) m_minbin = h; @@ -341,12 +346,13 @@ 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)); + int previousOversampling = m_oversampling; m_oversampling = oversampling; + + m_minbin = int(round(getBinForFrequency(m_freqOfMinBin))); + m_maxbin = int(round((double(m_maxbin) / previousOversampling) * + m_oversampling)); int h = getFFTSize() / 2 + 1; if (m_minbin > h) m_minbin = h; @@ -355,7 +361,6 @@ SVDEBUG << m_minbin << " and " << m_maxbin << endl; m_newFFTNeeded = true; - emit layerParametersChanged(); } @@ -385,6 +390,16 @@ } } +bool +SpectrumLayer::setDisplayExtents(double min, double max) +{ + bool result = SliceLayer::setDisplayExtents(min, max); + if (result) { + m_freqOfMinBin = getFrequencyForBin(m_minbin); + } + return result; +} + double SpectrumLayer::getBinForFrequency(double freq) const { diff -r b0eeec95ab5b -r 10e768adaee5 layer/SpectrumLayer.h --- a/layer/SpectrumLayer.h Thu Nov 15 14:18:26 2018 +0000 +++ b/layer/SpectrumLayer.h Thu Nov 15 15:08:08 2018 +0000 @@ -68,6 +68,8 @@ virtual void setProperty(const PropertyName &, int value) override; virtual void setProperties(const QXmlAttributes &) override; + virtual bool setDisplayExtents(double min, double max) override; + virtual bool getXScaleValue(const LayerGeometryProvider *v, int x, double &value, QString &unit) const override; @@ -123,6 +125,10 @@ bool m_showPeaks; mutable bool m_newFFTNeeded; + double m_freqOfMinBin; // used to ensure accurate + // alignment when changing + // fft size + mutable QMutex m_fftMutex; void setupFFT();