The audio_drain_fix texts say when the game's guard fires: evenly paced audio frames, not any run above 200 fps (#337)

The texts that came with the audiodrain set (docs/settings.md, totk.ini.example, the comments in patches-v121.txt and
patches-v143.txt) said that above about 200 game updates a second the game switches its sound off. Every run behind
them had captured the mix with audio = none. With a device playing, on Linux with PipeWire, the game keeps its sound at
240 fps without the set.

The guard (1.2.1 main+0x9bcdc4) sets its count back to 0 whenever a free list is there (0x9bce00), which takes two
audio frames between two updates of the game. The mixer's timer renders one frame every 5 ms, so at 240 updates a
second that never happens and the count reaches 300. A device paces the render thread in bursts after each period
(audren.c, gap_ns: 4 ms apart on Linux; 0 on Windows, read from the code and not measured), so it happens several times
a second. Sampled on the render thread on Linux with PipeWire's 1024-frame periods: 200 frames a second either way, 76%
of them 4 ms after the one before with the device, 939 of 940 at 5 ms with the timer. The count and the switch have
not been read in a run.

The mixer also keeps time by its timer while a device takes nothing. Measured at fps_limit 240, same save and input
script, with the game's audio stream paused from outside (pw-cli on its PipeWire node, not a real device stalling)
while the game ran at 240 fps. On 1.2.1 with the set off a pause of 5 s (two runs) and of 2 s (two runs) left the game
silent to the end of the run, also after the device resumed, and a pause of 1 s (one run) did not; with the set on a
pause of 5 s (two runs) left only the gap. On 1.4.3, one run each: silent after a pause of 5 s and of 2 s with the set
off, sound after a pause of 5 s with it on, sound with a device and no pause with the set off.

The numbers without a device now come from runs that can be named: 1.2.1 6 of 119 and 111 of 119, 1.4.3 3 of 119 and
113 of 120 (set off and on). They replace 5 of 118 / 108 of 118 and 2 of 118 / 110 of 119, which I cannot match to a
run any more.

Text only: no code, no site and no default changes. Not measured: Windows, a device with periods of 240 frames or
less, a real device stalling, 1.4.3 with a device and the set on.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
shinodanpenandClaude committed 2026-11-18 18:18:43 +00:00
1 parent ebce67b367
commit bb6523a080
4 files changed
+38 -21

No files matched your search

