feat(libSceAudioOut): host volume and mute hotkeys, opt-in mute on focus loss #12569

Merged
MarcZX10 merged 75 commits from upstream-pr/12569 into main 2026-10-30 20:46:25 +00:00
MarcZX10 commented 2026-10-28 20:45:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T20:45:28Z.


What

Host-side master volume and mute for the game window, plus an opt-in mute while the window has no focus. This is a control of the host, like a media player's volume. It is not a console behaviour and the title does not see it.

  • Hotkeys are three new input-mapping actions in the same system as F10, F11 and F12: VolumeDown (F5), VolumeUp (F6), ToggleMute (F8). They are keyboard-only, rebindable in anyps5-input.ini, never reach the pad, and follow the same conflict rule as the existing actions (a shared key triggers both). F5, F6 and F8 are used by no other default binding. Each handled press prints one line on stderr.
  • Volume is 0 to 100 in steps of 5, starting at 100 or at ANYPS5_VOLUME. The gain is the square of the volume as a fraction of 100, in 16.16 fixed point. Mute is separate from the volume, so unmuting restores it. A volume key while muted also unmutes. A gain change ramps at a constant per-frame step (10 ms for a full-scale change), exact and continuous across buffers.
  • ANYPS5_MUTE_ON_FOCUS_LOSS=1 mutes while the display window has no focus and restores on focus gained. Unset or 0 is today's behaviour. It never replaces the user's own mute. Only focus events of the display window count. An invalid value of either variable, including an empty one, stops the game with an error naming the variable.
  • At the default state (volume 100, not muted, focus not lost) the audio path is bypassed entirely: the title's own buffer pointer goes to SDL, with no copy and no multiply. A reopened port or a returned ramp is exactly at unity again.
  • Where it applies: AudioOut.cpp just before SDL_QueueAudio for every non-vibration port, and AudioOut2Context.cpp in DeviceCallback (the only place the main mix reaches the speakers). libSceAudio3d plays through sceAudioOutOutput, so it is covered. Not touched: the controller's sound card and haptics (vibration ports, the AudioOut2 pad device), and the microphone.
  • No on-screen indicator: feedback is the stderr line only.

Commits (67): the pure state class and its steps, mute independence, focus, gain (each with its test), the ramp and the S16 and float gain with their tests, the bypass filter, the strict setting parsers and message wording, the shared state, one commit per playback hook, the three input controls (per action: key request, mapping action, default key, each with a test), the VideoOut wiring (settings at startup, hotkeys, focus events, first focus read), and docs per file (ENVIRONMENT.md, INPUT_MAPPING.md in three commits, USAGE.md). The input mapper's action list and defaults follow the native table (its source-contract test).

Overlaps with open PRs (edits kept local, branched from main): #7499 (InputMapping.hpp/.cpp, PadInput.cpp, tests/InputMapping.cpp, INPUT_MAPPING.md), #11860 (input mapper and tests/InputMapping.cpp), #9154 (AudioOut.cpp, AudioOut2Context.cpp, VideoOut CMakeLists.txt, PadInput.cpp), #11049 and #11584 (libSceAudioOut/CMakeLists.txt), #12379 and #12536 (VideoOut, CMake and VulkanDevice areas; no code of theirs used).

Tested

