fix(audio): a frame mixed for the old device is dropped when the new one has another channel count #448
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/upscaling
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
testing wanted
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!448
Loading…
Reference in a new issue
No description provided.
Delete branch "jarynclouatre/Longshot:fix/audio-frame-new-channel-count"
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?
Why
When Windows' default output changes between a stereo device and a 5.1 one (or the first device appears after none), one audio frame mixed for the old device is sent to the new one with the other channel count: 5 ms with the channels in the wrong places and, from stereo to 5.1, stale samples behind it. A click at the switch.
renderer_maininhost/nn_audio.cmixes, gains and mono-mixes each frame forout_channels, thenoutput_framemay open the output again (output_moveon a default change,output_open_defaultwhen no device was open;output_opensetsout_channels) and goes on to copy the same samples with the new count.What changed
host/nn_audio.c,output_frame): keeps the channel count its frame was mixed for, and when a reopen in this call changed it, returns without queueing: that frame is dropped and the next one is mixed for the new device. A move that keeps the count still queues its frame. The WAV dump at the top is unchanged (a dump keeps one layout).tests/audio_output_errors_test.candtests/test_audio_output_errors.py: three new cases over the real output section.upmix: stereo fallback, then the default moves to a device that takes 5.1; nothing of the stereo frame reaches a block (a sentinel past its end never appears), the next frame is queued with 6 channels.downmix: the reverse, 5.1 to stereo.retry: no device at the start, then one that takes 5.1. Thedefaultcase now also checks that a stereo-to-stereo move keeps its frame.Flags and settings
None.
Measurements
main:
5e072fc8(2026-11-14)this PR: fix/audio-frame-new-channel-count @
4093570fHardware: none used (game-free checks on a Linux x86-64 PC, gcc 15.2, Python 3.14)
Scene: none, the game was not run
Method:
python3 -I -B tests/run_all.py, two runs each, interleaved (main, the other branch, PR, twice). The new cases also run against main'shost/nn_audio.c(--source).How to reproduce: the commands above in a checkout of each commit
5e072fc84093570ftests/run_all.py(run 1, run 2)test_bake_portability.py,test_menu_keys.py,test_module_ids.py,test_pad_layout.pytests/test_audio_output_errors.pynew casesupmix,downmix,retryfail (the old frame is copied with the new count)test_bake_portability.pyfails here for a missing Python module (zstandard).test_menu_keys.pydoesn't build with g++ andtest_pad_layout.py's fixture lackshost/hold_toggle.h, both on main since #137 (#331 and #338 fix them).test_module_ids.pylooks for a source marker that main no longer has.Testing
Tested: the game-free suite on a Linux PC, as in Measurements; the test compiles the changed output section with gcc and runs it with waveOut faked.
host/nn_audio.ccompiles (-fsyntax-only -Wall -Wextra) with llvm-mingw 20261104's x86_64-w64-mingw32-clang with the same 5 warnings as main's.Not tested: a real device change in the game on Windows (a stereo headset and 5.1 speakers switched as Windows' default while sound plays).
Needs other testers: None.
Screenshots
Nothing on screen.
Risk and rollback
At a switch between channel counts one 5 ms frame is now silent instead of garbled. Reverting the commit puts the copy back.
Issues
None filed. Found reading
output_frameafter #2190's default-device move (Hookshot).Checklist
For everyone
type(scope): description).main.python -I -B tests/run_all.pyrun and passing (any failure that also fails onmainis named above).third_party/untouched (a new folder with aPROVENANCE.mdinstead).If applicable
mainand passing here.tests/that reads changed source updated in this PR, not weakened.WIP: fix(audio): a frame mixed for the old device is dropped when the new one has another channel countto fix(audio): a frame mixed for the old device is dropped when the new one has another channel countView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.