Mercurial > hg > svgui
comparison 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 |
comparison
equal
deleted
inserted
replaced
1136:9ff838a64461 | 1137:4e7ed3252d80 |
---|---|
71 m_initialRotation(0), | 71 m_initialRotation(0), |
72 m_minFrequency(10), | 72 m_minFrequency(10), |
73 m_maxFrequency(8000), | 73 m_maxFrequency(8000), |
74 m_initialMaxFrequency(8000), | 74 m_initialMaxFrequency(8000), |
75 m_colourScale(ColourScaleType::Log), | 75 m_colourScale(ColourScaleType::Log), |
76 m_colourScaleMultiple(1.0), | |
76 m_colourMap(0), | 77 m_colourMap(0), |
77 m_binScale(BinScale::Linear), | 78 m_binScale(BinScale::Linear), |
78 m_binDisplay(BinDisplay::AllBins), | 79 m_binDisplay(BinDisplay::AllBins), |
79 m_normalization(ColumnNormalization::None), | 80 m_normalization(ColumnNormalization::None), |
80 m_normalizeVisibleArea(false), | 81 m_normalizeVisibleArea(false), |
133 { | 134 { |
134 invalidateRenderers(); | 135 invalidateRenderers(); |
135 invalidateFFTModel(); | 136 invalidateFFTModel(); |
136 } | 137 } |
137 | 138 |
138 ColourScaleType | 139 pair<ColourScaleType, double> |
139 SpectrogramLayer::convertToColourScale(int value) | 140 SpectrogramLayer::convertToColourScale(int value) |
140 { | 141 { |
141 switch (value) { | 142 switch (value) { |
142 case 0: return ColourScaleType::Linear; | 143 case 0: return { ColourScaleType::Linear, 1.0 }; |
143 case 1: return ColourScaleType::Meter; | 144 case 1: return { ColourScaleType::Meter, 1.0 }; |
144 case 2: return ColourScaleType::Log; //!!! db^2 | 145 case 2: return { ColourScaleType::Log, 2.0 }; // dB^2 (i.e. log of power) |
145 case 3: return ColourScaleType::Log; | 146 case 3: return { ColourScaleType::Log, 1.0 }; // dB (of magnitude) |
146 case 4: return ColourScaleType::Phase; | 147 case 4: return { ColourScaleType::Phase, 1.0 }; |
147 default: return ColourScaleType::Linear; | 148 default: return { ColourScaleType::Linear, 1.0 }; |
148 } | 149 } |
149 } | 150 } |
150 | 151 |
151 int | 152 int |
152 SpectrogramLayer::convertFromColourScale(ColourScaleType scale) | 153 SpectrogramLayer::convertFromColourScale(ColourScaleType scale, double multiple) |
153 { | 154 { |
154 switch (scale) { | 155 switch (scale) { |
155 case ColourScaleType::Linear: return 0; | 156 case ColourScaleType::Linear: return 0; |
156 case ColourScaleType::Meter: return 1; | 157 case ColourScaleType::Meter: return 1; |
157 case ColourScaleType::Log: return 3; //!!! + db^2 | 158 case ColourScaleType::Log: return (multiple > 1.5 ? 2 : 3); |
158 case ColourScaleType::Phase: return 4; | 159 case ColourScaleType::Phase: return 4; |
159 | |
160 case ColourScaleType::PlusMinusOne: | 160 case ColourScaleType::PlusMinusOne: |
161 case ColourScaleType::Absolute: | 161 case ColourScaleType::Absolute: |
162 default: return 0; | 162 default: return 0; |
163 } | 163 } |
164 } | 164 } |
328 // linear, meter, db^2, db, phase | 328 // linear, meter, db^2, db, phase |
329 *min = 0; | 329 *min = 0; |
330 *max = 4; | 330 *max = 4; |
331 *deflt = 2; | 331 *deflt = 2; |
332 | 332 |
333 val = convertFromColourScale(m_colourScale); | 333 val = convertFromColourScale(m_colourScale, m_colourScaleMultiple); |
334 | 334 |
335 } else if (name == "Colour") { | 335 } else if (name == "Colour") { |
336 | 336 |
337 *min = 0; | 337 *min = 0; |
338 *max = ColourMapper::getColourMapCount() - 1; | 338 *max = ColourMapper::getColourMapCount() - 1; |
588 if (vs != m_lastEmittedZoomStep) { | 588 if (vs != m_lastEmittedZoomStep) { |
589 emit verticalZoomChanged(); | 589 emit verticalZoomChanged(); |
590 m_lastEmittedZoomStep = vs; | 590 m_lastEmittedZoomStep = vs; |
591 } | 591 } |
592 } else if (name == "Colour Scale") { | 592 } else if (name == "Colour Scale") { |
593 setColourScaleMultiple(1.0); | |
593 switch (value) { | 594 switch (value) { |
594 default: | 595 default: |
595 case 0: setColourScale(ColourScaleType::Linear); break; | 596 case 0: setColourScale(ColourScaleType::Linear); break; |
596 case 1: setColourScale(ColourScaleType::Meter); break; | 597 case 1: setColourScale(ColourScaleType::Meter); break; |
597 case 2: setColourScale(ColourScaleType::Log); break; //!!! dB^2 | 598 case 2: |
599 setColourScale(ColourScaleType::Log); | |
600 setColourScaleMultiple(2.0); | |
601 break; | |
598 case 3: setColourScale(ColourScaleType::Log); break; | 602 case 3: setColourScale(ColourScaleType::Log); break; |
599 case 4: setColourScale(ColourScaleType::Phase); break; | 603 case 4: setColourScale(ColourScaleType::Phase); break; |
600 } | 604 } |
601 } else if (name == "Frequency Scale") { | 605 } else if (name == "Frequency Scale") { |
602 switch (value) { | 606 switch (value) { |
876 { | 880 { |
877 return m_colourScale; | 881 return m_colourScale; |
878 } | 882 } |
879 | 883 |
880 void | 884 void |
885 SpectrogramLayer::setColourScaleMultiple(double multiple) | |
886 { | |
887 if (m_colourScaleMultiple == multiple) return; | |
888 | |
889 invalidateRenderers(); | |
890 | |
891 m_colourScaleMultiple = multiple; | |
892 | |
893 emit layerParametersChanged(); | |
894 } | |
895 | |
896 double | |
897 SpectrogramLayer::getColourScaleMultiple() const | |
898 { | |
899 return m_colourScaleMultiple; | |
900 } | |
901 | |
902 void | |
881 SpectrogramLayer::setColourMap(int map) | 903 SpectrogramLayer::setColourMap(int map) |
882 { | 904 { |
883 if (m_colourMap == map) return; | 905 if (m_colourMap == map) return; |
884 | 906 |
885 invalidateRenderers(); | 907 invalidateRenderers(); |
1406 sources.source = sources.fft; | 1428 sources.source = sources.fft; |
1407 sources.peaks = getPeakCache(); | 1429 sources.peaks = getPeakCache(); |
1408 | 1430 |
1409 ColourScale::Parameters cparams; | 1431 ColourScale::Parameters cparams; |
1410 cparams.colourMap = m_colourMap; | 1432 cparams.colourMap = m_colourMap; |
1411 cparams.scale = m_colourScale; | 1433 cparams.scaleType = m_colourScale; |
1434 cparams.multiple = m_colourScaleMultiple; | |
1412 | 1435 |
1413 if (m_colourScale != ColourScaleType::Phase) { | 1436 if (m_colourScale != ColourScaleType::Phase) { |
1414 cparams.gain = m_gain; | 1437 cparams.gain = m_gain; |
1415 cparams.threshold = m_threshold; | 1438 cparams.threshold = m_threshold; |
1416 } | 1439 } |
1421 if (m_normalizeVisibleArea && m_viewMags[viewId].isSet()) { | 1444 if (m_normalizeVisibleArea && m_viewMags[viewId].isSet()) { |
1422 minValue = m_viewMags[viewId].getMin(); | 1445 minValue = m_viewMags[viewId].getMin(); |
1423 maxValue = m_viewMags[viewId].getMax(); | 1446 maxValue = m_viewMags[viewId].getMax(); |
1424 } else if (m_colourScale == ColourScaleType::Linear && | 1447 } else if (m_colourScale == ColourScaleType::Linear && |
1425 m_normalization == ColumnNormalization::None) { | 1448 m_normalization == ColumnNormalization::None) { |
1426 //!!! This should not be necessary -- what is the actual range | |
1427 maxValue = 0.1f; | 1449 maxValue = 0.1f; |
1428 } | 1450 } |
1429 | 1451 |
1430 if (maxValue <= minValue) { | 1452 if (maxValue <= minValue) { |
1431 maxValue = minValue + 0.1f; | 1453 maxValue = minValue + 0.1f; |
2382 "colourRotation=\"%5\" " | 2404 "colourRotation=\"%5\" " |
2383 "frequencyScale=\"%6\" " | 2405 "frequencyScale=\"%6\" " |
2384 "binDisplay=\"%7\" ") | 2406 "binDisplay=\"%7\" ") |
2385 .arg(m_minFrequency) | 2407 .arg(m_minFrequency) |
2386 .arg(m_maxFrequency) | 2408 .arg(m_maxFrequency) |
2387 .arg(convertFromColourScale(m_colourScale)) | 2409 .arg(convertFromColourScale(m_colourScale, m_colourScaleMultiple)) |
2388 .arg(m_colourMap) | 2410 .arg(m_colourMap) |
2389 .arg(m_colourRotation) | 2411 .arg(m_colourRotation) |
2390 .arg(int(m_binScale)) | 2412 .arg(int(m_binScale)) |
2391 .arg(int(m_binDisplay)); | 2413 .arg(int(m_binDisplay)); |
2392 | 2414 |
2457 if (ok) { | 2479 if (ok) { |
2458 SVDEBUG << "SpectrogramLayer::setProperties: setting max freq to " << maxFrequency << endl; | 2480 SVDEBUG << "SpectrogramLayer::setProperties: setting max freq to " << maxFrequency << endl; |
2459 setMaxFrequency(maxFrequency); | 2481 setMaxFrequency(maxFrequency); |
2460 } | 2482 } |
2461 | 2483 |
2462 ColourScaleType colourScale = convertToColourScale | 2484 auto colourScale = convertToColourScale |
2463 (attributes.value("colourScale").toInt(&ok)); | 2485 (attributes.value("colourScale").toInt(&ok)); |
2464 if (ok) setColourScale(colourScale); | 2486 if (ok) { |
2487 setColourScale(colourScale.first); | |
2488 setColourScaleMultiple(colourScale.second); | |
2489 } | |
2465 | 2490 |
2466 int colourMap = attributes.value("colourScheme").toInt(&ok); | 2491 int colourMap = attributes.value("colourScheme").toInt(&ok); |
2467 if (ok) setColourMap(colourMap); | 2492 if (ok) setColourMap(colourMap); |
2468 | 2493 |
2469 int colourRotation = attributes.value("colourRotation").toInt(&ok); | 2494 int colourRotation = attributes.value("colourRotation").toInt(&ok); |