Suspend idle AudioContext to release the 1 ms platform timer - #106
Open
daiverd wants to merge 1 commit into
Open
Suspend idle AudioContext to release the 1 ms platform timer#106daiverd wants to merge 1 commit into
daiverd wants to merge 1 commit into
Conversation
The AudioContext was created at MudClient construction and never suspended for the life of the tab, holding a 1 ms Windows platform timer request and an open OS audio stream even after days of silence. MediaService now suspends the context after 5 minutes with no audio activity and wakes it programmatically via a memoized ensureAwake() at the top of every inbound audio path (load, play, update, setChain, automate, music resume). Pending ramps and fades defer suspension via a busyUntil deadline so scheduled automation is never frozen, and a wake-hold API keeps the context alive for activity the sound registry cannot see; voice chat holds it for the room's lifetime. Construction stays eager so cacophony's auto-unlock still has the longest possible window before the first server-sent sound. Fixes #99 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #99
The AudioContext ran from MudClient construction for the life of the tab, holding a 1 ms Windows platform timer request (a machine-wide effect: raised interrupt rate, blocked deep idle states) and an open OS audio stream even after days of silence. Confirmed live on a long-running session:
context.state === "running"with zero sounds cached.Changes
MediaServicesuspends the context viacacophony.pause()after 5 minutes with no audio activity.ensureAwake()— memoized single-flight resume — is called at the top of every inbound audio path (load,play,update,setChain,automate, music resume), so concurrent GMCP messages during a wake share oneresume().busyUntildeadline so scheduled automation is never frozen mid-ramp (AudioContext.currentTimestops while suspended). Units verified as milliseconds throughout.acquireWakeHold/releaseWakeHold) pins the context for activity the sound registry can't see; voice chat (audioChat.tsx) holds it for the room's lifetime since LiveKit routes through the shared cacophony context.Verification
MediaService.idleSuspend.test.ts): suspend after idle, no suspend while playing / held / ramping, single shared resume, wake-before-play ordering, shutdown clears the timer. Full suite 1070/1070 green;tsc --noEmitclean.suspendIfIdle()→suspended, holds block it; programmaticpause()→resume()round-trip verified on client.mongoose.world with no fresh gesture (origin has autoplay rights; on zero-engagement origins the resume correctly stays pending until first gesture, same audible behavior as before via cacophony's auto-unlock).Note: the MIDI virtual synth (JZZ/Tiny) creates its own AudioContext, so with MIDI enabled a second timer-holder exists that this PR does not cover — noted on #99.
🤖 Generated with Claude Code