From 4ae7cf2d4e4437661fcafea1cc3d97af2d2f8d55 Mon Sep 17 00:00:00 2001 From: Michael SCHAL Date: Sun, 3 May 2026 23:09:52 +0200 Subject: [PATCH] fix: normalisation par bande, bords aussi actifs que le centre --- frontend/src/components/AudioVisualizer.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/AudioVisualizer.tsx b/frontend/src/components/AudioVisualizer.tsx index ef70fbe..80d4e01 100644 --- a/frontend/src/components/AudioVisualizer.tsx +++ b/frontend/src/components/AudioVisualizer.tsx @@ -14,6 +14,7 @@ export default function AudioVisualizer({ height = 80 }: AudioVisualizerProps) { const canvasRef = useRef(null); const rafRef = useRef(0); const heightsRef = useRef(Array(NUM_POINTS).fill(0)); + const bandMaxRef = useRef(Array(NUM_POINTS).fill(1)); const playingRef = useRef(isPlaying); const getDataRef = useRef(getFrequencyData); const hasRealDataRef = useRef(false); @@ -42,6 +43,7 @@ export default function AudioVisualizer({ height = 80 }: AudioVisualizerProps) { const drawW = displayW - PADDING * 2; const HALF = Math.floor(NUM_POINTS / 2); // 21 — center outward + const bandMax = bandMaxRef.current; let frame = 0; const animate = () => { @@ -73,8 +75,11 @@ export default function AudioVisualizer({ height = 80 }: AudioVisualizerProps) { count++; } const avg = count > 0 ? sum / count : 0; - const boosted = Math.pow(avg / 255, 0.6); - const target = boosted * MAX_AMPLITUDE; + // Per-band normalization: each band moves relative to its own history + // so treble (quiet by nature) animates as much as bass + bandMax[i] = Math.max(avg, bandMax[i] * 0.994, 8); + const normalized = avg / bandMax[i]; + const target = Math.pow(normalized, 0.7) * MAX_AMPLITUDE; hts[i] += (target - hts[i]) * 0.22; } } else {