perf(audio): no stutter in step with Link's footsteps with a cabled DualSense (the speaker's sound search reads a few spots, not 64 KB) #2312

Merged
HumanBean merged 3 commits from Veix/Longshot:fix/pad-speaker-search into main 2026-11-23 15:17:29 +00:00
Contributor

Summary

With a DualSense on a cable, the frame time zigzags in step with Link's footsteps. The controller speaker looks up every sound buffer the game queues by searching up to 64 KB of memory in front of it.

Since #1545, some sound classes play from the DualSense's speaker by default (Navi's voice, Z-targeting, pick-ups, ...). To know which sound a wave buffer belongs to, AppendWaveBuffer calls hos_audio_source_of for every buffer the game queues, and it searched for the wave's header up to 64 KB (BWAV_MAX_BEFORE) in front of the samples, with VirtualQuery over that range first. A buffer that continues a streamed sound, or a later one of a looping sound, has no header in front of it, so the whole 64 KB was searched every time, on the audio thread, while it holds one of the game's virtual cores and the audio lock. A single search took up to 2-3 ms. The game's other threads waited for it, and the frame time rose and fell with each footstep sound (a rhythm at 4.6 Hz, Link's running steps).

A wave's first channel always starts right behind its header and its channel table, on the archive's 0x40 alignment: 0x80 bytes for a mono wave, at most 0x280 for 8 channels. hos_audio_source_of now looks only at those spots (at most 9 probes, one page boundary at most) instead of 64 KB. When it finds a header, it takes the start of every channel of that wave from the header's own table and keeps them by address, so a wave's later channels (up to megabytes behind the header) and every later play of the same sound are found by one lookup. An entry is trusted only while the same wave's header (its magic and checksum) is still in front of it. A buffer that neither names is searched as far as main searched, once: a later channel queued before its first is found as before, and where that search finds no header (a streamed sound's ring) the place is kept as such, so a ring that comes round again costs a look in the table. Every buffer is still classed, as before.

How to see it on main: a DualSense on a USB cable (the speaker needs its USB sound card; over Bluetooth it stays off), the speaker at its defaults, Castle Town's market, run around. The frame graph zigzags in step with the footsteps; with HOS_PAD_SPEAKER=0 it is flat.

Read first: hos_audio_source_of in host/audio_source.c, audio_source_find_back and BWAV_FIRST_MAX in host/audio_source.h, then tests/test_audio_source_load.py.

Testing

Please no automatic fixes on this branch (@fix, bot pushes): review comments are welcome, I make the changes myself.

