audio: baseline the internal speaker at full volume on boot and hotplug
PortAudio has no volume control, so a muted ALSA Master silences the voice gateway's cue and replies, and the mixer resets whenever a sound device is added/removed. scripts/audio-baseline.sh sets the analog speaker (found by its 'Speaker' control, so a shifting card index does not matter) to 100% unmuted; scripts/audio-baseline-watch.sh re-applies it on every sound udev event. Both are driven by systemd user services (audio-baseline.service / -watch.service) so they run at startup and on hotplug.
This commit is contained in:
1 parent
ec39a990e4
commit
dcfe5e5fec
2 files changed
+46
No files matched your search
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
# Re-apply the audio baseline whenever a sound device is added, changed, or
|
||||
# removed, so the internal speaker stays at full volume and unmuted (the
|
||||
# baseline) after a USB mic, HDMI, or headset is plugged or unplugged.
|
||||
#
|
||||
# `udevadm monitor` is readable without root, so this runs as a long-lived
|
||||
# systemd user service (see `audio-baseline.service`); each sound event
|
||||
# triggers one idempotent apply of `audio-baseline.sh`.
|
||||
set -u
|
||||
|
||||
BASELINE="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)/audio-baseline.sh"
|
||||
|
||||
stdbuf -oL udevadm monitor --udev --subsystem-match=sound 2>/dev/null \
|
||||
| while IFS= read -r line; do
|
||||
# Event lines look like `UDEV [1696.123] add /devices/... (sound)`;
|
||||
# the `[` distinguishes them from the 3-line startup banner.
|
||||
case "$line" in
|
||||
UDEV*\[*) "$BASELINE" ;;
|
||||
esac
|
||||
done
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
# Restore the internal analog speaker to full volume, unmuted.
|
||||
#
|
||||
# PortAudio/ALSA has no volume control, so the voice gateway's cue beep and
|
||||
# spoken replies are silent when the card's Master is muted or at 0%. The mixer
|
||||
# also resets when a sound device is added or removed (e.g. a USB mic or HDMI
|
||||
# unplug), so this runs both at startup and on every hotplug event (see
|
||||
# `audio-baseline-watch.sh`).
|
||||
#
|
||||
# The card is identified by its 'Speaker' control (HDMI cards only expose
|
||||
# IEC958), so a shifting card index after a device change does not matter.
|
||||
# Idempotent and safe to run repeatedly; exits 0 when no card is present yet
|
||||
# (the watcher retries on the next hotplug event).
|
||||
set -u
|
||||
|
||||
for dir in /proc/asound/card*/; do
|
||||
[ -e "$dir" ] || continue
|
||||
idx=${dir#/proc/asound/card}
|
||||
idx=${idx%/}
|
||||
amixer -c "$idx" scontrols 2>/dev/null | grep -q "'Speaker'" || continue
|
||||
amixer -c "$idx" sset Master 100% unmute >/dev/null 2>&1 || true
|
||||
amixer -c "$idx" sset Speaker 100% unmute >/dev/null 2>&1 || true
|
||||
amixer -c "$idx" sset Headphone 100% unmute >/dev/null 2>&1 || true
|
||||
done
|
||||
|
||||
exit 0
|
||||
Reference in new issue
Block a user