[feat](trx-frontend-http): smooth spectrum waveform
Co-authored-by: Codex <codex@openai.com> Signed-off-by: Stan Grams <sjg@haxx.space>
This commit is contained in:
@@ -2988,6 +2988,7 @@ let spectrumSource = null;
|
|||||||
let spectrumReconnectTimer = null;
|
let spectrumReconnectTimer = null;
|
||||||
let spectrumDrawPending = false;
|
let spectrumDrawPending = false;
|
||||||
let spectrumAxisKey = "";
|
let spectrumAxisKey = "";
|
||||||
|
let lastSpectrumRenderData = null;
|
||||||
|
|
||||||
// Zoom / pan state. zoom >= 1; panFrac in [0,1] is the fraction of the full
|
// Zoom / pan state. zoom >= 1; panFrac in [0,1] is the fraction of the full
|
||||||
// bandwidth at the centre of the visible window.
|
// bandwidth at the centre of the visible window.
|
||||||
@@ -2997,6 +2998,7 @@ let spectrumPanFrac = 0.5;
|
|||||||
// Y-axis level: floor = bottom dB value shown; range = total dB span.
|
// Y-axis level: floor = bottom dB value shown; range = total dB span.
|
||||||
let spectrumFloor = -115;
|
let spectrumFloor = -115;
|
||||||
let spectrumRange = 80;
|
let spectrumRange = 80;
|
||||||
|
const SPECTRUM_SMOOTH_ALPHA = 0.42;
|
||||||
|
|
||||||
// BW-strip drag state.
|
// BW-strip drag state.
|
||||||
let _bwDragEdge = null; // "left" | "right" | null
|
let _bwDragEdge = null; // "left" | "right" | null
|
||||||
@@ -3007,6 +3009,23 @@ function spectrumBgColor() {
|
|||||||
return canvasPalette().bg;
|
return canvasPalette().bg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildSpectrumRenderData(frame) {
|
||||||
|
if (!frame || !Array.isArray(frame.bins)) return frame;
|
||||||
|
const prev = lastSpectrumRenderData;
|
||||||
|
const canBlend =
|
||||||
|
prev &&
|
||||||
|
Array.isArray(prev.bins) &&
|
||||||
|
prev.bins.length === frame.bins.length &&
|
||||||
|
prev.sample_rate === frame.sample_rate &&
|
||||||
|
prev.center_hz === frame.center_hz;
|
||||||
|
const bins = frame.bins.map((value, idx) => {
|
||||||
|
if (!canBlend) return value;
|
||||||
|
const prevValue = prev.bins[idx];
|
||||||
|
return prevValue + (value - prevValue) * SPECTRUM_SMOOTH_ALPHA;
|
||||||
|
});
|
||||||
|
return { ...frame, bins };
|
||||||
|
}
|
||||||
|
|
||||||
// Returns { loHz, hiHz, visLoHz, visHiHz, fullSpanHz, visSpanHz } and clamps
|
// Returns { loHz, hiHz, visLoHz, visHiHz, fullSpanHz, visSpanHz } and clamps
|
||||||
// panFrac so the view never scrolls past the edges.
|
// panFrac so the view never scrolls past the edges.
|
||||||
function spectrumVisibleRange(data) {
|
function spectrumVisibleRange(data) {
|
||||||
@@ -3155,6 +3174,7 @@ function startSpectrumStreaming() {
|
|||||||
spectrumSource.onmessage = (evt) => {
|
spectrumSource.onmessage = (evt) => {
|
||||||
if (evt.data === "null") {
|
if (evt.data === "null") {
|
||||||
lastSpectrumData = null;
|
lastSpectrumData = null;
|
||||||
|
lastSpectrumRenderData = null;
|
||||||
overviewWaterfallRows = [];
|
overviewWaterfallRows = [];
|
||||||
overviewWaterfallPushCount = 0;
|
overviewWaterfallPushCount = 0;
|
||||||
_wfResetOffscreen();
|
_wfResetOffscreen();
|
||||||
@@ -3165,6 +3185,7 @@ function startSpectrumStreaming() {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
lastSpectrumData = JSON.parse(evt.data);
|
lastSpectrumData = JSON.parse(evt.data);
|
||||||
|
lastSpectrumRenderData = buildSpectrumRenderData(lastSpectrumData);
|
||||||
rdsFrameCount++;
|
rdsFrameCount++;
|
||||||
pushOverviewWaterfallFrame(lastSpectrumData);
|
pushOverviewWaterfallFrame(lastSpectrumData);
|
||||||
refreshCenterFreqDisplay();
|
refreshCenterFreqDisplay();
|
||||||
@@ -3192,6 +3213,7 @@ function stopSpectrumStreaming() {
|
|||||||
}
|
}
|
||||||
spectrumDrawPending = false;
|
spectrumDrawPending = false;
|
||||||
lastSpectrumData = null;
|
lastSpectrumData = null;
|
||||||
|
lastSpectrumRenderData = null;
|
||||||
rdsFrameCount = 0;
|
rdsFrameCount = 0;
|
||||||
overviewWaterfallRows = [];
|
overviewWaterfallRows = [];
|
||||||
overviewWaterfallPushCount = 0;
|
overviewWaterfallPushCount = 0;
|
||||||
@@ -3399,8 +3421,8 @@ function scheduleSpectrumDraw() {
|
|||||||
spectrumDrawPending = true;
|
spectrumDrawPending = true;
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
spectrumDrawPending = false;
|
spectrumDrawPending = false;
|
||||||
if (lastSpectrumData) {
|
if (lastSpectrumRenderData) {
|
||||||
drawSpectrum(lastSpectrumData);
|
drawSpectrum(lastSpectrumRenderData);
|
||||||
if (overviewWaterfallRows.length > 0) scheduleOverviewDraw();
|
if (overviewWaterfallRows.length > 0) scheduleOverviewDraw();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user