Tested: Windows 11, RTX 4070 SUPER 12 GB, driver 621.24, Ryzen 9 9900X, a DualSense on a USB cable, the speaker at its defaults (the log: "pad speaker: playing on the DualSense's endpoint" in every run). The scripted Castle Town route, two interleaved runs each side (below): the footstep zigzag gone, frames over 20 ms a third of main's. The first-channel spot checked on the game's own data: all 1,152 sound archives (Sound/Resource/*.bars.zs, unpacked with the game's dictionary), 25,676 waves; every first channel lies right behind its header and channel table (0x80 mono x24,728, 0xc0 stereo x614, up to 0x200 for 6 channels), none elsewhere, the channels always in ascending order.
Of the 948 multi-channel waves, 115 have a later channel between 0x280 bytes and 64 KB behind the header (44 of them menu sounds in UI_Static), which main found with its far search and this finds the same way, once a place; 850 have one beyond 64 KB, which main never found and this finds from their first channel's header.
tests/test_audio_source_load.py fails on main ("asked_most <= 0x280": for a streamed buffer main asks about 64 KB of memory), fails on 4f03fec7 for review L1 (a later channel queued first not found), and passes here. It counts the far searches: a mono sound played 100 times, 0; a later channel queued first, 10 plays, 1; a streamed ring of 8 places come round 100 times, 8; after the kept places are pushed out by 2,048 others, the later channel found again with at most 1 more. tests/test_audio_source.py and tests/test_audio_wave_buffer_release.py pass; tests/run_all.py --changed origin/main: 18 passed, 0 failed (1 skipped: Linux only). The whole suite and the Linux build: CI.

Still to test:

  • Windows with another GPU (Test Farm, a DualSense on a cable if a tester has one): Castle Town, run around, expecting a flat frame graph and Navi, Z-targeting and pick-ups from the controller as on main (@Beanstalk)

Measurements

Verdict: frames over 20 ms in Castle Town 74 and 90 on main, 26 and 26 here; the footstep rhythm gone (0.46 and 0.57 ms of swing at 4.6 Hz on main, 0.04 and 0.08 here).

Setup: Windows 11, RTX 4070 SUPER 12 GB, driver 621.24, Ryzen 9 9900X, a DualSense on a USB cable, the speaker at its defaults. 2560x1440, DLAA, uncapped (HOS_FPS_MAX=1000), V-Sync off, RX_VK_LOAD=start, RX_VK_FRAME_GATE=0 (main's default), no other switch but the frame trace's, the same on both sides. Both builds from the same lift of main 753fb5af (lifted code df6d1eb1a7), only the host code differs. The scripted route through Castle Town's market and the castle, in the order main, PR, main, PR; the second market stay from 5 s after its entry (54.5 s, ~4,100 frames), from the frame trace; both runs of each side are given.

Before: main @ 753fb5af After: this PR @ 4f03fec7
Frames over 20 ms 74 / 90 26 / 26
of them: the game's own time 27 / 39 8 / 6
of them: textures made in the frame 29 / 37 10 / 14
Swing of the frame time at 4.6 Hz (Link's steps) 0.46 / 0.57 ms 0.04 / 0.08 ms
99th percentile frame 20.5 / 21.6 ms 19.5 / 19.4 ms
99th percentile of the game's own time 18.8 / 19.3 ms 16.5 / 16.6 ms
Median frame 12.9 / 12.7 ms 12.7 / 12.7 ms
fps 74.8 / 75.2 76.7 / 76.2

The head 0443f84a (review L1 and L2), one run with the same setup and lift: 22 frames over 20 ms, 0.09 ms of swing at 4.6 Hz, p99 19.1 ms, the game's own time p99 16.3 ms: as the two runs above.

Earlier, the same route at 3840x2160 DLAA with one run each on an older lift: main 136 frames over 20 ms, HOS_PAD_SPEAKER=0 95, this change 83; the 4.6 Hz swing 0.51, 0.08 and 0.11 ms.

Risks

The worst case is a sound played from the wrong speaker (the TV instead of the controller, or the other way round). Nothing else in the game's sound or memory changes: every read goes through the same checks as on main.

  • Only where a first channel can start: the window is the header and its channel table for 8 channels, on the alignment the archives use; checked on every wave the game has (above).
  • A later channel queued first is searched as far as main searched, and found; its wave's channels are kept from then on. One case still differs from main: a place kept as having no header (a streamed sound's ring) whose memory the game later gives to a wave's later channel is not searched far again, so that sound plays with the voice's previous class until its wave's first channel is queued, which keeps every channel of it. main searched it again.
  • A kept channel start is checked before it is used: the same header's magic and checksum must still be in front of it, its 16 bytes mapped and readable; anything else is searched again.
  • One caller: AppendWaveBuffer, under the audio lock.

Windows only in practice: the speaker needs the DualSense's USB sound card, which the endpoint lookup finds only on Windows. HOS_PAD_SPEAKER=0 turns the speaker off; a revert is enough. A player notices nothing after updating: no save or option changes.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here.
  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

Written with the help of an AI coding agent.

## Summary **With a DualSense on a cable, the frame time zigzags in step with Link's footsteps. The controller speaker looks up every sound buffer the game queues by searching up to 64 KB of memory in front of it.** Since #1545, some sound classes play from the DualSense's speaker by default (Navi's voice, Z-targeting, pick-ups, ...). To know which sound a wave buffer belongs to, `AppendWaveBuffer` calls `hos_audio_source_of` for every buffer the game queues, and it searched for the wave's header up to 64 KB (`BWAV_MAX_BEFORE`) in front of the samples, with `VirtualQuery` over that range first. A buffer that continues a streamed sound, or a later one of a looping sound, has no header in front of it, so the whole 64 KB was searched every time, on the audio thread, while it holds one of the game's virtual cores and the audio lock. A single search took up to 2-3 ms. The game's other threads waited for it, and the frame time rose and fell with each footstep sound (a rhythm at 4.6 Hz, Link's running steps). A wave's first channel always starts right behind its header and its channel table, on the archive's 0x40 alignment: 0x80 bytes for a mono wave, at most 0x280 for 8 channels. `hos_audio_source_of` now looks only at those spots (at most 9 probes, one page boundary at most) instead of 64 KB. When it finds a header, it takes the start of every channel of that wave from the header's own table and keeps them by address, so a wave's later channels (up to megabytes behind the header) and every later play of the same sound are found by one lookup. An entry is trusted only while the same wave's header (its magic and checksum) is still in front of it. A buffer that neither names is searched as far as `main` searched, once: a later channel queued before its first is found as before, and where that search finds no header (a streamed sound's ring) the place is kept as such, so a ring that comes round again costs a look in the table. Every buffer is still classed, as before. How to see it on `main`: a DualSense on a USB cable (the speaker needs its USB sound card; over Bluetooth it stays off), the speaker at its defaults, Castle Town's market, run around. The frame graph zigzags in step with the footsteps; with `HOS_PAD_SPEAKER=0` it is flat. Read first: `hos_audio_source_of` in `host/audio_source.c`, `audio_source_find_back` and `BWAV_FIRST_MAX` in `host/audio_source.h`, then `tests/test_audio_source_load.py`. ## Testing **Please no automatic fixes on this branch (`@fix`, bot pushes): review comments are welcome, I make the changes myself.** **Tested:** Windows 11, RTX 4070 SUPER 12 GB, driver 621.24, Ryzen 9 9900X, a DualSense on a USB cable, the speaker at its defaults (the log: "pad speaker: playing on the DualSense's endpoint" in every run). The scripted Castle Town route, two interleaved runs each side (below): the footstep zigzag gone, frames over 20 ms a third of `main`'s. The first-channel spot checked on the game's own data: all 1,152 sound archives (`Sound/Resource/*.bars.zs`, unpacked with the game's dictionary), 25,676 waves; every first channel lies right behind its header and channel table (0x80 mono x24,728, 0xc0 stereo x614, up to 0x200 for 6 channels), none elsewhere, the channels always in ascending order. Of the 948 multi-channel waves, 115 have a later channel between 0x280 bytes and 64 KB behind the header (44 of them menu sounds in `UI_Static`), which `main` found with its far search and this finds the same way, once a place; 850 have one beyond 64 KB, which `main` never found and this finds from their first channel's header. `tests/test_audio_source_load.py` fails on `main` ("asked_most <= 0x280": for a streamed buffer `main` asks about 64 KB of memory), fails on 4f03fec7 for review L1 (a later channel queued first not found), and passes here. It counts the far searches: a mono sound played 100 times, 0; a later channel queued first, 10 plays, 1; a streamed ring of 8 places come round 100 times, 8; after the kept places are pushed out by 2,048 others, the later channel found again with at most 1 more. `tests/test_audio_source.py` and `tests/test_audio_wave_buffer_release.py` pass; `tests/run_all.py --changed origin/main`: 18 passed, 0 failed (1 skipped: Linux only). The whole suite and the Linux build: CI. **Still to test:** - Windows with another GPU (Test Farm, a DualSense on a cable if a tester has one): Castle Town, run around, expecting a flat frame graph and Navi, Z-targeting and pick-ups from the controller as on `main` (@Beanstalk) ## Measurements **Verdict:** frames over 20 ms in Castle Town 74 and 90 on `main`, 26 and 26 here; the footstep rhythm gone (0.46 and 0.57 ms of swing at 4.6 Hz on `main`, 0.04 and 0.08 here). Setup: Windows 11, RTX 4070 SUPER 12 GB, driver 621.24, Ryzen 9 9900X, a DualSense on a USB cable, the speaker at its defaults. 2560x1440, DLAA, uncapped (`HOS_FPS_MAX=1000`), V-Sync off, `RX_VK_LOAD=start`, `RX_VK_FRAME_GATE=0` (main's default), no other switch but the frame trace's, the same on both sides. Both builds from the same lift of `main` 753fb5af (`lifted code df6d1eb1a7`), only the host code differs. The scripted route through Castle Town's market and the castle, in the order main, PR, main, PR; the second market stay from 5 s after its entry (54.5 s, ~4,100 frames), from the frame trace; both runs of each side are given. | | Before: main @ 753fb5af | After: this PR @ 4f03fec7 | |---|---|---| | Frames over 20 ms | 74 / 90 | 26 / 26 | | of them: the game's own time | 27 / 39 | 8 / 6 | | of them: textures made in the frame | 29 / 37 | 10 / 14 | | Swing of the frame time at 4.6 Hz (Link's steps) | 0.46 / 0.57 ms | 0.04 / 0.08 ms | | 99th percentile frame | 20.5 / 21.6 ms | 19.5 / 19.4 ms | | 99th percentile of the game's own time | 18.8 / 19.3 ms | 16.5 / 16.6 ms | | Median frame | 12.9 / 12.7 ms | 12.7 / 12.7 ms | | fps | 74.8 / 75.2 | 76.7 / 76.2 | The head 0443f84a (review L1 and L2), one run with the same setup and lift: 22 frames over 20 ms, 0.09 ms of swing at 4.6 Hz, p99 19.1 ms, the game's own time p99 16.3 ms: as the two runs above. Earlier, the same route at 3840x2160 DLAA with one run each on an older lift: `main` 136 frames over 20 ms, `HOS_PAD_SPEAKER=0` 95, this change 83; the 4.6 Hz swing 0.51, 0.08 and 0.11 ms. ## Risks **The worst case is a sound played from the wrong speaker (the TV instead of the controller, or the other way round). Nothing else in the game's sound or memory changes: every read goes through the same checks as on `main`.** - **Only where a first channel can start:** the window is the header and its channel table for 8 channels, on the alignment the archives use; checked on every wave the game has (above). - **A later channel queued first** is searched as far as `main` searched, and found; its wave's channels are kept from then on. One case still differs from `main`: a place kept as having no header (a streamed sound's ring) whose memory the game later gives to a wave's later channel is not searched far again, so that sound plays with the voice's previous class until its wave's first channel is queued, which keeps every channel of it. `main` searched it again. - **A kept channel start is checked before it is used:** the same header's magic and checksum must still be in front of it, its 16 bytes mapped and readable; anything else is searched again. - **One caller:** `AppendWaveBuffer`, under the audio lock. Windows only in practice: the speaker needs the DualSense's USB sound card, which the endpoint lookup finds only on Windows. `HOS_PAD_SPEAKER=0` turns the speaker off; a revert is enough. A player notices nothing after updating: no save or option changes. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (any failure that also fails on `main` is named). - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. - [x] A check under `tests/` that reads changed source is updated, not weakened. - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. Written with the help of an AI coding agent.
A buffer that continues a streamed sound has no wave header in front of it. The search should look only where a
wave's first channel can start (right behind its header and channel table, 0x280 bytes at most), and a later
channel is found from its first channel's header. Fails on main: it asks about 64 KB of memory for every such buffer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
perf(audio): the controller speaker's sound search reads a few spots, not 64 KB, on every wave buffer
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Failing after 7s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
4f03fec72a
With a cabled DualSense and the controller speaker on (its default), every wave buffer the game queued was searched
for its wave's header up to 64 KB in front of it, with VirtualQuery over that range: a buffer that continues a
streamed sound has none, so the whole 64 KB every time, in step with the footsteps.

Now a wave's first channel is looked for only where it can start (right behind the header and its channel table,
0x280 bytes at most), and the starts of all its channels are taken from that header's own table, so later
channels and later plays of the same sound are found by their address (checked against the header's magic and
checksum before they are trusted). Every buffer is still classed, as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Contributor

Tested in game: Windows 11, RTX 4070 SUPER 12 GB, driver 621.24, a DualSense on a USB cable with the speaker at its defaults: Castle Town's market and the castle on the scripted route, two runs of main and two of this PR interleaved at 1440p DLAA uncapped. The frame graph's zigzag in step with Link's footsteps is gone; frames over 20 ms 74 and 90 on main, 26 and 26 here.

Tested in game: Windows 11, RTX 4070 SUPER 12 GB, driver 621.24, a DualSense on a USB cable with the speaker at its defaults: Castle Town's market and the castle on the scripted route, two runs of main and two of this PR interleaved at 1440p DLAA uncapped. The frame graph's zigzag in step with Link's footsteps is gone; frames over 20 ms 74 and 90 on main, 26 and 26 here.
Owner
@review
BeanBot left a comment

Recommendation: Request changes. The measured Windows run shows a substantial reduction in footstep-related frame-time spikes, but the shorter search can repeatedly misroute channels that main classified.

The change replaces a 64 KB search on each queued audio buffer with a short search and an address cache. It reduces the measured frame-time spikes for a cabled DualSense, at the cost of losing classification for some later channels.

Blocking (1): must change before merging.

  1. L1 host/audio_source.c:284: A later channel is no longer found unless its first channel has already populated the cache, and the cache does not guarantee that this only happens once. (more on the line) Do: Preserve classification of later channels independently of first-channel queue order and cache eviction, while keeping the common streamed-buffer search bounded; add a game-free test covering repeated later-channel-first plays and eviction.

Nits (1): optional.

  • L2 host/audio_source.c:295: The description says the cache records channels up to megabytes behind the header, but it discards every offset above 64 KB. (more on the line) Do: Describe the 64 KB cache limit and its effect, or support the larger offsets with appropriate validation and a test.

@fix can do L1 and L2.

Checks: Failing on this head, which is behind its base, where it passes: PR description / Description follows the template (pull_request_target). @rebase (or @fix) brings it up to date and runs it again; not held against it. Still running: 9 checks.

More: does it help, other systems, switches, what was read

Does it help: Yes. In two interleaved Castle Town runs per side on Windows with an RTX 4070 SUPER and Ryzen 9 9900X, frames over 20 ms fell from 74/90 to 26/26, and the 4.6 Hz frame-time swing fell from 0.46/0.57 ms to 0.04/0.08 ms. These are the author's reported frame-trace numbers.

Other systems: The lookup is reached only while the controller speaker is active and runs under the audio lock. Windows page-read checks and Linux compilation are affected; the reported game runs cover Windows on one machine, while the requested additional Windows hardware run and host builds remain outstanding.

Switches: None added, changed or removed.

Reviewed: 4f03fec72a against 753fb5af68: Read AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the pull request template, the commits, all three changed files, and the relevant audio caller and memory-region check. Skimmed references in other tests. docs/review-checklist.md and ../Tooling/AGENTS.md were absent. No generated files or recorded runs were changed.; nothing run (a code review).

Checked and fine:

  • The cache's only production caller holds the audio lock.
  • Both commits record AI assistance, and the diff adds no switch, generated file, or game-derived file.
  • The new bounded-search assertion would fail against the previous 64 KB search.

Testing: No code or tests were run, as requested. The author reports the game-free audio tests passing and the Windows game measurements; CI is still running.

Overlaps and merge order: Not checked; the network is closed.


Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The measured Windows run shows a substantial reduction in footstep-related frame-time spikes, but the shorter search can repeatedly misroute channels that main classified. The change replaces a 64 KB search on each queued audio buffer with a short search and an address cache. It reduces the measured frame-time spikes for a cabled DualSense, at the cost of losing classification for some later channels. **Blocking (1)**: must change before merging. 1. **L1** `host/audio_source.c:284`: A later channel is no longer found unless its first channel has already populated the cache, and the cache does not guarantee that this only happens once. (more on the line) **Do:** Preserve classification of later channels independently of first-channel queue order and cache eviction, while keeping the common streamed-buffer search bounded; add a game-free test covering repeated later-channel-first plays and eviction. **Nits (1)**: optional. - **L2** `host/audio_source.c:295`: The description says the cache records channels up to megabytes behind the header, but it discards every offset above 64 KB. (more on the line) **Do:** Describe the 64 KB cache limit and its effect, or support the larger offsets with appropriate validation and a test. `@fix` can do L1 and L2. **Checks:** Failing on this head, which is behind its base, where it passes: `PR description / Description follows the template (pull_request_target)`. `@rebase` (or `@fix`) brings it up to date and runs it again; not held against it. Still running: 9 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes. In two interleaved Castle Town runs per side on Windows with an RTX 4070 SUPER and Ryzen 9 9900X, frames over 20 ms fell from 74/90 to 26/26, and the 4.6 Hz frame-time swing fell from 0.46/0.57 ms to 0.04/0.08 ms. These are the author's reported frame-trace numbers. **Other systems:** The lookup is reached only while the controller speaker is active and runs under the audio lock. Windows page-read checks and Linux compilation are affected; the reported game runs cover Windows on one machine, while the requested additional Windows hardware run and host builds remain outstanding. **Switches:** None added, changed or removed. **Reviewed:** 4f03fec72a89 against 753fb5af6860: Read AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the pull request template, the commits, all three changed files, and the relevant audio caller and memory-region check. Skimmed references in other tests. docs/review-checklist.md and ../Tooling/AGENTS.md were absent. No generated files or recorded runs were changed.; nothing run (a code review). **Checked and fine:** - The cache's only production caller holds the audio lock. - Both commits record AI assistance, and the diff adds no switch, generated file, or game-derived file. - The new bounded-search assertion would fail against the previous 64 KB search. **Testing:** No code or tests were run, as requested. The author reports the game-free audio tests passing and the Windows game measurements; CI is still running. **Overlaps and merge order:** Not checked; the network is closed. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
@ -260,3 +283,2 @@
}
before = readable;
#endif
size_t before = BWAV_FIRST_MAX; /* (as far as the game's memory is mapped before it) */
Member

L1 (blocking): A later channel is no longer found unless its first channel has already populated the cache, and the cache does not guarantee that this only happens once.

When: If a wave's second channel starts more than 0x280 but at most 0x10000 bytes after its header and is queued before its first channel, main finds the header but this search returns -1. If the first channel is never queued, or its cache entry is displaced before the later channel is queued on another play, the channel keeps the voice's previous class on every such play and can be routed to the wrong output.

Do: Preserve classification of later channels independently of first-channel queue order and cache eviction, while keeping the common streamed-buffer search bounded; add a game-free test covering repeated later-channel-first plays and eviction.

**L1** (blocking): A later channel is no longer found unless its first channel has already populated the cache, and the cache does not guarantee that this only happens once. *When:* If a wave's second channel starts more than 0x280 but at most 0x10000 bytes after its header and is queued before its first channel, main finds the header but this search returns -1. If the first channel is never queued, or its cache entry is displaced before the later channel is queued on another play, the channel keeps the voice's previous class on every such play and can be routed to the wrong output. **Do:** Preserve classification of later channels independently of first-channel queue order and cache eviction, while keeping the common streamed-buffer search bounded; add a game-free test covering repeated later-channel-first plays and eviction.
@ -265,0 +292,4 @@
const unsigned channels = audio_source_u16(h + BWAV_CHANNELS);
for (unsigned ch = 0; ch < channels; ch++) { /* (every channel's start, by the header's table) */
const uint32_t off = audio_source_u32(h + BWAV_HEADER + ch * BWAV_CHANNEL + BWAV_CHANNEL_DATA);
if (off < BWAV_ALIGN * 2 || off > BWAV_MAX_BEFORE) continue;
Member

L2 (nit): The description says the cache records channels up to megabytes behind the header, but it discards every offset above 64 KB.

When: For a wave with a channel offset greater than 0x10000, finding its first channel does not cache that later channel; its subsequent buffer cannot be found by the 0x280-byte search.

Do: Describe the 64 KB cache limit and its effect, or support the larger offsets with appropriate validation and a test.

**L2** (nit): The description says the cache records channels up to megabytes behind the header, but it discards every offset above 64 KB. *When:* For a wave with a channel offset greater than 0x10000, finding its first channel does not cache that later channel; its subsequent buffer cannot be found by the 0x280-byte search. **Do:** Describe the 64 KB cache limit and its effect, or support the larger offsets with appropriate validation and a test.
fix(audio): a later channel queued first is searched as far as main did, once a place
Some checks failed
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Failing after 11s
0443f84a75
Review L1: a wave's later channel queued before its first was no longer found (its header lies up to 64 KB in front
of it, past the 0x280 bytes looked at), and nothing made that happen only once. Now a buffer that neither the kept
places nor the near search name is searched as far as main searched, and every channel of the wave found is kept;
where that search finds no header (a streamed sound's ring) the place is kept as such, so each place is searched far
once and a ring that comes round costs a look in the table. Review L2: the channel starts are kept wherever they lie,
not only within 64 KB (each is checked against its header before it is used).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Contributor

L1 and L2 are fixed in 0443f84a, the way L1 asked. The gain holds: 22 frames over 20 ms in the market, against 74 and 90 on main.

L1: right: 115 of the game's 948 multi-channel waves have a later channel between 0x280 bytes and 64 KB behind the header (44 are menu sounds). A buffer that neither the kept places nor the near search name is now searched as far as main searched, once a place: a later channel queued first is found, and where no header is found (a streamed sound's ring) the place is kept as such, so the ring costs a table lookup when it comes round. The new test counts the far searches: later channel first, 10 plays: found every time, 1 far search; mono sound, 100 plays: 0; a ring of 8 places, 100 rounds: 8; after eviction: found, at most 1 more. It fails on 4f03fec7 and on main. One case still differs from main (a no-header place later reused for a wave); it is in the Risks section.

L2: channel starts are kept wherever they lie, each checked against its header before use, so the 850 waves with a channel beyond 64 KB, which main never classed, are classed too.

**L1 and L2 are fixed in 0443f84a, the way L1 asked. The gain holds: 22 frames over 20 ms in the market, against 74 and 90 on `main`.** **L1:** right: 115 of the game's 948 multi-channel waves have a later channel between 0x280 bytes and 64 KB behind the header (44 are menu sounds). A buffer that neither the kept places nor the near search name is now searched as far as `main` searched, once a place: a later channel queued first is found, and where no header is found (a streamed sound's ring) the place is kept as such, so the ring costs a table lookup when it comes round. The new test counts the far searches: later channel first, 10 plays: found every time, 1 far search; mono sound, 100 plays: 0; a ring of 8 places, 100 rounds: 8; after eviction: found, at most 1 more. It fails on 4f03fec7 and on `main`. One case still differs from `main` (a no-header place later reused for a wave); it is in the Risks section. **L2:** channel starts are kept wherever they lie, each checked against its header before use, so the 850 waves with a channel beyond 64 KB, which `main` never classed, are classed too.
HumanBean deleted branch fix/pad-speaker-search 2026-11-23 15:17:29 +00:00
Some checks failed
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Failing after 11s
Some workflows are waiting to be reviewed.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
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
MagicBeanDev/Longshot!2312
No description provided.