dsp: pass speaker filters by their shape, not by size #457
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/lobomfz--VIctory-xmem!457
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-457"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@niiniiniintje on GitHub · 2026-12-04 11:43 UTC · original
niiniiniintje:dsp-speaker-shape→main· +151 −6 · 2 files · 2 commits · merged 2026-12-05 20:50 UTCProblem
Indoors, dialogue and footsteps sound doubled, like a short echo.
Convolutions aren't computed (the coprocessor's impulse-response layout is unknown). As a stand-in, any convolution whose response has at most 65536 floats passes its input through at 5x (
b69806a, for the phone speaker), and all others are silent. But that size range also contains about a hundred short room reverbs. Passed through, each one plays a second, louder copy of the dry sound.Change
Each response is laid out in 2048-float blocks, and each block holds the spectrum of one 1024-frame partition. By Parseval, a block's energy equals its partition's energy, whatever order the bins are in. So the response's energy over time can be measured without knowing the layout. The trailing block (first word
0xFFFFACE1) isn't a partition, so it's left out.A convolution now passes only if at least 98% of its response's energy is in the first three blocks (~64 ms), which is what a speaker filter looks like. Rooms stay dry, as the other reverbs already were.
To check, I carved all 227 DSP impulse responses (codec 2) out of
audio.rpf. They match the in-memory responses byte for byte.Each stream shape is logged once at info level with its early share.
Testing
speaker_filters_pass_and_rooms_do_not, andconvolution_stream_as_the_title_drives_itupdated to use a speaker-shaped response. Both pass under Wine.@niiniiniintje on GitHub · 2026-12-04 11:46 UTC · original
NOte that this isn't a pure fix, just a small shape test after reading source info on audio more closer. The pure fix is to figure out the audio processor setup on xbox and implement it as the console setup. This approximation gets close enough though.
@Luxuride on GitHub · 2026-12-04 12:20 UTC · original
The heuristic is well argued and validated against all 227 carved impulse responses. One thing must change before it lands, because it is the only thing here that can take the process down.
The
unsaferead is unbounded.response_ofbuildsstd::slice::from_raw_parts(ir, ir_floats as usize)(crates/victory-hle/src/modules/dsp.rs:87-94), and thevalid()gate that runs at activation checks kind/options/frames/channels but neverirorir_floats(dsp.rs:60-75).ir_floatsis bounded only by the caller's own descriptor — up to 2^32 floats. Onmainthe same number was only compared, never dereferenced, which is why this was safe before and is not now. Clamp it invalid()before the read:ir_floats <= 0x1_0000andir_floats % BLOCK_FLOATS == 0, which is also the alignment the block splitter already assumes.Two smaller notes:
early_shareusesresponse.len() / BLOCK_FLOATS(dsp.rs:55), so a trailing partial block is dropped from numerator and denominator alike. A response shorter than one block givesblocks == 0 → None → no pass, and a single-block response whose first float happens to be the footer magic also givesNone. Harmless, but worth a comment so the next person does not "fix" it by rounding up.docs/SETTINGS.mdentry. At minimum, document the transition and what thenote_shapelog line means, so a user whose room reverb changed has something to find.The shape it replaces — an
ir_floats <= 0x1_0000size test — was a proxy for the same thing; the energy share is a better proxy, and the footer-magic check is the right way to drop the trailing block.0 behind, no conflict.
@niiniiniintje on GitHub · 2026-12-04 12:53 UTC · original
Thanks. Bounded in
cd1b7b5, though not invalid(): 48 of the title's 227 responses are over 0x10000 floats (up to 243712), all room reverbs that main activates, so refusing them would change activation. The read now happens only for whole 2048-float blocks up to 0x80000 floats; anything else activates as before, is read as empty and gives silence. Also added the whole-block comment and a paragraph indocs/SETTINGS.md. (The commit message says 40; it is 48.)@niiniiniintje on GitHub · 2026-12-04 14:05 UTC · original
MIght've misread on the SETTINGS comment, was the purpose to note a change in audio or to add a falg to switch between and record that in settings?
@Kal0s-design on GitHub · 2026-12-04 14:10 UTC · original
Checked
cd1b7b5natively on Windows (MSVC build, not Wine).cargo test -p victory-hle --libwith VICTORY_NATIVE_INPUT=0 gives 162 passed, 0 failed, 1 ignored.Negative control. I put the old size rule back inside
passes(a convolution passes if it has at most 0x10000 floats) and left the rest alone.speaker_filters_pass_and_rooms_do_notthen fails at dsp.rs:390, since the 21-block room is under the old limit and passes with an early share of 0.65. The other two dsp tests pass under both rules.a_response_is_read_only_within_its_boundstests a helper that main doesn't have, andconvolution_stream_as_the_title_drives_ituses a one-block response that either rule passes.The unbounded read from the earlier review is fixed.
response_ofreads only whole blocks, up to 0x80000 floats (dsp.rs:96-105), andvalid()is unchanged, so activation accepts the same descriptors as main.I also fuzzed
passesandresponse_oflocally (not pushed). 20000 random buffers of random length, some whole blocks and some not, filled with random bits, NaN, inf and footer words, each run with four kind values. Nothing panicked, the share always stayed between 0 and 1, and only kind 1 ever passed. Throughresponse_of, everyir_floatsI tried (0, 1, 2047, 2048, 2049, the cap, the cap plus one block, u32::MAX, plus random values) came back as whole blocks and never past the cap. Then I took a passing speaker shape and changed one thing at a time. These were all rejected: another kind, a 4th block with about 3% of the energy, a NaN or inf anywhere, all zeros, a nullir,ir_floatsof 0, andir_floatsone short of a whole block. At about 1.3% late energy it still passes, and it also still passes with the footer word cleared.What changes compared to main, in both directions:
ir,ir_floatsof 0, or a size that isn't whole blocks used to pass at or under 0x10000 floats. Now these give silence (dsp.rs:96-101).I don't have the game data, so I couldn't check whether any of the 41 passing responses are over 0x10000 floats, or whether all of the title's responses are whole blocks.
A small non-blocking note.
note_shapekeys on kind, options, frames, channels and ir_floats, not on the response itself (dsp.rs:111-120). So two different responses with the same size log only once, showing the first one'spassesandearly_share. The 40960-float group is mixed, according to the PR description, so for that group the log line and the new SETTINGS.md sentence can mislead.Looks good to me.
AI-assisted: yes