Audio capture: wait for the engine's event, buffer the writes, raise the recorder's priority #4725

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

@⁠kkrlock on GitHub · 2026-12-01 03:39 UTC · original
kkrlock:fix/audio-capture-drops → main · +110 −13 · 1 files · 1 commits · open

What it changes

VICTORY_AUDIO_CAPTURE recorded silence where the title played audio. In a 12-minute capture 22 to 24% of the file was exact zeros, in stretches of whole 10 ms periods (peaks at exactly 480, 960 and 1440 frames), one every 80 to 110 ms, the longest 725 ms. Anyone reading such a capture for dropouts finds thousands of them, and none belong to the title.

The cause is in record(). It slept 10 ms between drains while the process loopback's own buffer holds a few periods, it wrote every packet straight to disk with an unbuffered File::write_all, and it ran at normal thread priority. Under the title's load a drain comes late, the loopback buffer wraps, and the packets for that period are gone. What is left is a jump in the timestamps, which the code already fills with silence, so the file reads as if the title played nothing.

Four changes:

  1. Wait on the engine's event (AUDCLNT_STREAMFLAGS_EVENTCALLBACK and SetEventHandle) instead of sleeping a whole period between drains. The wait has a 200 ms timeout, so the title is still polled and the header still patched while nothing arrives.
  2. Write through a 1 MiB BufWriter.
  3. The recorder's thread runs at THREAD_PRIORITY_HIGHEST.
  4. Count the two ways a stretch can be silent and log them once a second: missed is a packet that never arrived, silent is a packet that arrived marked silent. Only the first is a recorder bug, so a capture cannot be judged without the split.

VICTORY_AUDIO_TONE=1 makes the recorder play a constant 1 kHz sine from its own process, which is inside the process tree the loopback records. That is the reference used below, and it can be used any time to check a capture before trusting it.

Nothing the title does changes, and nothing is built outside the diagnostics feature.

How it was tested

  • GPU and profile: RTX 5060 8 GB, Ryzen 5 5600X, 32 GB, Windows 11. Series S, 540p internal to a 1080p output, DLSS performance, frame generation 5X, ray tracing off. The title runs at 10-12 fps under that load.

  • Method: the recorder plays the 1 kHz sine and records it with the same process loopback. The sine cannot have a gap of its own, so any gap in the recording is the recorder's. Measured as the exact-zero fraction of the file, and as the 1 kHz band envelope (FFT around 1 kHz, 128-sample blocks). Same save, same protocol, the title parked in the same car, for every run.

  • Before, three runs: 22.38%, 23.60%, 23.25% exact zeros.

  • After, four runs: 0.19%, 0.08%, 0.09%, 0.18% exact zeros.

  • The recorder's own counters agree with the files, and put the remainder on this side:

    run missed missed_ms silent of the file
    2nd 11 232 0 0.06%
    3rd 8 287 0 0.07%
    4th 14 623 0 0.16%

    silent counts packets that arrived marked silent, which would mean the tone underran. It was 0 in every run.

  • No listening comparison: this changes no audio the title plays, only what the recorder writes.

  • For shader changes, the wave sizes tested: not a shader change.

  • cargo test: not run. cargo check --profile diag -p victory --features diagnostics passes on this branch, rebased onto main. The capture module has no unit tests on main and this change adds none.

  • One machine, non-blinded, three runs before and four after. The 23% figure needs the title busy enough that a drain is late; where it is never late, the bug does not show.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: none. crates/victory-hle/src/modules/audio/capture.rs has one commit on main, the one that added it, and no pull request changes it. #2799 mentions VICTORY_AUDIO_CAPTURE in its list of settings that write game data outside the repo; it does not change this file.