Linux x86_64, GCC 12, throwaway archive build of this branch and of main (319621ba2e). No console, no title.

  • New tests, all passed: audio_out_host_volume (state machine, steps at 0 and 100, mute restore, focus transitions, gain, strict setting parsers, messages), audio_out_host_gain (S16 and float on mono, stereo and 8 channels: byte-for-byte bypass at unity, exact first sample and landing frame, up and down ramps, no step above the slope, a ramp split across buffers equal to one buffer, saturation, rounding, filter pointer and copy rules), audio_out_host_volume_state (shared state, env parsing, invalid values refused and named, concurrent readers), pad_host_volume (requests and focus events). pad_keyboard_mouse and pad_input_mapping gained cases for the three actions, their defaults, key repeat, mouse and wheel refusal, shared keys and unknown names. Input mapper: node --test tests 25 pass.
  • Existing audio, input and video-out tests, ctest -R '^(audio_out|pad_|video_out_)': main 85 tests, 0 failed; this branch 89 tests, 0 failed. The per-test results are identical except for the four added tests (pad_command_file was not built in the first branch run and passed when built).
  • Video-out with a display: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation xvfb-run -a ctest -R '^(video_out_|pad_)' -V with -DANYPS5_VIDEO_OUT_TEST_DRIVER=x11: main 33/33 passed, branch 34/34 passed (the extra one is pad_host_volume). The validation layer was found in both runs and VUID- appears 0 times in both.
  • Negative controls: 51 mutations of the new code (step clamps, mute independence, focus rules, gain at default and its curve, parsers, bypass, ramp, saturation, rounding, per-frame gain, filter copy rules, state publishing, env names, window ID and event rules, request order, key repeat, keyboard-only rules, default keys) were applied in scratch copies. 50 fail at the intended assertion. The last one, accepting an empty level, is an equivalent mutant because std::from_chars already rejects an empty string. Two controls first passed (an upward ramp without a final snap, S16 truncation instead of rounding); tests were added and now catch them. Removing the bypass is not caught by the byte-for-byte S16 sample test, since unity is an identity; the filter's pointer and copy assertions catch it.
  • check_conventions.py --base upstream/main, git diff --check, the public-headers audit and env_reference.py --check are clean.

