Catch up after a stall of the audio renderer by rendering the owed frames without queueing them.

A frame that was not rendered when it was due stayed lost: the timer set its
deadline to now once it was more than 100 ms late, and the device-paced path
only filled the ring to its target again, so after every gap the sound was
heard that much later than the picture it belongs to.

Frames that are owed are now rendered and dropped: mixed in full, so the
voices, the effects and the sinks the game reads back advance, and not queued
for the device, whose queue is filled to the same target afterwards. While the
device paces, what is owed is the silence it played for want of frames,
counted in its own samples from an underrun until the prefill is queued again;
the wait for the first prefill and anything owed across a stop do not count.
On the timer a frame is owed when its deadline passed a whole frame ago. A gap
of more than 3 seconds is not caught up: the sound goes on from now.

NX2NAVI_AUDIO_CATCHUP=0 turns it off and keeps the old timing. The audio
statistics line counts the catch-up frames and the gaps that were too long,
and tests/audio_mixer_check.py checks the device's side of the accounting.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-12 15:17:00 -05:00
parent 42d16e7f0b
commit 641c866e8a
7 changed files with 206 additions and 26 deletions

View File

@@ -359,12 +359,17 @@ sites do: at 144 fps each of 64 water objects gets its ripple steps and the day
gives what the game computes. No game files.
A change to how the mixer applies volumes (`runtime/audio_mixer.c` `accumulate_ramp`, the voice and splitter paths
of `audio_mixer_render`) passes `python tests\audio_mixer_check.py`, which builds `audio_mixer.c` with the rest of
the runtime stubbed and mixes voices of one constant sample, so a mix buffer shows the gain sample by sample: a
of `audio_mixer_render`) or to what it owes the device after a stall (`ring_pull`, `audio_mixer_owed`) passes
`python tests\audio_mixer_check.py`, which builds `audio_mixer.c` with the rest of the runtime stubbed. It mixes
voices of one constant sample, so a mix buffer shows the gain sample by sample: a
volume stepped from 0 to 1 rises in equal steps across the next 5 ms frame and holds after it, for a voice into a mix,
a voice into a splitter destination and a submix into one; a voice that starts, was silent in the frame before or was
moved to another mix, a destination that is new or was moved, and the first frame after the renderer starts take the
new volume at once; `NX2NAVI_AUDIO_RAMP=0` applies every volume at once. No game files and no audio device.
new volume at once; `NX2NAVI_AUDIO_RAMP=0` applies every volume at once. It also makes the device's requests by
hand: the silence of an underrun, up to the prefill's return, is owed in whole render frames, which are rendered and
not queued; the silence before the first prefill and across a stop is not owed, and more than 3 seconds of it is given
up. The render thread's own timing (`runtime/audren.c` `render_thread`) is not built by it. No game files and no audio
device.
A change to the mouse camera (`runtime/mouse_direct.c`, the mouse path of `runtime/input.c`, the set `mouse_direct` of
`recomp/patches-v111.txt` or `patches-v143.txt`) passes `python tests\mouse_direct_check.py --cc <clang> --deps