comparison layer/SpectrogramLayer.cpp @ 1127:9fb8dfd7ce4c spectrogram-minor-refactor

Fix threshold in spectrogram -- it wasn't working in the last release. There is a new protocol for this. Formerly the threshold parameter had a range from -50dB to 0 with the default at -50, and -50 treated internally as "no threshold". However, there was a hardcoded, hidden internal threshold for spectrogram colour mapping at -80dB with anything below this being rounded to zero. Now the threshold parameter has range -81 to -1 with the default at -80, -81 is treated internally as "no threshold", and there is no hidden internal threshold. So the default behaviour is the same as before, an effective -80dB threshold, but it is now possible to change this in both directions. Sessions reloaded from prior versions may look slightly different because, if the session says there should be no threshold, there will now actually be no threshold instead of having the hidden internal one. Still need to do something in the UI to make it apparent that the -81dB setting removes the threshold entirely. This is at least no worse than the previous, also obscured, magic -50dB setting.
author Chris Cannam
date Mon, 01 Aug 2016 16:21:01 +0100
parents 50324fca1328
children 4e022a3e567b
comparison
equal deleted inserted replaced
1126:5c3333fb70b3 1127:9fb8dfd7ce4c
63 m_windowSize(1024), 63 m_windowSize(1024),
64 m_windowType(HanningWindow), 64 m_windowType(HanningWindow),
65 m_windowHopLevel(2), 65 m_windowHopLevel(2),
66 m_gain(1.0), 66 m_gain(1.0),
67 m_initialGain(1.0), 67 m_initialGain(1.0),
68 m_threshold(0.0), 68 m_threshold(1.0e-8),
69 m_initialThreshold(0.0), 69 m_initialThreshold(1.0e-8),
70 m_colourRotation(0), 70 m_colourRotation(0),
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),
302 if (val < *min) val = *min; 302 if (val < *min) val = *min;
303 if (val > *max) val = *max; 303 if (val > *max) val = *max;
304 304
305 } else if (name == "Threshold") { 305 } else if (name == "Threshold") {
306 306
307 *min = -50; 307 *min = -81;
308 *max = 0; 308 *max = -1;
309 309
310 *deflt = int(lrint(AudioLevel::multiplier_to_dB(m_initialThreshold))); 310 *deflt = int(lrint(AudioLevel::multiplier_to_dB(m_initialThreshold)));
311 if (*deflt < *min) *deflt = *min; 311 if (*deflt < *min) *deflt = *min;
312 if (*deflt > *max) *deflt = *max; 312 if (*deflt > *max) *deflt = *max;
313 313
528 { 528 {
529 if (name == "Gain") { 529 if (name == "Gain") {
530 return new LinearRangeMapper(-50, 50, -25, 25, tr("dB")); 530 return new LinearRangeMapper(-50, 50, -25, 25, tr("dB"));
531 } 531 }
532 if (name == "Threshold") { 532 if (name == "Threshold") {
533 return new LinearRangeMapper(-50, 0, -50, 0, tr("dB")); 533 return new LinearRangeMapper(-81, -1, -81, -1, tr("dB"));
534 } 534 }
535 return 0; 535 return 0;
536 } 536 }
537 537
538 void 538 void
539 SpectrogramLayer::setProperty(const PropertyName &name, int value) 539 SpectrogramLayer::setProperty(const PropertyName &name, int value)
540 { 540 {
541 if (name == "Gain") { 541 if (name == "Gain") {
542 setGain(float(pow(10, float(value)/20.0))); 542 setGain(float(pow(10, float(value)/20.0)));
543 } else if (name == "Threshold") { 543 } else if (name == "Threshold") {
544 if (value == -50) setThreshold(0.0); 544 if (value == -81) setThreshold(0.0);
545 else setThreshold(float(AudioLevel::dB_to_multiplier(value))); 545 else setThreshold(float(AudioLevel::dB_to_multiplier(value)));
546 } else if (name == "Colour Rotation") { 546 } else if (name == "Colour Rotation") {
547 setColourRotation(value); 547 setColourRotation(value);
548 } else if (name == "Colour") { 548 } else if (name == "Colour") {
549 setColourMap(value); 549 setColourMap(value);
2053 2053
2054 QString top, bottom; 2054 QString top, bottom;
2055 double min = m_viewMags[v->getId()].getMin(); 2055 double min = m_viewMags[v->getId()].getMin();
2056 double max = m_viewMags[v->getId()].getMax(); 2056 double max = m_viewMags[v->getId()].getMax();
2057 2057
2058 if (min < m_threshold) min = m_threshold;
2059 if (max < min) max = min;
2060
2058 double dBmin = AudioLevel::multiplier_to_dB(min); 2061 double dBmin = AudioLevel::multiplier_to_dB(min);
2059 double dBmax = AudioLevel::multiplier_to_dB(max); 2062 double dBmax = AudioLevel::multiplier_to_dB(max);
2060 2063
2061 #ifdef DEBUG_SPECTROGRAM_REPAINT 2064 #ifdef DEBUG_SPECTROGRAM_REPAINT
2062 cerr << "paintVerticalScale: for view id " << v->getId() 2065 cerr << "paintVerticalScale: for view id " << v->getId()