From 6036f62ae496f66bc3bc98eb4aabe6ba5351aa38 Mon Sep 17 00:00:00 2001 From: f4exb Date: Thu, 22 Jul 2021 08:48:26 +0200 Subject: [PATCH] GLSpectrum: implement power tracking histogram markers --- sdrgui/gui/glspectrum.cpp | 49 ++++++++++++++++++++++++++++----------- sdrgui/gui/glspectrum.h | 11 +++++++++ 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/sdrgui/gui/glspectrum.cpp b/sdrgui/gui/glspectrum.cpp index e33d7ae91..afc29ee80 100644 --- a/sdrgui/gui/glspectrum.cpp +++ b/sdrgui/gui/glspectrum.cpp @@ -1143,23 +1143,35 @@ void GLSpectrum::drawMarkers() // paint histogram markers if (m_histogramMarkers.size() > 0) { - // crosshairs for (int i = 0; i < m_histogramMarkers.size(); i++) { + QPointF ypoint = m_histogramMarkers.at(i).m_point; + QString powerStr = m_histogramMarkers.at(i).m_powerStr; + + if (m_histogramMarkers.at(i).m_markerType == HistogramMarkerTypePower) + { + ypoint.ry() = + (m_powerScale.getRangeMax() - m_currentSpectrum[m_histogramMarkers.at(i).m_fftBin]) / m_powerScale.getRange(); + powerStr = displayScaledF( + m_currentSpectrum[m_histogramMarkers.at(i).m_fftBin], + m_linear ? 'e' : 'f', + m_linear ? 3 : 1, + false + ); + } + + // crosshairs GLfloat h[] { (float) m_histogramMarkers.at(i).m_point.x(), 0, (float) m_histogramMarkers.at(i).m_point.x(), 1 }; m_glShaderSimple.drawSegments(m_glHistogramBoxMatrix, markerColor, h, 2); GLfloat v[] { - 0, (float) m_histogramMarkers.at(i).m_point.y(), - 1, (float) m_histogramMarkers.at(i).m_point.y() + 0, (float) ypoint.y(), + 1, (float) ypoint.y() }; m_glShaderSimple.drawSegments(m_glHistogramBoxMatrix, markerColor, v, 2); - } - // text - for (int i = 0; i < m_histogramMarkers.size(); i++) - { + // text if (i == 0) { drawTextOverlay( @@ -1172,17 +1184,28 @@ void GLSpectrum::drawMarkers() !m_invertedWaterfall && (m_waterfallHeight != 0), m_histogramRect); drawTextOverlay( - m_histogramMarkers.at(i).m_powerStr, + powerStr, QColor(255, 255, 255, 192), m_textOverlayFont, 0, - m_histogramMarkers.at(i).m_point.y() * m_histogramRect.height(), + ypoint.y() * m_histogramRect.height(), true, - m_histogramMarkers.at(i).m_point.y() < 0.5f, + ypoint.y() < 0.5f, m_histogramRect); } else { + float power0 = m_histogramMarkers.at(0).m_markerType == HistogramMarkerTypePower ? + m_currentSpectrum[m_histogramMarkers.at(0).m_fftBin] : + m_histogramMarkers.at(0).m_power; + float poweri = m_histogramMarkers.at(i).m_markerType == HistogramMarkerTypePower ? + m_currentSpectrum[m_histogramMarkers.at(i).m_fftBin] : + m_histogramMarkers.at(i).m_power; + QString deltaPowerStr = displayScaledF( + poweri - power0, + m_linear ? 'e' : 'f', + m_linear ? 3 : 1, + false); drawTextOverlay( m_histogramMarkers.at(i).m_deltaFrequencyStr, QColor(255, 255, 255, 192), @@ -1193,13 +1216,13 @@ void GLSpectrum::drawMarkers() (m_invertedWaterfall || (m_waterfallHeight == 0)), m_histogramRect); drawTextOverlay( - m_histogramMarkers.at(i).m_deltaPowerStr, + deltaPowerStr, QColor(255, 255, 255, 192), m_textOverlayFont, m_histogramRect.width(), - m_histogramMarkers.at(i).m_point.y() * m_histogramRect.height(), + ypoint.y() * m_histogramRect.height(), false, - m_histogramMarkers.at(i).m_point.y() < 0.5f, + ypoint.y() < 0.5f, m_histogramRect); } } diff --git a/sdrgui/gui/glspectrum.h b/sdrgui/gui/glspectrum.h index e54f98cc1..f461dd357 100644 --- a/sdrgui/gui/glspectrum.h +++ b/sdrgui/gui/glspectrum.h @@ -175,11 +175,18 @@ private: CSChannel, CSChannelMoving }; + + enum HistogramMarkerType { + HistogramMarkerTypeManual, + HistogramMarkerTypePower + }; + struct HistogramMarker { QPointF m_point; float m_frequency; int m_fftBin; float m_power; + HistogramMarkerType m_markerType; QString m_frequencyStr; QString m_powerStr; QString m_deltaFrequencyStr; @@ -189,6 +196,7 @@ private: m_frequency(0), m_fftBin(0), m_power(0), + m_markerType(HistogramMarkerTypeManual), m_frequencyStr(), m_powerStr(), m_deltaFrequencyStr(), @@ -199,6 +207,7 @@ private: float frequency, int fftBin, float power, + HistogramMarkerType markerType, const QString& frequencyStr, const QString& powerStr, const QString& deltaFrequencyStr, @@ -208,6 +217,7 @@ private: m_frequency(frequency), m_fftBin(fftBin), m_power(power), + m_markerType(markerType), m_frequencyStr(frequencyStr), m_powerStr(powerStr), m_deltaFrequencyStr(deltaFrequencyStr), @@ -218,6 +228,7 @@ private: m_frequency(other.m_frequency), m_fftBin(other.m_fftBin), m_power(other.m_power), + m_markerType(other.m_markerType), m_frequencyStr(other.m_frequencyStr), m_powerStr(other.m_powerStr), m_deltaFrequencyStr(other.m_deltaFrequencyStr),