Mercurial > hg > svgui
diff layer/SliceLayer.cpp @ 1386:fc3d89f88690 spectrogramparam
Use log-frequency rather than log-bin for calculating x coord in spectrum. This has the advantage that frequency positions don't move when we change the window size or oversampling ratio, but it does give us an unhelpfully large amount of space for very low frequencies - to be considered
author | Chris Cannam |
---|---|
date | Mon, 12 Nov 2018 11:34:34 +0000 |
parents | 413e09f303ba |
children | bca9870301b7 |
line wrap: on
line diff
--- a/layer/SliceLayer.cpp Thu Nov 08 12:55:36 2018 +0000 +++ b/layer/SliceLayer.cpp Mon Nov 12 11:34:34 2018 +0000 @@ -193,13 +193,20 @@ double SliceLayer::getXForBin(const LayerGeometryProvider *v, double bin) const { + return getXForScalePoint(v, bin, m_minbin, m_maxbin); +} + +double +SliceLayer::getXForScalePoint(const LayerGeometryProvider *v, + double p, double pmin, double pmax) const +{ double x = 0; - bin -= m_minbin; - if (bin < 0) bin = 0; + p -= pmin; + if (p < 0) p = 0; - double count = m_maxbin - m_minbin; - if (count < 0) count = 0; + double extent = pmax - pmin; + if (extent < 0) extent = 0; int pw = v->getPaintWidth(); int origin = m_xorigins[v->getId()]; @@ -209,7 +216,7 @@ switch (m_binScale) { case LinearBins: - x = (w * bin) / count; + x = (w * p) / extent; break; case LogBins: @@ -225,11 +232,11 @@ // as "a bit less than 1", so that most of it is visible but a // bit is tactfully cropped at the left edge so it doesn't // take up so much space. - x = (w * log10(bin + 0.8)) / log10(count + 0.8); + x = (w * log10(p + 0.8)) / log10(extent + 0.8); break; case InvertedLogBins: - x = w - (w * log10(count - bin - 1)) / log10(count); + x = w - (w * log10(extent - p - 1)) / log10(extent); break; } @@ -239,10 +246,17 @@ double SliceLayer::getBinForX(const LayerGeometryProvider *v, double x) const { - double bin = 0; + return getScalePointForX(v, x, m_minbin, m_maxbin); +} - double count = m_maxbin - m_minbin; - if (count < 0) count = 0; +double +SliceLayer::getScalePointForX(const LayerGeometryProvider *v, + double x, double pmin, double pmax) const +{ + double p = 0; + + double extent = pmax - pmin; + if (extent < 0) extent = 0; int pw = v->getPaintWidth(); int origin = m_xorigins[v->getId()]; @@ -258,20 +272,20 @@ switch (m_binScale) { case LinearBins: - bin = (x * count) / w + eps; + p = (x * extent) / w + eps; break; case LogBins: - // See comment in getXForBin - bin = pow(10.0, (x * log10(count + 0.8)) / w) - 0.8 + eps; + // See comment in getXForScalePoint + p = pow(10.0, (x * log10(extent + 0.8)) / w) - 0.8 + eps; break; case InvertedLogBins: - bin = count + 1 - pow(10.0, (log10(count) * (w - x)) / double(w)) + eps; + p = extent + 1 - pow(10.0, (log10(extent) * (w - x)) / double(w)) + eps; break; } - return bin + m_minbin; + return p + pmin; } double