**@⁠kkrlock** on GitHub · 2026-12-01 03:39 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4724) `kkrlock:fix/audio-capture-drops` → `main` · +110 −13 · 1 files · 1 commits · open ## What it changes `VICTORY_AUDIO_CAPTURE` recorded silence where the title played audio. In a 12-minute capture 22 to 24% of the file was exact zeros, in stretches of whole 10 ms periods (peaks at exactly 480, 960 and 1440 frames), one every 80 to 110 ms, the longest 725 ms. Anyone reading such a capture for dropouts finds thousands of them, and none belong to the title. The cause is in `record()`. It slept 10 ms between drains while the process loopback's own buffer holds a few periods, it wrote every packet straight to disk with an unbuffered `File::write_all`, and it ran at normal thread priority. Under the title's load a drain comes late, the loopback buffer wraps, and the packets for that period are gone. What is left is a jump in the timestamps, which the code already fills with silence, so the file reads as if the title played nothing. Four changes: 1. Wait on the engine's event (`AUDCLNT_STREAMFLAGS_EVENTCALLBACK` and `SetEventHandle`) instead of sleeping a whole period between drains. The wait has a 200 ms timeout, so the title is still polled and the header still patched while nothing arrives. 2. Write through a 1 MiB `BufWriter`. 3. The recorder's thread runs at `THREAD_PRIORITY_HIGHEST`. 4. Count the two ways a stretch can be silent and log them once a second: `missed` is a packet that never arrived, `silent` is a packet that arrived marked silent. Only the first is a recorder bug, so a capture cannot be judged without the split. `VICTORY_AUDIO_TONE=1` makes the recorder play a constant 1 kHz sine from its own process, which is inside the process tree the loopback records. That is the reference used below, and it can be used any time to check a capture before trusting it. Nothing the title does changes, and nothing is built outside the diagnostics feature. ## How it was tested - GPU and profile: RTX 5060 8 GB, Ryzen 5 5600X, 32 GB, Windows 11. Series S, 540p internal to a 1080p output, DLSS performance, frame generation 5X, ray tracing off. The title runs at 10-12 fps under that load. - Method: the recorder plays the 1 kHz sine and records it with the same process loopback. The sine cannot have a gap of its own, so any gap in the recording is the recorder's. Measured as the exact-zero fraction of the file, and as the 1 kHz band envelope (FFT around 1 kHz, 128-sample blocks). Same save, same protocol, the title parked in the same car, for every run. - Before, three runs: 22.38%, 23.60%, 23.25% exact zeros. - After, four runs: 0.19%, 0.08%, 0.09%, 0.18% exact zeros. - The recorder's own counters agree with the files, and put the remainder on this side: | run | missed | missed_ms | silent | of the file | |---|---|---|---|---| | 2nd | 11 | 232 | 0 | 0.06% | | 3rd | 8 | 287 | 0 | 0.07% | | 4th | 14 | 623 | 0 | 0.16% | `silent` counts packets that arrived marked silent, which would mean the tone underran. It was 0 in every run. - No listening comparison: this changes no audio the title plays, only what the recorder writes. - For shader changes, the wave sizes tested: not a shader change. - `cargo test`: not run. `cargo check --profile diag -p victory --features diagnostics` passes on this branch, rebased onto `main`. The capture module has no unit tests on `main` and this change adds none. - One machine, non-blinded, three runs before and four after. The 23% figure needs the title busy enough that a drain is late; where it is never late, the bug does not show. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: none. `crates/victory-hle/src/modules/audio/capture.rs` has one commit on `main`, the one that added it, and no pull request changes it. #2799 mentions `VICTORY_AUDIO_CAPTURE` in its list of settings that write game data outside the repo; it does not change this file.
VICTORY_AUDIO_CAPTURE recorded silence for stretches of the title's audio: 22.4% of a 12-minute capture was exact zeros, in stretches of whole 10 ms periods. A constant 1 kHz tone played from the recorder's own process (VICTORY_AUDIO_TONE=1, added here) - a source that cannot have a gap of its own - came out 22.4% zeros too, so the loss was the recorder's.

The loop slept 10 ms between drains while the process loopback buffer holds a few periods, wrote every packet straight to disk unbuffered, and ran at the normal thread priority. It now waits on the engine's event (AUDCLNT_STREAMFLAGS_EVENTCALLBACK) with the same 1 MiB buffered writes and THREAD_PRIORITY_HIGHEST, and the tone's own thread no longer starves either.

The same tone: 22.4% zeros before, 0.19% and 0.08% in two runs after. The recorder now also counts the two ways a stretch can be silent apart and logs them once a second - a packet that never arrived (this side) and a packet that arrived marked silent (the source) - so a capture can be judged before it is used; the tone runs logged silent=0, which puts what is left on this side.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 03:41:19 +00:00
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/4725/head:github-bot/gh-4724'
git switch 'github-bot/gh-4724'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-4724'
git switch 'github-bot/gh-4724'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-4724'
git switch 'github-bot/gh-4724'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-4724'
git switch 'main'
git merge --squash 'github-bot/gh-4724'
git switch 'main'
git merge --ff-only 'github-bot/gh-4724'
git switch 'main'
git merge 'github-bot/gh-4724'
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!4725
No description provided.