Preserve capture timing when WASAPI flags an unreliable timestamp #4825

Open
github-bot wants to merge 1 commit from github-bot/gh-4824 into main AGit
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-12-01 10:18 UTC · original
andrewpozdnakov7-jpg:fix/audio-capture-packet-clock → main · +16 −2 · 1 files · 1 commits · draft

Main at 5fabb46 has five Clippy errors covered by #4708.

What it changes

Audio capture estimates missed playback from WASAPI packet timestamps. The current code uses the timestamp even when WASAPI marks its timing as uncertain. As a result the estimate can insert silence that the audio source did not play. WASAPI buffer flags

Continue writing that packet at the current output position. Anchor the first reliable timestamp to the number of frames already written and keep using reliable timestamps to account for later gaps.

How it was tested

  • Windows x64 / MSVC. A synthetic packet sequence with the exact frame calculation on 5fabb46 and 6ee5ad4 gave 4,320 extra silence frames before and zero after. A later reliable 480-frame gap was preserved. The fixture also covered an unreliable packet in the middle of a capture and a continuous stream.
  • cargo check --locked -p victory-hle --features diagnostics --jobs 2 and the staged policy check passed.
  • The fixture exercised the clock calculation with simulated packets. Physical audio capture and game playback remain unverified.

Checked for overlap

  • Searched reports and PRs for the timestamp flag. #4725 changes the capture scheduling and writes. Both diffs merge cleanly in capture.rs against its unchanged base.

Please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the change into another commit.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-12-01 10:18 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4824) `andrewpozdnakov7-jpg:fix/audio-capture-packet-clock` → `main` · +16 −2 · 1 files · 1 commits · draft Main at `5fabb46` has five Clippy errors covered by #4708. ## What it changes Audio capture estimates missed playback from WASAPI packet timestamps. The current code uses the timestamp even when WASAPI marks its timing as uncertain. As a result the estimate can insert silence that the audio source did not play. [WASAPI buffer flags](https://learn.microsoft.com/windows/win32/api/audioclient/ne-audioclient-_audclnt_bufferflags) Continue writing that packet at the current output position. Anchor the first reliable timestamp to the number of frames already written and keep using reliable timestamps to account for later gaps. ## How it was tested - Windows x64 / MSVC. A synthetic packet sequence with the exact frame calculation on `5fabb46` and `6ee5ad4` gave 4,320 extra silence frames before and zero after. A later reliable 480-frame gap was preserved. The fixture also covered an unreliable packet in the middle of a capture and a continuous stream. - `cargo check --locked -p victory-hle --features diagnostics --jobs 2` and the staged policy check passed. - The fixture exercised the clock calculation with simulated packets. Physical audio capture and game playback remain unverified. ## Checked for overlap - [x] Searched reports and PRs for the timestamp flag. #4725 changes the capture scheduling and writes. Both diffs merge cleanly in `capture.rs` against its unchanged base. Please retain the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the change into another commit.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 10:19:13 +00:00
Author
Owner

@⁠gut0to on GitHub · 2026-12-01 15:18 UTC · original · reviewed

AI-assisted review: I traced the new timestamp helper and its caller. I used AI assistance and verified that this diff adds no tests for the timing policy.

**@⁠gut0to** on GitHub · 2026-12-01 15:18 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4824#pullrequestreview-6134211591) · **reviewed** AI-assisted review: I traced the new timestamp helper and its caller. I used AI assistance and verified that this diff adds no tests for the timing policy.
@ -116,2 +116,4 @@
}
/// Align the first reliable timestamp (100 ns units) with the current WAV position.
fn packet_frame(anchor: &mut Option<(u64, u64)>, timestamp: Option<u64>, written: u64) -> u64 {
Author
Owner

@⁠gut0to on GitHub · 2026-12-01 15:18 UTC · original

Could packet_frame get pure unit tests for an unreliable first packet, the first later reliable anchor, and a regressing timestamp? This helper is the new timing policy, but the diff adds no regression test for it. In particular, after an invalid timestamp it should continue from written, then anchor the first reliable timestamp at that current frame; a backward timestamp should fall back without moving the anchor.

**@⁠gut0to** on GitHub · 2026-12-01 15:18 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4824#discussion_r4756356564) Could packet_frame get pure unit tests for an unreliable first packet, the first later reliable anchor, and a regressing timestamp? This helper is the new timing policy, but the diff adds no regression test for it. In particular, after an invalid timestamp it should continue from written, then anchor the first reliable timestamp at that current frame; a backward timestamp should fall back without moving the anchor.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/4825/head:github-bot/gh-4824'
git switch 'github-bot/gh-4824'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-4824'
git switch 'github-bot/gh-4824'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-4824'
git switch 'github-bot/gh-4824'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-4824'
git switch 'main'
git merge --squash 'github-bot/gh-4824'
git switch 'main'
git merge --ff-only 'github-bot/gh-4824'
git switch 'main'
git merge 'github-bot/gh-4824'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!4825
No description provided.