fix(audio): audioFramesForTick counts frames at the realm's declared rate - #275
Draft
NathanWalker wants to merge 1 commit into
Draft
fix(audio): audioFramesForTick counts frames at the realm's declared rate#275NathanWalker wants to merge 1 commit into
NathanWalker wants to merge 1 commit into
Conversation
…rate The Bresenham floor difference takes the realm's ticks-per-second (default 60, so every existing callsite and tape is byte-identical); the sim sink is constructed at the runner's declared rate. The zero-drift property is now stated and tested over any ticksPerSecond window, and gen-rust pins the formula at a declared 120 alongside the 60 pins. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Aug 14, 2026
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.
The audio deferral from #257, closed before any audio-capable host grows a declared rate:
audioFramesForTickdivided by a literal 60, so a 120 realm would consume PCM at 2x and the zero-drift statement went false.What changed
contracts/spec/audio.ts:audioFramesForTick(rate, tick, ticksPerSecond = 60). The default keeps every existing callsite byte-identical — the 60-window tests now pin the default path. The doc states the generalized property (sum over anyticksPerSecondconsecutive ticks is exactlyrate) and the reachability argument: the pairing invariant refuses a mismatched mount, so formula and realm can only disagree through a host bug, never through a bundle.hosts/sim/audio.ts:createSimAudioSink(ticksPerSecond = 60)— a runner driving a non-60 realm constructs the sink at that rate, keeping one-tick-one-sink.tick()pairing intact.contracts/spec/gen-rust.ts+ regeneratedengine/core/src/spec.rs: the pin now also asserts the formula at a declared 120 (22050 -> 183, 184), and the emitted doc states the rate-parameterized form.Tests
AUDIO_RATESentry, window starts 0/1/59/600, plus the ±1-frame bound.Verification
bun run test11/11 stages green (38.5 s);bunx tsc --noEmitclean;bun tests/contract.tsgreen against the regenerated spec.rs;cargo check -p pocketjs-coreclean (the spec.rs delta is doc text).Deliberately not here: nothing calls this with a non-60 rate yet — the sim can't reach a non-60 realm until
engine/wasmexportsui_set_tick_rate(next PR in this follow-up series).🤖 Generated with Claude Code