+1 -1
View File
@@ -229,7 +229,7 @@ These names are code patch sets built into the generated game code (`recomp/patc
| --- | --- | --- | --- |
| `ability_guard` (default `1`) | Patch set that checks the target a Recall or Ultrahand pick hands to the game (1.4.3 main+0x1bd01c4, 1.2.1 main+0x1622bf0) and drops it for that frame where the game's own code would fault on it: the holder, the actor or its component unreadable, or the word the game's reference writes not writable (`runtime/ov_ability.c`). Every other target goes on unchanged; a target that fails UltraTears' live-actor test is only logged (`ability: target kept although ...`). | `0` runs the game's code as shipped: the random crash reading `0xffffffffffffffff` during an ability pick can return. | Risky |
| `aspect_patch` (default `0`) | Patch set that feeds the camera the output's aspect ratio when it is not 16:9. | The resolution code switches this set on or off itself at start, so a value here is replaced; the code does not settle what a manual value does. | Unknown |
| `audio_drain_fix` (default `1`) | Patch set that sends the game's audio thread back to its command ring after each list (1.2.1 main+0x883780, 1.4.3 main+0x149244), so it takes every queued list per 5 ms audio frame instead of one (#337). Game 1.1.0 has no site and keeps the game's code. | `0` runs the game's code as shipped: above about 200 game updates a second the ring stays full and the game's guard (1.2.1 main+0x9bcdc4) switches the sound commands off until the game is restarted. The set acts only when more than one list is queued, so below that rate it seldom changes anything. Measured at `fps_limit = 240`, seconds with sound: on 1.2.1 5 of 118 with `0` and 108 of 118 with `1`; on 1.4.3 2 of 118 with `0` and 110 of 119 with `1`. | Safe |
| `audio_drain_fix` (default `1`) | Patch set that sends the game's audio thread back to its command ring after each list (1.2.1 main+0x883780, 1.4.3 main+0x149244), so it takes every queued list per 5 ms audio frame instead of one (#337). Game 1.1.0 has no site and keeps the game's code. | `0` runs the game's code as shipped: above about 200 game updates a second the ring fills, and the game's guard (1.2.1 main+0x9bcdc4) switches the sound commands off until the game is restarted once 300 updates in a row find it full. The guard starts over whenever two audio frames fall between two updates, so by the code it fires only while the audio frames come evenly, 5 ms apart: with `audio = none`, or while the audio device takes nothing and the mixer keeps time by its own timer. The guard's count and the switch have not been read in a run. With a device playing the game kept its sound in every run on Linux with PipeWire and 1024-frame device periods, where the frames come in bursts after each period; on Windows the bursts are read from the code (`gap_ns = 0` in `runtime/audren.c`), not measured; a device with periods of 240 frames or less was not tried and may pace as evenly as the timer. The set acts only when more than one list is queued, so below that rate it seldom changes anything. Measured at `fps_limit = 240` (Linux, PipeWire), seconds with sound with `0` and with `1`. On 1.2.1: without a device 6 of 119 and 111 of 119; with a device 111 of 119 and 112 of 119; with the game's stream paused for 5 s from outside (`pw-cli`, not a real device stalling) 4 of 120 (silent from the pause on, also after the device resumed) and 113 of 119; a pause of 2 s silenced the game with `0`, a pause of 1 s did not. On 1.4.3: without a device 3 of 119 and 113 of 120; with a device 111 of 119 with `0`; with the stream paused for 5 s, in 60 s runs, 3 of 59 and 51 of 59; a pause of 2 s with `0`, 4 of 59. | Safe |
| `fixed_res_patch` (default `0`) | Patch set that holds the game's dynamic resolution at 100 percent (the scene tier). | The resolution code switches this set from `dynamic_res` (on at `0`); a manual value is replaced. | Unknown |
| `fov_patch` (default `0`) | Patch set that scales the camera's vertical view angle by the field-of-view setting. | The resolution code switches this set itself whenever the field of view is not 100 percent; a manual value is replaced. | Unknown |
| `mouse_direct_patch` (default `1`) | Patch set of the hooks in the game's camera code behind `mouse_mode = direct` on game 1.4.3. | `0` stops `mouse_mode = direct` from taking effect; other mouse modes are unaffected. | Safe |
+26 -14
View File
@@ -1181,19 +1181,31 @@ set ability TOTK_ABILITY_GUARD 1
site ability main 1622bf0 f9400115 94c424dc # ldr x21, [x8] -> bl page+0xf60
site ability main 1622bf4 b4000155 aa0903f5 b4000155 # cbz x21 -> mov x21, x9; cbz x21 (x9 dead after it)
# Sound command lists above 200 fps (issue #337). The game thread hands its sound commands to the audio thread in
# lists: 16 of them, of which 4 are always held (one being filled by the game thread, the others on the audio thread's
# side), so at most 12 wait in the command ring. The game thread submits at most one list per update (main+0x9bd144,
# when a free list is there), and the audio thread takes one per pass of its loop, one 5 ms audio frame: after a list
# main+0x883780 goes on past the ring's check (b 0x883318). Above about 200 updates a second the ring stays full. A
# guard in the game (main+0x9bcdc4, at the end of each update) counts the updates that find the ring of free lists
# empty and exactly 12 lists in the command ring (0x9bce1c cmp w9, #0xc); the count goes back to 0 only when a free
# list is there. At every multiple of 300 (10 s at 30 fps, 1.25 s at 240) it clears the sound command switch, the byte
# at [[engine + 0x1a0] + 8] (main+0x2268bfc), and stops every active voice (main+0x226f29c). The switch is set to 1 only
# by its constructor (main+0xf31ce8, from the engine's init main+0xf31530), so the game stays silent until it is
# restarted. The site sends the audio thread back to the ring's check (0x8832e8, where the game's own 0x883c18 also
# branches; x21, the engine, is not written between the check and the site), so it takes every queued list in the pass
# and the ring does not stay full. Measured on 1.2.1 at fps_limit 240, same save and input script: sound in 5 of 118 s
# with the set off, in 108 of 118 s with it on.
# Sound command lists above 200 updates a second (issue #337). The game thread hands its sound commands to the audio
# thread in lists: 16 of them, of which 4 are always held (one being filled by the game thread, the others on the audio
# thread's side), so at most 12 wait in the command ring. The game thread submits at most one list per update
# (main+0x9bd144, when a free list is there), and the audio thread takes one per pass of its loop, one 5 ms audio frame:
# after a list main+0x883780 goes on past the ring's check (b 0x883318). Above about 200 updates a second the ring
# fills. A guard in the game (main+0x9bcdc4, at the end of each update) counts the updates that find the ring of free
# lists empty and exactly 12 lists in the command ring (0x9bce1c cmp w9, #0xc); the count goes back to 0 whenever a free
# list is there (0x9bce00), which takes two audio frames between two updates: the game thread picks up one of the two
# lists, the other is still free at the guard. At every multiple of 300 (10 s at 30 fps, 1.25 s at 240) the guard clears
# the sound command switch, the byte at [[engine + 0x1a0] + 8] (main+0x2268bfc), and stops every active voice
# (main+0x226f29c). The switch is set to 1 only by its constructor (main+0xf31ce8, from the engine's init
# main+0xf31530), so the game stays silent until it is restarted. By this reading the guard fires only when the audio
# frames come evenly, 5 ms apart, through 300 updates in a row at more than 200 a second: that is the mixer pacing its
# render thread by its own timer (runtime/audio_mixer.c, audio_mixer_pace_ns), with audio = none or while a device takes
# nothing. While a device paces the rendering the frames come in bursts after each device period: on Linux with
# PipeWire's 1024-frame periods 76% of the frames were measured 4 ms after the one before (audren.c, gap_ns), two of
# them fall between two updates several times a second, and the game kept its sound in every run. On Windows gap_ns is 0
# and the frames of a burst are rendered back to back: read from the code, not measured here. A device with periods of
# 240 frames or less was not tried and may pace as evenly as the timer. The count and the switch have not been read in a
# run. The site sends the audio thread back to the ring's check (0x8832e8, where the game's own 0x883c18 also branches;
# x21, the engine, is not written between the check and the site), so it takes every queued list in the pass and the
# ring does not stay full. Measured on 1.2.1 at fps_limit 240 (Linux, PipeWire), same save and input script, seconds
# with sound in the mix with the set off and on: without a device 6 of 119 and 111 of 119; with a device 111 of 119 and
# 112 of 119; with the game's stream paused for 5 s from outside (pw-cli, not a real device stalling) while the game ran
# at 240 fps 4 of 120 (silent from the pause on, also after the device resumed) and 113 of 119. A pause of 2 s silenced
# the game with the set off in two runs of two, a pause of 1 s in none of one.
set audiodrain TOTK_AUDIO_DRAIN_FIX 1
site audiodrain main 883780 17fffee6 17fffeda # b 0x883318 -> b 0x8832e8
+7 -4
View File
@@ -1205,9 +1205,12 @@ site qstamp main 6e1324 540000c1 540000c8 # b.ne 0x6e133c -> b.hi 0x
# the game's own call at start, so a DLSS mode can change while the game runs.
hook main 585bd0
# Sound command lists above 200 fps (issue #337): as in patches-v121.txt. The audio thread's check of the command ring
# is main+0x148aec, which wants x8 = the engine (as 0x148ae0 loads it from [x19]); after a list the site goes back to
# it instead of on to 0x148b14, with the two instructions the game itself has at 0x149700. Measured on 1.4.3 at
# fps_limit 240, same save and input script: sound in 2 of 118 s with the set off, in 110 of 119 s with it on.
# Sound command lists above 200 updates a second (issue #337): as in patches-v121.txt, which also says when the game's
# guard fires. The audio thread's check of the command ring is main+0x148aec, which wants x8 = the engine (as 0x148ae0
# loads it from [x19]); after a list the site goes back to it instead of on to 0x148b14, with the two instructions the
# game itself has at 0x149700. Measured on 1.4.3 at fps_limit 240 (Linux, PipeWire), same save and input script, seconds
# with sound in the mix: without a device 3 of 119 with the set off and 113 of 120 with it on; with a device 111 of 119
# with the set off; with the game's stream paused for 5 s from outside at 240 fps, in 60 s runs, 3 of 59 with the set
# off (silent from the pause on) and 51 of 59 with it on; a pause of 2 s with the set off, 4 of 59.
set audiodrain TOTK_AUDIO_DRAIN_FIX 1
site audiodrain main 149244 17fffe34 f9400268 17fffe2a # b 0x148b14 -> ldr x8, [x19]; b 0x148aec
+4 -2
View File
@@ -28,8 +28,10 @@
# highfps_fix = 1
# Climbing walls and ladders at full speed above 60 fps; 30 and 60 fps are unchanged. Needs realtime = 1.
# climb_fix = 1
# The game's audio thread takes every queued sound command list each 5 ms instead of one, so the queue does not fill
# above 200 fps, where the game would switch its sound off for good. 0 = the game's own code.
# The game's audio thread takes every queued sound command list each 5 ms instead of one, so the queue does not stay
# full above 200 fps. With the queue full through 300 updates the game switches its sound off for good: measured with
# audio = none and after the game's audio stream was paused for 2 s and for 5 s in test runs, not while a device plays.
# 0 = the game's own code.
# audio_drain_fix = 1
[performance]