music video renderer web app deftoku.digi.rip
audio visualizer webapp
1

Configure Feed

Select the types of activity you want to include in your feed.

utils: cleaned up comments

digi.rip (Jun 21, 2026, 6:12 PM EDT) 55dc986b 77a3a880

+9 -15
+9 -15
src/visualizers/utils.ts
··· 1 - /* 2 - * - **Ghost-loop prevention** via a `stopped` flag — if the cleanup function 3 - * is called mid-draw, the loop won't re-schedule itself via the rAF at the 4 - * end of the tick (which would otherwise keep the old loop running forever 5 - * and fighting any new preview for the canvas). 6 - * 7 - * Returns a cleanup function — call it once to stop the loop and cancel the 8 - * pending animation frame. 9 - */ 10 - 11 1 // double buffered anim loop: draws offscreen then gets placed to 12 2 // visible canvas in one op 13 3 export function createPreviewLoop( ··· 24 14 const displayCtx = canvas.getContext("2d")!; 25 15 26 16 let raf: number; 17 + 18 + // using this prevents ghost-loops; if cleanup is called mid-draw, 19 + // loop won't re-schedule via rAF at end of tick and prevents 20 + // old loop running forever and fighting new preview for canvas 27 21 let stopped = false; 28 22 29 23 function loop(now: number) { 30 24 if (stopped) return; 31 25 if (now >= nextFrame) { 32 26 // fps limiting: skips rAF callbacks until the next frame deadline 33 - // then catches up if the callback was delayed (no spiral). 27 + // then catches up if the callback was delayed 34 28 nextFrame += fixedDt * 1000; 35 29 if (nextFrame < now) nextFrame = now + fixedDt * 1000; 36 30 render(offscreen, fixedDt); ··· 40 34 } 41 35 42 36 raf = requestAnimationFrame(loop); 37 + 38 + // cleanup function: called once to stop loop and cancel pending animation 43 39 return () => { 44 40 stopped = true; 45 41 cancelAnimationFrame(raf); 46 42 }; 47 43 } 48 44 49 - /** 50 - * Fills a Uint8Array with synthetic frequency data (animated sine wave). 51 - * Used by previews that don't have real audio data. 52 - */ 45 + // generates Uint8Array with an animated sine wave 46 + // useful for previews that need real audio data placeholder 53 47 export function generateSyntheticFreq( 54 48 freq: Uint8Array, 55 49 phase: number,