Spaces:
Running
Running
Download src/video/ADebug.tsx from Ethscriptions/mx: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/spaces/Ethscriptions/mx/resolve/main/src/video/ADebug.tsx
- Command line
-
hf download hf://spaces/Ethscriptions/mx/src/video/ADebug.tsx
-
curl -L -o ADebug.tsx https://huggingface.co/spaces/Ethscriptions/mx/resolve/main/src/video/ADebug.tsx
1.37 kB
| import { useEffect } from 'react' | |
| import { getSoundtrack } from './audio' | |
| import { SHOTS } from './scenes' | |
| export default function ADebug() { | |
| useEffect(() => { | |
| const t0 = performance.now() | |
| getSoundtrack(undefined, true).then(b => { | |
| const d = b.getChannelData(0) | |
| const rms = SHOTS.map(s => { | |
| let a = 0, pk = 0; const i0 = Math.floor(s.start * b.sampleRate), i1 = Math.floor(s.end * b.sampleRate) | |
| for (let i = i0; i < i1; i++) { a += d[i] * d[i]; pk = Math.max(pk, Math.abs(d[i])) } | |
| return `${s.index}:${Math.sqrt(a / (i1 - i0)).toFixed(3)}/${pk.toFixed(2)}` | |
| }) | |
| const L = b.getChannelData(0), R = b.getChannelData(1), pcm = new Int16Array(L.length * 2) | |
| for (let i = 0; i < L.length; i++) { pcm[2 * i] = Math.max(-1, Math.min(1, L[i])) * 32767; pcm[2 * i + 1] = Math.max(-1, Math.min(1, R[i])) * 32767 } | |
| const u8 = new Uint8Array(pcm.buffer); let bin = '' | |
| for (let i = 0; i < u8.length; i += 0x8000) bin += String.fromCharCode(...u8.subarray(i, i + 0x8000)) | |
| ;(window as unknown as { __pcm: string }).__pcm = btoa(bin) | |
| console.log('INFO dur=' + b.duration.toFixed(2) + ' ms=' + (performance.now() - t0).toFixed(0) + ' ' + rms.join(' ')) | |
| }).catch(e => console.log('INFO ERROR ' + e)).finally(() => { (window as unknown as { __done: boolean }).__done = true }) | |
| }, []) | |
| return null | |
| } | |