fix pinning of 5.1 channel

This commit is contained in:
scootz 2026-05-02 14:35:25 +01:00
parent 6fd0802239
commit 07e1fd0aa5
2 changed files with 58 additions and 4 deletions

View file

@ -40,6 +40,8 @@ After Arma has created its audio stream, restore your normal default device:
reforger-surround restore
```
`restore` first pins the running Arma stream to the 5.1 sink, then switches normal system audio back to the previous default device.
Check whether Arma negotiated surround:
```bash
@ -57,7 +59,8 @@ reforger-surround down
```bash
reforger-surround create # create the 5.1 sink without changing defaults
reforger-surround up # create the sink, save current default, make 5.1 default
reforger-surround restore # restore the saved previous default, keep 5.1 sink alive
reforger-surround pin # move a running Arma/Reforger stream to the 5.1 sink
reforger-surround restore # pin Reforger if running, then restore the saved previous default
reforger-surround down # restore previous default and unload the 5.1 sink
reforger-surround status # show sink/default/game stream state
reforger-surround check # report whether Arma is 2ch or 6ch
@ -100,6 +103,7 @@ If Arma creates a stereo-only stream, restart the game with the 5.1 sink selecte
## Notes
- `up` temporarily routes normal system audio to the 5.1 sink until `restore` is run.
- `restore` does not unload the 5.1 sink; it only gives normal system audio back to the previous default.
- `restore` does not unload the 5.1 sink; it pins Reforger if running, then gives normal system audio back to the previous default.
- If Reforger follows the default sink when the default changes, run `reforger-surround pin` before switching devices manually.
- `down` unloads the temporary sink created by this tool.
- LFE may be silent in Arma Reforger even when the stream is 6ch.

View file

@ -14,6 +14,7 @@ usage() {
Usage:
reforger-surround create
reforger-surround up
reforger-surround pin
reforger-surround restore
reforger-surround down
reforger-surround status
@ -22,7 +23,8 @@ Usage:
Commands:
create Create the temporary 5.1 sink without changing the default sink.
up Create the 5.1 sink, save the current default, and make it default.
restore Restore the saved previous default sink, leaving the 5.1 sink alive.
pin Move a running Reforger stream to the 5.1 sink.
restore Pin Reforger if running, then restore the saved previous default sink.
down Restore the saved previous default sink and unload the 5.1 sink.
status Show default sink, virtual sink state, and detected Reforger stream.
check Report whether a running Reforger stream negotiated stereo or surround.
@ -137,6 +139,44 @@ Launch Arma Reforger now. After the game has created its audio stream, run:
EOF
}
move_app_to_sink() {
local input_id sample_spec
input_id="$(find_app_sink_input_id || true)"
if [[ -z "${input_id}" ]]; then
printf 'No running sink-input found for application.name="%s".\n' "${app_name}" >&2
return 1
fi
create_sink
sample_spec="$(app_stream_sample_spec "${input_id}")"
pactl move-sink-input "${input_id}" "${sink_name}"
printf 'Pinned %s sink-input #%s to %s\n' "${app_name}" "${input_id}" "${sink_name}"
case "${sample_spec}" in
*" 6ch "*)
printf 'Stream is 6ch; restoring the system default should leave Reforger on the 5.1 sink.\n'
;;
*" 2ch "*)
printf 'Warning: stream is already stereo-only. Pinning will not make Reforger renegotiate surround.\n' >&2
;;
*)
printf 'Warning: unknown stream channel count; run reforger-surround check.\n' >&2
;;
esac
}
pin_app_if_running() {
local input_id
input_id="$(find_app_sink_input_id || true)"
if [[ -n "${input_id}" ]]; then
move_app_to_sink
else
printf 'No %s stream found to pin; restoring only the system default.\n' "${app_name}"
fi
}
restore_default() {
local restore_sink
restore_sink="$(sed -n '1p' "${previous_default_sink_file}" 2>/dev/null || true)"
@ -155,6 +195,11 @@ restore_default() {
printf 'Restored default sink: %s\n' "${restore_sink}"
}
restore_with_pin() {
pin_app_if_running
restore_default
}
unload_sink() {
local module_id
module_id="$(find_module_id || true)"
@ -339,10 +384,15 @@ main() {
require_pulse_connection
up
;;
pin)
ensure_dependencies
require_pulse_connection
move_app_to_sink
;;
restore)
ensure_dependencies
require_pulse_connection
restore_default
restore_with_pin
;;
down)
ensure_dependencies