Files
baudmine/src/ui/SpectrumDisplay.h
2026-04-09 10:20:28 +02:00

60 lines
2.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include "core/Types.h"
#include <imgui.h>
#include <vector>
namespace baudmine {
struct ChannelStyle {
ImU32 lineColor;
ImU32 fillColor;
};
class SpectrumDisplay {
public:
// Draw multiple channel spectra overlaid.
// `spectra` has one entry per channel; `styles` has matching colors.
// viewLo/viewHi (01) control the visible frequency range (zoom/pan).
void draw(const std::vector<std::vector<float>>& spectra,
const std::vector<ChannelStyle>& styles,
float minDB, float maxDB,
double sampleRate, bool isIQ,
FreqScale freqScale,
float posX, float posY, float sizeX, float sizeY,
float viewLo = 0.0f, float viewHi = 1.0f,
int minPixPerBin = 1) const;
// Convenience: single-channel draw (backward compat).
void draw(const std::vector<float>& spectrumDB,
float minDB, float maxDB,
double sampleRate, bool isIQ,
FreqScale freqScale,
float posX, float posY, float sizeX, float sizeY) const;
double screenXToFreq(float screenX, float posX, float sizeX,
double sampleRate, bool isIQ, FreqScale freqScale,
float viewLo = 0.0f, float viewHi = 1.0f) const;
float freqToScreenX(double freq, float posX, float sizeX,
double sampleRate, bool isIQ, FreqScale freqScale,
float viewLo = 0.0f, float viewHi = 1.0f) const;
float screenYToDB(float screenY, float posY, float sizeY,
float minDB, float maxDB) const;
// Peak hold: update with current spectra, then draw the held peaks.
void updatePeakHold(const std::vector<std::vector<float>>& spectra);
void clearPeakHold();
bool showGrid = true;
bool fillSpectrum = false;
bool additiveBlend = true; // additive color mixing for multi-channel
bool peakHoldEnable = false;
float peakHoldDecay = 20.0f; // dB/second decay rate
private:
// One peak-hold trace per channel.
mutable std::vector<std::vector<float>> peakHold_;
};
} // namespace baudmine