# HG changeset patch # User Chris Cannam # Date 1465977127 -3600 # Node ID e1c2dcc7790e585a0861797868b0b2dc03d69459 # Parent 9a13bc339fa93c02cc5fcc82a43c311deed123de A couple more helper functions diff -r 9a13bc339fa9 -r e1c2dcc7790e layer/SpectrogramLayer.cpp --- a/layer/SpectrogramLayer.cpp Mon Jun 13 16:17:44 2016 +0100 +++ b/layer/SpectrogramLayer.cpp Wed Jun 15 08:52:07 2016 +0100 @@ -2410,7 +2410,7 @@ } void -SpectrogramLayer::scaleColumn(vector &col) +SpectrogramLayer::scaleColumn(vector &col) const { if (m_normalization != NormalizeColumns && m_normalization != NormalizeHybrid) { @@ -2437,7 +2437,7 @@ int h, const vector &binfory, int minbin, - bool interpolate) + bool interpolate) const { vector out(h, 0.f); int bins = int(in.size()); @@ -2465,23 +2465,12 @@ other = bin; } - if (m_binDisplay == PeakBins) { - - if (is_peak(in, bin)) { - out[y] = in[bin]; - } else if (other != bin && is_peak(in, other)) { - out[y] = in[other]; - } + double prop = 1.0 - fabs(dist); + + double v0 = in[bin]; + double v1 = in[other]; - } else { - - double prop = 1.0 - fabs(dist); - - double v0 = in[bin]; - double v1 = in[other]; - - out[y] = float(prop * v0 + (1.0 - prop) * v1); - } + out[y] = float(prop * v0 + (1.0 - prop) * v1); } else { // not interpolating this one @@ -2491,10 +2480,6 @@ for (int bin = by0; bin < by1; ++bin) { - if (m_binDisplay == PeakBins && !is_peak(in, bin)) { - continue; - } - float value = in[bin]; if (value > out[y] || m_colourScale == PhaseColourScale) { @@ -2511,12 +2496,8 @@ SpectrogramLayer::recordColumnExtents(const vector &col, int sx, // column index, for m_columnMags MagnitudeRange &overallMag, - bool &overallMagChanged) + bool &overallMagChanged) const { - //!!! this differs from previous logic when in peak mode - as the - //!!! zeros between peaks are now sampled, where they were not - //!!! before - if (!in_range_for(sx, m_columnMags)) { throw logic_error("sx out of range for m_columnMags"); } @@ -2530,8 +2511,37 @@ } } +vector +SpectrogramLayer::peakPickColumn(const vector &in) const +{ + if (m_binDisplay != PeakBins) return in; + + vector out(in.size(), 0.f); + + for (int i = 0; in_range_for(i, in); ++i) { + if (is_peak(in, i)) { + out[i] = in[i]; + } + } + + return move(out); +} + +vector +SpectrogramLayer::applyDisplayGain(const vector &in) const +{ + if (m_gain == 1.0) return in; + + vector out; + out.reserve(in.size()); + for (auto v: in) { + out.push_back(v * m_gain); + } + return move(out); +} + // order: -// get column -> scale -> distribute/interpolate -> record extents -> normalise -> apply display gain +// get column -> scale -> distribute/interpolate -> record extents -> normalise -> peak pick -> apply display gain int SpectrogramLayer::paintDrawBuffer(LayerGeometryProvider *v, diff -r 9a13bc339fa9 -r e1c2dcc7790e layer/SpectrogramLayer.h --- a/layer/SpectrogramLayer.h Mon Jun 13 16:17:44 2016 +0100 +++ b/layer/SpectrogramLayer.h Wed Jun 15 08:52:07 2016 +0100 @@ -400,6 +400,21 @@ int bincount) const; void scaleColumn(std::vector &col) const; + + std::vector distributeColumn(const std::vector &in, + int h, + const std::vector &binfory, + int minbin, + bool interpolate) const; + + void recordColumnExtents(const std::vector &col, + int sx, + MagnitudeRange &overallMag, + bool &overallMagChanged) const; + + std::vector peakPickColumn(const std::vector &in) const; + + std::vector applyDisplayGain(const std::vector &in) const; virtual void updateMeasureRectYCoords(LayerGeometryProvider *v, const MeasureRect &r) const;