global peak label moved to the spectrogram

This commit is contained in:
2026-03-25 21:54:03 +01:00
parent 1918645d53
commit 67247654cf
4 changed files with 21 additions and 9 deletions

View File

@@ -797,14 +797,6 @@ void Application::renderControlPanel() {
ImGui::TextDisabled("Mode: %s", settings_.isIQ ? "I/Q" ImGui::TextDisabled("Mode: %s", settings_.isIQ ? "I/Q"
: (settings_.numChannels > 1 ? "Multi-ch" : "Real")); : (settings_.numChannels > 1 ? "Multi-ch" : "Real"));
int pkCh2 = std::clamp(waterfallChannel_, 0, analyzer_.numSpectra() - 1);
auto [peakBin, peakDB] = analyzer_.findPeak(pkCh2);
double peakFreq = analyzer_.binToFreq(peakBin);
{
char peakBuf[128];
fmtFreqDB(peakBuf, sizeof(peakBuf), "Peak", peakFreq, peakDB);
ImGui::TextDisabled("%s", peakBuf);
}
} }
void Application::renderSpectrumPanel() { void Application::renderSpectrumPanel() {

View File

@@ -123,7 +123,7 @@ void Cursors::draw(const SpectrumDisplay& specDisplay,
fmtFreqDB(deltaBuf, sizeof(deltaBuf), "D", dFreq, dDB); fmtFreqDB(deltaBuf, sizeof(deltaBuf), "D", dFreq, dDB);
ImVec2 dSz = ImGui::CalcTextSize(deltaBuf); ImVec2 dSz = ImGui::CalcTextSize(deltaBuf);
float tx = posX + sizeX - dSz.x - 178; float tx = posX + sizeX - dSz.x - 168;
float lineH = ImGui::GetTextLineHeight(); float lineH = ImGui::GetTextLineHeight();
float ty = posY + 4; float ty = posY + 4;
ImU32 col = IM_COL32(255, 200, 100, 255); ImU32 col = IM_COL32(255, 200, 100, 255);

View File

@@ -63,6 +63,15 @@ void Measurements::findPeaks(const std::vector<float>& spectrumDB, int maxN,
void Measurements::update(const std::vector<float>& spectrumDB, void Measurements::update(const std::vector<float>& spectrumDB,
double sampleRate, bool isIQ, int fftSize) { double sampleRate, bool isIQ, int fftSize) {
// Always track global peak (for the readout label).
if (!spectrumDB.empty()) {
auto it = std::max_element(spectrumDB.begin(), spectrumDB.end());
int bin = static_cast<int>(std::distance(spectrumDB.begin(), it));
globalPeak_.bin = bin;
globalPeak_.dB = *it;
globalPeak_.freq = binToFreq(bin, sampleRate, isIQ, fftSize);
}
if (!enabled) { peaks_.clear(); return; } if (!enabled) { peaks_.clear(); return; }
findPeaks(spectrumDB, maxPeaks, minPeakDist, peakThreshold); findPeaks(spectrumDB, maxPeaks, minPeakDist, peakThreshold);
@@ -78,6 +87,16 @@ void Measurements::draw(const SpectrumDisplay& specDisplay,
double sampleRate, bool isIQ, FreqScale freqScale, double sampleRate, bool isIQ, FreqScale freqScale,
float minDB, float maxDB, float minDB, float maxDB,
float viewLo, float viewHi) const { float viewLo, float viewHi) const {
// Global peak readout (always shown, left of cursor delta)
{
char pkBuf[128];
fmtFreqDB(pkBuf, sizeof(pkBuf), "Peak", globalPeak_.freq, globalPeak_.dB);
ImVec2 pkSz = ImGui::CalcTextSize(pkBuf);
float pkX = posX + sizeX - pkSz.x - 8 - 350;
float pkY = posY + 4;
ImGui::GetWindowDrawList()->AddText({pkX, pkY}, IM_COL32(180, 180, 200, 200), pkBuf);
}
if (!enabled || !showOnSpectrum || peaks_.empty()) return; if (!enabled || !showOnSpectrum || peaks_.empty()) return;
ImDrawList* dl = ImGui::GetWindowDrawList(); ImDrawList* dl = ImGui::GetWindowDrawList();

View File

@@ -46,6 +46,7 @@ public:
bool showOnWaterfall = false; // draw vertical lines on waterfall bool showOnWaterfall = false; // draw vertical lines on waterfall
private: private:
PeakInfo globalPeak_; // always-tracked highest peak
std::vector<PeakInfo> peaks_; std::vector<PeakInfo> peaks_;
// Find top-N peaks with minimum bin separation. // Find top-N peaks with minimum bin separation.