Mercurial > hg > svgui
diff layer/SpectrogramLayer.cpp @ 1137:4e7ed3252d80 spectrogram-minor-refactor
Re-implement dB^2 (log-power) spectrogram setting
author | Chris Cannam |
---|---|
date | Thu, 04 Aug 2016 11:26:11 +0100 |
parents | 9ff838a64461 |
children | 2976f57164ac |
line wrap: on
line diff
--- a/layer/SpectrogramLayer.cpp Wed Aug 03 16:16:23 2016 +0100 +++ b/layer/SpectrogramLayer.cpp Thu Aug 04 11:26:11 2016 +0100 @@ -73,6 +73,7 @@ m_maxFrequency(8000), m_initialMaxFrequency(8000), m_colourScale(ColourScaleType::Log), + m_colourScaleMultiple(1.0), m_colourMap(0), m_binScale(BinScale::Linear), m_binDisplay(BinDisplay::AllBins), @@ -135,28 +136,27 @@ invalidateFFTModel(); } -ColourScaleType +pair<ColourScaleType, double> SpectrogramLayer::convertToColourScale(int value) { switch (value) { - case 0: return ColourScaleType::Linear; - case 1: return ColourScaleType::Meter; - case 2: return ColourScaleType::Log; //!!! db^2 - case 3: return ColourScaleType::Log; - case 4: return ColourScaleType::Phase; - default: return ColourScaleType::Linear; + case 0: return { ColourScaleType::Linear, 1.0 }; + case 1: return { ColourScaleType::Meter, 1.0 }; + case 2: return { ColourScaleType::Log, 2.0 }; // dB^2 (i.e. log of power) + case 3: return { ColourScaleType::Log, 1.0 }; // dB (of magnitude) + case 4: return { ColourScaleType::Phase, 1.0 }; + default: return { ColourScaleType::Linear, 1.0 }; } } int -SpectrogramLayer::convertFromColourScale(ColourScaleType scale) +SpectrogramLayer::convertFromColourScale(ColourScaleType scale, double multiple) { switch (scale) { case ColourScaleType::Linear: return 0; case ColourScaleType::Meter: return 1; - case ColourScaleType::Log: return 3; //!!! + db^2 + case ColourScaleType::Log: return (multiple > 1.5 ? 2 : 3); case ColourScaleType::Phase: return 4; - case ColourScaleType::PlusMinusOne: case ColourScaleType::Absolute: default: return 0; @@ -330,7 +330,7 @@ *max = 4; *deflt = 2; - val = convertFromColourScale(m_colourScale); + val = convertFromColourScale(m_colourScale, m_colourScaleMultiple); } else if (name == "Colour") { @@ -590,11 +590,15 @@ m_lastEmittedZoomStep = vs; } } else if (name == "Colour Scale") { + setColourScaleMultiple(1.0); switch (value) { default: case 0: setColourScale(ColourScaleType::Linear); break; case 1: setColourScale(ColourScaleType::Meter); break; - case 2: setColourScale(ColourScaleType::Log); break; //!!! dB^2 + case 2: + setColourScale(ColourScaleType::Log); + setColourScaleMultiple(2.0); + break; case 3: setColourScale(ColourScaleType::Log); break; case 4: setColourScale(ColourScaleType::Phase); break; } @@ -878,6 +882,24 @@ } void +SpectrogramLayer::setColourScaleMultiple(double multiple) +{ + if (m_colourScaleMultiple == multiple) return; + + invalidateRenderers(); + + m_colourScaleMultiple = multiple; + + emit layerParametersChanged(); +} + +double +SpectrogramLayer::getColourScaleMultiple() const +{ + return m_colourScaleMultiple; +} + +void SpectrogramLayer::setColourMap(int map) { if (m_colourMap == map) return; @@ -1408,7 +1430,8 @@ ColourScale::Parameters cparams; cparams.colourMap = m_colourMap; - cparams.scale = m_colourScale; + cparams.scaleType = m_colourScale; + cparams.multiple = m_colourScaleMultiple; if (m_colourScale != ColourScaleType::Phase) { cparams.gain = m_gain; @@ -1423,7 +1446,6 @@ maxValue = m_viewMags[viewId].getMax(); } else if (m_colourScale == ColourScaleType::Linear && m_normalization == ColumnNormalization::None) { - //!!! This should not be necessary -- what is the actual range maxValue = 0.1f; } @@ -2384,7 +2406,7 @@ "binDisplay=\"%7\" ") .arg(m_minFrequency) .arg(m_maxFrequency) - .arg(convertFromColourScale(m_colourScale)) + .arg(convertFromColourScale(m_colourScale, m_colourScaleMultiple)) .arg(m_colourMap) .arg(m_colourRotation) .arg(int(m_binScale)) @@ -2459,9 +2481,12 @@ setMaxFrequency(maxFrequency); } - ColourScaleType colourScale = convertToColourScale + auto colourScale = convertToColourScale (attributes.value("colourScale").toInt(&ok)); - if (ok) setColourScale(colourScale); + if (ok) { + setColourScale(colourScale.first); + setColourScaleMultiple(colourScale.second); + } int colourMap = attributes.value("colourScheme").toInt(&ok); if (ok) setColourMap(colourMap);