Monorepo for Aesthetic.Computer aesthetic.computer
4
fork

Configure Feed

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

speaker: replace setTimeout with sim() tick (QuickJS has no setTimeout)

ac-native runs pieces under QuickJS which doesn't ship setTimeout.
Rewrite the 's' sweep to use sim() with a Date.now() step counter.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

+27 -12
+27 -12
system/public/aesthetic.computer/disks/speaker.mjs
··· 23 23 let durationsMs = [200, 500, 1000, 2000, 5000]; 24 24 let durIdx = 1; // 500 ms 25 25 let lastMainTone = { freq: 0, vol: 0, ts: 0 }; 26 + // Sweep state — uses sim() tick instead of setTimeout (not available in ac-native QuickJS). 27 + let sweepActive = false; 28 + let sweepStartMs = 0; 29 + let sweepFreq = 440; 30 + let sweepStep = 0; 26 31 27 32 function boot({ system }) { 28 33 refreshPcms(system); ··· 109 114 return; 110 115 } 111 116 112 - // 's' = sweep — ramps volume from 0→100% to hear max clean loudness. 117 + // 's' = sweep — ramps volume from 20%→100% via sim() tick (no setTimeout). 113 118 if (e.is("keyboard:down:s")) { 114 - const freq = freqs[freqIdx]; 115 - const steps = 5; 116 - for (let i = 0; i < steps; i++) { 117 - const v = ((i + 1) / steps); 118 - setTimeout(() => { 119 - sound?.synth?.({ type: "sine", tone: freq, duration: 0.3, 120 - volume: v, attack: 0.01, decay: 0.15 }); 121 - }, i * 350); 122 - } 123 - lastMainTone = { freq, vol: 1.0, ts: Date.now() }; 119 + sweepActive = true; 120 + sweepStartMs = Date.now(); 121 + sweepFreq = freqs[freqIdx]; 122 + sweepStep = 0; 123 + lastMainTone = { freq: sweepFreq, vol: 1.0, ts: Date.now() }; 124 124 return; 125 125 } 126 + } 127 + 128 + function sim({ sound }) { 129 + if (!sweepActive) return; 130 + const steps = 5; 131 + const stepMs = 350; 132 + const elapsed = Date.now() - sweepStartMs; 133 + const wantStep = Math.floor(elapsed / stepMs); 134 + while (sweepStep < wantStep && sweepStep < steps) { 135 + const v = (sweepStep + 1) / steps; 136 + sound?.synth?.({ type: "sine", tone: sweepFreq, duration: 0.3, 137 + volume: v, attack: 0.01, decay: 0.15 }); 138 + sweepStep++; 139 + } 140 + if (sweepStep >= steps) sweepActive = false; 126 141 } 127 142 128 143 function paint({ wipe, ink, box, write, screen }) { ··· 201 216 { x: pad, y: h - 10, size: 1, font }); 202 217 } 203 218 204 - export { boot, paint, act }; 219 + export { boot, paint, act, sim };