Skip to content

Fix -w volume script: shared helper, correct dB mapping, skip on power-off#1

Merged
mr-manuel merged 1 commit into
mr-manuel:masterfrom
patapovich:fix-volume-script-w-option-mrmanuel
May 6, 2026
Merged

Fix -w volume script: shared helper, correct dB mapping, skip on power-off#1
mr-manuel merged 1 commit into
mr-manuel:masterfrom
patapovich:fix-volume-script-w-option-mrmanuel

Conversation

@patapovich

Copy link
Copy Markdown

Following up on your comment in ralph-irving#258.

This fixes three issues in the current -w implementation and refactors the code to avoid duplication across backends.

Changes

Shared helper in output.c — replaces the ~40-line inline block copy-pasted into output_alsa.c and output_pa.c with a single call_volume_script() function. All three backends (ALSA, PortAudio, PulseAudio) call it with one line.

Correct dB floor — the hardcoded dB_min = -49.510895 caused vol=0 for any LMS volume at or below ~16%, as reported by allmazz in the PR comments. The fix mirrors the floor that ALSA's own mixer path uses: MINVOL_DB = 72, giving a -72..0 dB range mapped linearly to 0-100.

Skip script on power-offcall_volume_script() returns immediately when output.state == OUTPUT_OFF. This prevents LMS's fade-to-off AUDG sequence from reaching the script and muting external hardware (e.g. a miniDSP whose master gain affects all inputs including sources other than squeezelite).

Consistent async on all backends — PulseAudio previously ran the script synchronously (blocking the audio thread). Now all POSIX backends launch with &; Windows uses start /B.

Man page-w documented in doc/squeezelite.1.

Adds a -w <script> option that invokes an executable script whenever LMS
sends a volume command (AUDG packet).  The script receives a single integer
argument 0-100 mapped from the LMS dB range (-72..0 dB) using the same
linear scale that the ALSA mixer path already uses.  When -w is active the
internal software gain is held at unity (FIXED_ONE) so the script has full
control over output level.

The shared helper call_volume_script() is placed in output.c (always
compiled) to avoid duplicating the mapping arithmetic across the ALSA,
PortAudio and PulseAudio backends.  On POSIX the script is launched
asynchronously via a shell "&" so the audio thread is not blocked; on
Windows "start /B" is used instead.

-w is mutually exclusive with -V (ALSA hardware volume control).
@mr-manuel mr-manuel merged commit 7334a66 into mr-manuel:master May 6, 2026
@mr-manuel

Copy link
Copy Markdown
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants