The sound engine's audio thread takes every queued command list, so the game keeps its sound above 200 fps (#337)

The game thread hands its sound commands to the audio thread in lists: 16, of which 4 are always held, so at most 12
wait in the command ring. The game thread submits at most one per update (1.2.1 main+0x9bd144), the audio thread
takes one per 5 ms audio frame (after a list, main+0x883780 goes on past the ring's check). Above about 200 updates a
second the ring stays full. The game's guard (main+0x9bcdc4) 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 returns 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
(main+0x2268bfc) and stops every active voice (main+0x226f29c). Only the switch's constructor sets it to 1
(main+0xf31ce8, from the engine's init main+0xf31530), so the game is silent until it is restarted.

Measured on 1.2.1 (Linux, RX 6750 XT), same save and scripted input, mix dumped without a device: with fps_limit 60,
144, 180, 200 and 201 the mix has sound; with 205, 210, 220, 230, 239 and 240 it goes silent after the boot logo and
stays silent, also at the 130-148 fps of the scene that follows. The guard is read from the code; the switch going
to 0 has not been observed in a run.

The set audiodrain (TOTK_AUDIO_DRAIN_FIX, audio_drain_fix, on by default) sends the audio thread back to the ring's
check after each list, so it takes every queued list in the pass: one site per version (1.2.1 main+0x883780, 1.4.3
main+0x149244), each going to a target the game's own code already branches to in the same way (1.2.1 main+0x883c18,
1.4.3 main+0x149700). The setting is in runtime/cfg.c, totk.ini.example and docs/settings.md.

At fps_limit 240, 120 s runs of one build per game version with the set switched, seconds with sound in the mix: on
1.2.1 5 of 118 with the set off and 108 of 118 with it on; on 1.4.3 2 of 118 off and 110 of 119 on. Not run:
Windows. Not covered: 1.1.0, whose main we do not have, so its table has no site and it keeps the game's code.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
shinodanpenandClaude authored and Valiantsin Dzerakh committed 2026-11-17 18:56:55 +03:00
1 parent a5c3e0f9f5
commit 037a39d303
5 files changed
+31 -3

No files matched your search

+17
View File
@@ -1151,3 +1151,20 @@ site optref main 1622bec b4000188 937ffd09 8a290108 b4000188 # cbz x8 -> asr x
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.
set audiodrain TOTK_AUDIO_DRAIN_FIX 1
site audiodrain main 883780 17fffee6 17fffeda # b 0x883318 -> b 0x8832e8
+7
View File
@@ -1177,3 +1177,10 @@ site report main a2310 531f7821 530f7c24 531f7821 35000184 # lsr w4, w1, #15;
# hook. main+0x585bd0 sets the render size (runtime/resolution.c SET_RENDER_SIZE): res_fn_hit takes the renderer from
# 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.
set audiodrain TOTK_AUDIO_DRAIN_FIX 1
site audiodrain main 149244 17fffe34 f9400268 17fffe2a # b 0x148b14 -> ldr x8, [x19]; b 0x148aec