Fixing scope and spectrogram

This commit is contained in:
2025-10-15 13:03:22 +02:00
parent 1ead074e21
commit c5733897ea
2 changed files with 7 additions and 3 deletions

View File

@ -9,7 +9,7 @@
let container: HTMLDivElement; let container: HTMLDivElement;
let canvas: HTMLCanvasElement; let canvas: HTMLCanvasElement;
let canvasContext: CanvasRenderingContext2D | null = null; let canvasContext = $state<CanvasRenderingContext2D | null>(null);
let animationFrameId: number | null = null; let animationFrameId: number | null = null;
let dataArray: Uint8Array | null = null; let dataArray: Uint8Array | null = null;
let width = $state(800); let width = $state(800);
@ -28,7 +28,7 @@
function setupScope(node: AnalyserNode) { function setupScope(node: AnalyserNode) {
try { try {
const bufferLength = node.frequencyBinCount; const bufferLength = node.fftSize;
dataArray = new Uint8Array(bufferLength); dataArray = new Uint8Array(bufferLength);
startDrawing(node); startDrawing(node);
} catch (error) { } catch (error) {
@ -93,6 +93,10 @@
onMount(() => { onMount(() => {
if (canvas) { if (canvas) {
canvasContext = canvas.getContext('2d'); canvasContext = canvas.getContext('2d');
if (canvasContext) {
canvasContext.fillStyle = '#0a0a0a';
canvasContext.fillRect(0, 0, canvas.width, canvas.height);
}
} }
updateSize(); updateSize();

View File

@ -9,7 +9,7 @@
let container: HTMLDivElement; let container: HTMLDivElement;
let canvas: HTMLCanvasElement; let canvas: HTMLCanvasElement;
let canvasContext: CanvasRenderingContext2D | null = null; let canvasContext = $state<CanvasRenderingContext2D | null>(null);
let animationFrameId: number | null = null; let animationFrameId: number | null = null;
let dataArray: Uint8Array | null = null; let dataArray: Uint8Array | null = null;
let width = $state(800); let width = $state(800);