feat(frontend): добавлены частоты ниже 1

This commit is contained in:
2025-12-28 23:07:07 +03:00
parent c560b9be76
commit bcc94b40fe
3 changed files with 12 additions and 10 deletions

View File

@@ -11,7 +11,7 @@ type LiveStreamState = {
lastMessageAt: number | null;
// WS frequency control
requestedHz: number; // 1..60
requestedHz: number; // 0.1-60
setRequestedHz: (hz: number) => void;
// Window selection
@@ -33,14 +33,14 @@ const PEAK_WINDOW_MS = 3_000;
const WINDOW_OPTIONS_MS = [15_000, 30_000, 60_000, 120_000, 300_000] as const;
const DEFAULT_WINDOW_MS = 60_000;
const MIN_HZ = 1;
const MIN_HZ = 0.1;
const MAX_HZ = 60;
const DEFAULT_REQUESTED_HZ = 10;
// If there are more than 600 points in selected window -> downsample
const MAX_CHART_POINTS = 600;
// UI updates not more than ~12 Hz (1015 Hz recommended)
// UI updates not more than ~12 Hz
const UI_FLUSH_HZ = 12;
const UI_FLUSH_MS = Math.round(1000 / UI_FLUSH_HZ);
@@ -58,10 +58,12 @@ let lastSeenSample: AudioSample | null = null;
function clampInt(v: number, min: number, max: number): number {
if (!Number.isFinite(v)) return min;
return Math.max(min, Math.min(max, Math.trunc(v)));
return Math.max(min, v);
}
function isAllowedWindowMs(ms: number): ms is (typeof WINDOW_OPTIONS_MS)[number] {
function isAllowedWindowMs(
ms: number,
): ms is (typeof WINDOW_OPTIONS_MS)[number] {
return (WINDOW_OPTIONS_MS as readonly number[]).includes(ms);
}
@@ -81,7 +83,8 @@ function buildWsUrl(base: string, hz: number): string {
function trimPeakWindow(nowSampleMs: number): void {
const cutoff = nowSampleMs - PEAK_WINDOW_MS;
while (peakWindow.length && peakWindow[0]!.timeMs < cutoff) peakWindow.shift();
while (peakWindow.length && peakWindow[0]!.timeMs < cutoff)
peakWindow.shift();
// Safety cap: even at 60 Hz, 3 sec ~ 180 points; allow some jitter
if (peakWindow.length > 512) peakWindow = peakWindow.slice(-512);
@@ -255,4 +258,3 @@ export const useLiveStreamStore = create<LiveStreamState>()((set, get) => {
},
};
});