host_posix: the spatial audio event ticks on a clock of its own #144
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/144"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by ItsMariusBC on 2026-11-26T20:31:10Z.
What this changes
The title's spatial audio event is set by a clock of the stream's own, instead of by the device's buffer requests. This is the crackling and the drop-outs in the boot movie and the menus reported in #110.
Cause. The
AudioQueuedoes not ask for buffers evenly. I timed the render callback for 3 s on an M5 Pro at 48 kHz: 10 ms buffers are asked for 10.7 ms apart, and every 16th request comes right after the one before (under 2 ms). That is a device cycle of 512 frames against buffers of 480. The event was set once per request, so the title got one signal for those two periods, and one for any stretch it slept through. The queue held one period at most, so each of those played as 10 ms of silence.Fix.
Shared::tickis the event's clock: a period apart, half a period apart while fewer than three periods are queued, and no signal while five are.spatial.rsruns it on a thread that stops with the stream. The device callback only takes frames.Why not make the lost pass up at once. I tried that first (signal again at the end of a pass while the queue is short). It left 7 gaps, 5 of them exactly 160 ms apart in the first second of the movie's sound, with the queue full and 100 passes a second. So the title returns a silent pass when it is given two back to back while a sound starts. With passes at least half a period apart those are gone.
Measurements
50 s runs, Series S, same Mac, the device output recorded with
VICTORY_WASAPI_WAVand analysed offline. A gap is one or more periods of 480 frames that are all zero between two periods with sound.49e7c64The one gap left is 40 ms at 3.89 s into the movie's sound. It was at the same instant in the run before, and a temporary counter of frames the device got as silence because the queue was empty read 0 for the whole run, so it is in what the title mixes. That counter is not in this pull request.
By ear: no crackling left in the boot movie or the menus.
Not covered: the drop-outs during the world load. Those come with stalls of several seconds when memory runs out, and the title reopens its stream.
One caveat: the default output on this Mac is a virtual device at 48 kHz, and I did not time the built-in speakers.
How it was tested
cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victorycargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings49e7c64plus this change. Not run again after the rebase on57b7ebd.Two new tests in
wasapi.rsplay the stream on a clock of microseconds, with a device that takes frames in cycles of 512:the_event_clock_feeds_a_device_that_takes_frames_in_its_own_cycles: no silence, and no two passes closer than 5 ms. It fails with 1,250 µs if the short ticks are an eighth of a period.a_title_that_wakes_late_catches_up_instead_of_leaving_silence: a title that oversleeps 15 ms every second. It fails if every tick is a full period.cargo xtask policypasses.Checklist
Shared::tick)VICTORY_*variable and documented (none added)Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by ItsMariusBC on 2026-11-26T20:37:38Z.
Run again after the rebase: main
0ae6cfcwith this branch and #145 merged on top, Series S, 75 s, cold shader cache, same Mac.I did not record the output this time, so there is no gap count for this run.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T22:38:08Z.
Review: APPROVED
Reviewed and tested together with the other open PRs on main (macOS x86_64 workspace tests, the setup shell tests, and Windows clippy). Thanks!