Not run: Windows, macOS, a real audio device (the hooks themselves were reasoned, not heard), a real window system with a real SDL focus sequence (the hotkey wiring and focus events in PadInput.cpp are covered through the pure functions they call, not end to end), a hardware GPU, a console.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: llvmpipe (LLVM 15.0.6, 256 bits), Vulkan software rasterizer via Xvfb (x11 driver), Linux 6.1; no hardware GPU
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5057431503 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12569). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T20:45:28Z. --- ### What Host-side master volume and mute for the game window, plus an opt-in mute while the window has no focus. This is a control of the host, like a media player's volume. It is not a console behaviour and the title does not see it. - Hotkeys are three new input-mapping actions in the same system as F10, F11 and F12: `VolumeDown` (F5), `VolumeUp` (F6), `ToggleMute` (F8). They are keyboard-only, rebindable in `anyps5-input.ini`, never reach the pad, and follow the same conflict rule as the existing actions (a shared key triggers both). F5, F6 and F8 are used by no other default binding. Each handled press prints one line on stderr. - Volume is 0 to 100 in steps of 5, starting at 100 or at `ANYPS5_VOLUME`. The gain is the square of the volume as a fraction of 100, in 16.16 fixed point. Mute is separate from the volume, so unmuting restores it. A volume key while muted also unmutes. A gain change ramps at a constant per-frame step (10 ms for a full-scale change), exact and continuous across buffers. - `ANYPS5_MUTE_ON_FOCUS_LOSS=1` mutes while the display window has no focus and restores on focus gained. Unset or `0` is today's behaviour. It never replaces the user's own mute. Only focus events of the display window count. An invalid value of either variable, including an empty one, stops the game with an error naming the variable. - At the default state (volume 100, not muted, focus not lost) the audio path is bypassed entirely: the title's own buffer pointer goes to SDL, with no copy and no multiply. A reopened port or a returned ramp is exactly at unity again. - Where it applies: `AudioOut.cpp` just before `SDL_QueueAudio` for every non-vibration port, and `AudioOut2Context.cpp` in `DeviceCallback` (the only place the main mix reaches the speakers). `libSceAudio3d` plays through `sceAudioOutOutput`, so it is covered. Not touched: the controller's sound card and haptics (vibration ports, the AudioOut2 pad device), and the microphone. - No on-screen indicator: feedback is the stderr line only. Commits (67): the pure state class and its steps, mute independence, focus, gain (each with its test), the ramp and the S16 and float gain with their tests, the bypass filter, the strict setting parsers and message wording, the shared state, one commit per playback hook, the three input controls (per action: key request, mapping action, default key, each with a test), the VideoOut wiring (settings at startup, hotkeys, focus events, first focus read), and docs per file (`ENVIRONMENT.md`, `INPUT_MAPPING.md` in three commits, `USAGE.md`). The input mapper's action list and defaults follow the native table (its source-contract test). Overlaps with open PRs (edits kept local, branched from `main`): #7499 (InputMapping.hpp/.cpp, PadInput.cpp, tests/InputMapping.cpp, INPUT_MAPPING.md), #11860 (input mapper and tests/InputMapping.cpp), #9154 (AudioOut.cpp, AudioOut2Context.cpp, VideoOut CMakeLists.txt, PadInput.cpp), #11049 and #11584 (libSceAudioOut/CMakeLists.txt), #12379 and #12536 (VideoOut, CMake and VulkanDevice areas; no code of theirs used). ### Tested Linux x86_64, GCC 12, throwaway archive build of this branch and of `main` (319621ba2e). No console, no title. - New tests, all passed: `audio_out_host_volume` (state machine, steps at 0 and 100, mute restore, focus transitions, gain, strict setting parsers, messages), `audio_out_host_gain` (S16 and float on mono, stereo and 8 channels: byte-for-byte bypass at unity, exact first sample and landing frame, up and down ramps, no step above the slope, a ramp split across buffers equal to one buffer, saturation, rounding, filter pointer and copy rules), `audio_out_host_volume_state` (shared state, env parsing, invalid values refused and named, concurrent readers), `pad_host_volume` (requests and focus events). `pad_keyboard_mouse` and `pad_input_mapping` gained cases for the three actions, their defaults, key repeat, mouse and wheel refusal, shared keys and unknown names. Input mapper: `node --test tests` 25 pass. - Existing audio, input and video-out tests, ctest `-R '^(audio_out|pad_|video_out_)'`: `main` 85 tests, 0 failed; this branch 89 tests, 0 failed. The per-test results are identical except for the four added tests (`pad_command_file` was not built in the first branch run and passed when built). - Video-out with a display: `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation xvfb-run -a ctest -R '^(video_out_|pad_)' -V` with `-DANYPS5_VIDEO_OUT_TEST_DRIVER=x11`: `main` 33/33 passed, branch 34/34 passed (the extra one is `pad_host_volume`). The validation layer was found in both runs and `VUID-` appears 0 times in both. - Negative controls: 51 mutations of the new code (step clamps, mute independence, focus rules, gain at default and its curve, parsers, bypass, ramp, saturation, rounding, per-frame gain, filter copy rules, state publishing, env names, window ID and event rules, request order, key repeat, keyboard-only rules, default keys) were applied in scratch copies. 50 fail at the intended assertion. The last one, accepting an empty level, is an equivalent mutant because `std::from_chars` already rejects an empty string. Two controls first passed (an upward ramp without a final snap, S16 truncation instead of rounding); tests were added and now catch them. Removing the bypass is not caught by the byte-for-byte S16 sample test, since unity is an identity; the filter's pointer and copy assertions catch it. - `check_conventions.py --base upstream/main`, `git diff --check`, the public-headers audit and `env_reference.py --check` are clean. Not run: Windows, macOS, a real audio device (the hooks themselves were reasoned, not heard), a real window system with a real SDL focus sequence (the hotkey wiring and focus events in `PadInput.cpp` are covered through the pure functions they call, not end to end), a hardware GPU, a console. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: llvmpipe (LLVM 15.0.6, 256 bits), Vulkan software rasterizer via Xvfb (x11 driver), Linux 6.1; no hardware GPU - [x] AI-assisted: yes
adriadam10 commented 2026-10-29 21:36:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-29T21:36:43Z.

Review: CHANGES_REQUESTED


The full Build's windows job fails on this head in pad_sdl (Exit code 0xc0000409, an abort() after 0.38 s, run 40951632982). I reran the failed jobs once and it failed the same way, so it is not a flake; main does not have this failure.

  • core/libs/prx/libSceVideoOut/CMakeLists.txt:26: libSceVideoOut now links libSceAudioOut, a second shared library that statically links its own SDL2 and libScePad. pad_sdl_tests (tests/PadSdl.cpp) drives PadInput with SDL virtual joysticks and aborts in one of its Require calls, so the new dependency, or the new PadInput code that runs inside that test (HostVolumeConfigureFromEnvironment_nid_no_patch in the constructor, the focus read in the first Update), changes what that test sees on Windows.
  • Please reproduce pad_sdl on Windows and find which Require aborts. One direction: keep libSceVideoOut from depending on libSceAudioOut (for example put the shared volume state somewhere both already link, such as libScePad) and check that pad_sdl passes again.

The other jobs on this head are green and the review of the rest (gain path, bypass, shared state, input actions, docs, tests) is unchanged.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5705302873 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12569#pullrequestreview-5705302873). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-29T21:36:43Z. **Review:** CHANGES_REQUESTED --- The full Build's `windows` job fails on this head in `pad_sdl` (`Exit code 0xc0000409`, an `abort()` after 0.38 s, run 40951632982). I reran the failed jobs once and it failed the same way, so it is not a flake; `main` does not have this failure. - `core/libs/prx/libSceVideoOut/CMakeLists.txt:26`: `libSceVideoOut` now links `libSceAudioOut`, a second shared library that statically links its own SDL2 and `libScePad`. `pad_sdl_tests` (`tests/PadSdl.cpp`) drives `PadInput` with SDL virtual joysticks and aborts in one of its `Require` calls, so the new dependency, or the new `PadInput` code that runs inside that test (`HostVolumeConfigureFromEnvironment_nid_no_patch` in the constructor, the focus read in the first `Update`), changes what that test sees on Windows. - Please reproduce `pad_sdl` on Windows and find which `Require` aborts. One direction: keep `libSceVideoOut` from depending on `libSceAudioOut` (for example put the shared volume state somewhere both already link, such as `libScePad`) and check that `pad_sdl` passes again. The other jobs on this head are green and the review of the rest (gain path, bypass, shared state, input actions, docs, tests) is unchanged.
adriadam10 commented 2026-10-29 22:13:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-29T22:13:44Z.

Review: CHANGES_REQUESTED


Thanks for the diagnostic commit. Checked the Windows log of run 40951632982 for pad_sdl: the abort() is raised from pad_sdl_tests.exe itself (pad_sdl_tests.exe+0x161bb2, i.e. a Require), not from libSceAudioOut or an uncaught exception, so the environment parsing is not the cause and one of the pad/slot assertions fails.

The head still has the same dependency (core/libs/prx/libSceVideoOut/CMakeLists.txt:26, libSceVideoOut linking libSceAudioOut), and pad_sdl still has to pass on Windows before this can merge. The Build run on c1d819b954 (run 40962672138) will print pad_sdl: check failed at line N; once it does, please fix that case, or, if it points at the new dependency, move the shared volume state so libSceVideoOut does not link a second shared library that carries its own libScePad/SDL copy. Nothing else in the review changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5705657322 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12569#pullrequestreview-5705657322). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-29T22:13:44Z. **Review:** CHANGES_REQUESTED --- Thanks for the diagnostic commit. Checked the Windows log of run 40951632982 for `pad_sdl`: the `abort()` is raised from `pad_sdl_tests.exe` itself (`pad_sdl_tests.exe+0x161bb2`, i.e. a `Require`), not from `libSceAudioOut` or an uncaught exception, so the environment parsing is not the cause and one of the pad/slot assertions fails. The head still has the same dependency (`core/libs/prx/libSceVideoOut/CMakeLists.txt:26`, `libSceVideoOut` linking `libSceAudioOut`), and `pad_sdl` still has to pass on Windows before this can merge. The Build run on `c1d819b954` (run 40962672138) will print `pad_sdl: check failed at line N`; once it does, please fix that case, or, if it points at the new dependency, move the shared volume state so `libSceVideoOut` does not link a second shared library that carries its own `libScePad`/SDL copy. Nothing else in the review changes.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!12569
No description provided.