Add per-laptop speaker tunings, starting with the XPS 14
Laptop speakers ship voiced by the vendor's Windows DSP layer, which Linux does not get. A tuning restores that as a PipeWire filter-chain in front of the internal speaker sink, matched to the machine by DMI string and expected sink. Adding a laptop is a directory under default/audio/tunings with two files and no new code: matching is data. The XPS 14 DA14260 tuning included here was derived by measuring the xps-audio-linux EasyEffects profile (MIT) and fitting a biquad chain to it, so no impulse response or other upstream asset is redistributed. It measures 1.24 dB RMS against that reference, and matches its dynamic range within 0.1 LU -- the reference's multiband compressor turned out to contribute nothing, so a linear chain replaces it. Bass Q is capped deliberately: a closer magnitude fit swung group delay 31 ms across 63-80 Hz, which smears bass transients. The graph runs as its own PipeWire client under its own config name rather than loading into the audio daemon. The daemon only reads its config at startup, so a daemon-loaded tuning could only be switched by restarting PipeWire -- which drops every PulseAudio client's connection, and applications that do not reconnect (Spotify) then have to be restarted by hand. Hosting it separately also contains failure, since a malformed tuning breaks only that service. Three things about the surrounding audio graph needed fixing for this to behave: - Volume must live downstream of the tuning. omarchy-audio-output-sink is now the single definition of which sink an output's volume really uses, shared by the volume keys, the output switcher's OSD and the audio panel, so they cannot disagree. It resolves the current default output, which keeps it correct when headphones are selected while a tuning exists. - The tuning's own output is a movable sink input, so rerouting "all streams" to a newly selected output would drag the processing onto headphones, or into the tuning's own sink, which is a cycle. It is pinned, and stream moves are limited to streams carrying an application.name. - The physical sink a tuning fronts is not independently selectable, since picking it would only bypass the tuning, so it is kept out of the output list. Applying happens at first-run, not finalize-user, because finalize-user also runs in the ISO chroot where there is no audio server and nothing would retry. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
248659de5a
commit
aa9f0c54c5
@@ -15,6 +15,17 @@ fi
|
||||
timeout 2 wpctl set-default "$node_id" 2>/dev/null || true
|
||||
timeout 2 pactl set-default-sink "$sink_name" 2>/dev/null || true
|
||||
|
||||
timeout 2 pactl list short sink-inputs 2>/dev/null | awk '{ print $1 }' | while read -r input; do
|
||||
# Move only real application streams. A DSP filter-chain's own output is also a
|
||||
# sink input but carries no application.name, and moving it would rewire the
|
||||
# processing itself -- onto headphones, or into its own virtual sink, which is a
|
||||
# cycle. EasyEffects' output stream must stay put for the same reason.
|
||||
timeout 2 pactl list sink-inputs 2>/dev/null | awk '
|
||||
/^Sink Input #/ {id = substr($3, 2)}
|
||||
/application\.name = / {
|
||||
app = $0
|
||||
sub(/.*application\.name = "/, "", app)
|
||||
sub(/"$/, "", app)
|
||||
if (app != "EasyEffects") print id
|
||||
}' | while read -r input; do
|
||||
[[ -n $input ]] && timeout 2 pactl move-sink-input "$input" "$sink_name" 2>/dev/null || true
|
||||
done
|
||||
|
||||
Executable
+55
@@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
|
||||
# omarchy:summary=Print the sink whose volume and mute a given output really uses
|
||||
# omarchy:args=[sink-name]
|
||||
# omarchy:group=audio
|
||||
# omarchy:examples=omarchy audio output sink | omarchy audio output sink omarchy_speaker_tuning
|
||||
|
||||
set -uo pipefail
|
||||
|
||||
# A DSP sink -- a speaker tuning filter-chain, or EasyEffects -- can be the
|
||||
# selected output without being where loudness lives. Changing its volume alters
|
||||
# the level going *into* the processing: the display moves while the speakers do
|
||||
# not, and on a chain with a compressor or limiter the tone changes too. Resolve
|
||||
# through it to the physical sink it feeds.
|
||||
#
|
||||
# With no argument this resolves the current default output, so when headphones or
|
||||
# HDMI are selected it returns those, not the speakers a tuning happens to front.
|
||||
# Callers that need to describe some *other* output -- an output switcher naming
|
||||
# the next one in the rotation -- pass that sink explicitly.
|
||||
|
||||
sink="${1:-$(pactl get-default-sink 2>/dev/null)}"
|
||||
|
||||
if [[ -z $sink || $sink == alsa_output.* ]]; then
|
||||
printf '%s\n' "$sink"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# A DSP sink feeds its physical output through a stream of its own; follow that
|
||||
# stream down to the sink underneath.
|
||||
downstream="$(pactl list sink-inputs 2>/dev/null |
|
||||
awk -v virt="$sink" '
|
||||
/^Sink Input #/ {target = ""}
|
||||
/^[[:space:]]*Sink:/ {target = $2}
|
||||
/node\.name = / {
|
||||
name = $0
|
||||
sub(/.*node\.name = "/, "", name)
|
||||
sub(/"$/, "", name)
|
||||
if (index(name, virt) == 1 && target != "") {print target; exit}
|
||||
}
|
||||
/application\.name = "EasyEffects"/ {
|
||||
if (virt == "easyeffects_sink" && target != "") {print target; exit}
|
||||
}')"
|
||||
|
||||
if [[ -n $downstream ]]; then
|
||||
name="$(pactl list sinks short 2>/dev/null |
|
||||
awk -v id="$downstream" '$1 == id {print $2; exit}')"
|
||||
if [[ -n $name ]]; then
|
||||
printf '%s\n' "$name"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Nothing resolvable downstream -- the DSP sink may simply be idle and unlinked.
|
||||
# Fall back to the sink itself so callers still have something to act on.
|
||||
printf '%s\n' "$sink"
|
||||
@@ -2,7 +2,14 @@
|
||||
|
||||
# omarchy:summary=Switch between audio outputs while preserving the mute status
|
||||
|
||||
sinks=$(timeout 2 pactl -f json list sinks | jq '[.[] | select((.ports | length == 0) or ([.ports[]? | .availability != "not available"] | any))]')
|
||||
# Skip the physical sink an active speaker tuning fronts: rotating onto it would
|
||||
# silently bypass the tuning rather than pick a different output.
|
||||
fronted=$(omarchy-audio-tuning fronted-sink 2>/dev/null || true)
|
||||
|
||||
sinks=$(timeout 2 pactl -f json list sinks |
|
||||
jq --arg fronted "$fronted" '[.[]
|
||||
| select((.ports | length == 0) or ([.ports[]? | .availability != "not available"] | any))
|
||||
| select($fronted == "" or .name != $fronted)]')
|
||||
sinks_count=$(jq 'length' <<<"$sinks")
|
||||
|
||||
if (( sinks_count == 0 )); then
|
||||
@@ -22,8 +29,18 @@ fi
|
||||
next_sink=$(jq -c ".[$next_sink_index]" <<<"$sinks")
|
||||
next_sink_name=$(jq -r '.name' <<<"$next_sink")
|
||||
next_sink_description=$(jq -r '.description // .properties."device.description" // .name' <<<"$next_sink")
|
||||
next_sink_volume=$(jq -r '.volume | to_entries[0].value.value_percent | sub("%"; "") | tonumber' <<<"$next_sink")
|
||||
next_sink_is_muted=$(jq -r '.mute' <<<"$next_sink")
|
||||
# A tuning sink sits at a fixed 100% and unmuted while real loudness lives on the
|
||||
# physical sink beneath it, so read the level from whichever sink actually carries
|
||||
# it or the OSD contradicts the volume keys.
|
||||
next_sink_effective=$(omarchy-audio-output-sink "$next_sink_name")
|
||||
next_sink_volume=$(timeout 2 pactl get-sink-volume "$next_sink_effective" 2>/dev/null |
|
||||
awk 'NR == 1 {for (i = 1; i <= NF; i++) if ($i ~ /%$/) {sub("%", "", $i); print $i; exit}}')
|
||||
[[ -n $next_sink_volume ]] || next_sink_volume=$(jq -r '.volume | to_entries[0].value.value_percent | sub("%"; "") | tonumber' <<<"$next_sink")
|
||||
if [[ $(timeout 2 pactl get-sink-mute "$next_sink_effective" 2>/dev/null) == *yes ]]; then
|
||||
next_sink_is_muted=true
|
||||
else
|
||||
next_sink_is_muted=false
|
||||
fi
|
||||
|
||||
if [[ $next_sink_is_muted == "true" ]] || (( next_sink_volume == 0 )); then
|
||||
icon_state="muted"
|
||||
|
||||
@@ -11,20 +11,27 @@ if [[ -z $action ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
volume_state() {
|
||||
wpctl get-volume @DEFAULT_AUDIO_SINK@
|
||||
}
|
||||
# Resolve through any DSP sink to the physical one, so the keys always move real
|
||||
# loudness and the processing always sees full-scale input. Shared with the audio
|
||||
# panel and the output switcher.
|
||||
sink="$(omarchy-audio-output-sink)"
|
||||
if [[ -z $sink ]]; then
|
||||
echo "Could not resolve an audio sink to control." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# pactl reports the same percentage scale wpctl does (both are the raw volume
|
||||
# over PA_VOLUME_NORM), so the OSD reads identically either way.
|
||||
volume_percent() {
|
||||
volume_state | awk '{ for (i=1; i<=NF; i++) if ($i ~ /^[0-9.]+$/) print int($i * 100) }'
|
||||
pactl get-sink-volume "$sink" 2>/dev/null |
|
||||
awk 'NR == 1 {
|
||||
for (i = 1; i <= NF; i++)
|
||||
if ($i ~ /%$/) {sub("%", "", $i); print $i; exit}
|
||||
}'
|
||||
}
|
||||
|
||||
volume_muted() {
|
||||
volume_state | grep -q MUTED
|
||||
}
|
||||
|
||||
unmute_output() {
|
||||
wpctl set-mute @DEFAULT_AUDIO_SINK@ 0 >/dev/null
|
||||
[[ $(pactl get-sink-mute "$sink" 2>/dev/null) == *yes ]]
|
||||
}
|
||||
|
||||
case "$action" in
|
||||
@@ -37,31 +44,43 @@ if [[ $action == "mute-toggle" ]]; then
|
||||
debounce_file="$runtime_dir/omarchy-audio-output-volume-mute-toggle.last"
|
||||
now=$(date +%s%3N)
|
||||
last=0
|
||||
[[ -r $debounce_file ]] && read -r last < "$debounce_file" || true
|
||||
if (( now - last < 250 )); then
|
||||
[[ -r $debounce_file ]] && read -r last <"$debounce_file" || true
|
||||
if ((now - last < 250)); then
|
||||
exit 0
|
||||
fi
|
||||
printf '%s\n' "$now" > "$debounce_file"
|
||||
printf '%s\n' "$now" >"$debounce_file"
|
||||
|
||||
wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle >/dev/null
|
||||
elif [[ $action == +* ]]; then
|
||||
step="${action#+}"
|
||||
unmute_output
|
||||
wpctl set-volume -l 1.0 @DEFAULT_AUDIO_SINK@ "${step}%+"
|
||||
elif [[ $action == -* ]]; then
|
||||
step="${action#-}"
|
||||
unmute_output
|
||||
wpctl set-volume @DEFAULT_AUDIO_SINK@ "${step}%-"
|
||||
pactl set-sink-mute "$sink" toggle
|
||||
elif [[ $action =~ ^([+-])([0-9]+)$ ]]; then
|
||||
direction="${BASH_REMATCH[1]}"
|
||||
step="${BASH_REMATCH[2]}"
|
||||
|
||||
current="$(volume_percent)"
|
||||
if [[ -z $current ]]; then
|
||||
echo "Could not read volume for $sink." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $direction == "+" ]]; then
|
||||
next=$((current + step))
|
||||
((next <= 100)) || next=100
|
||||
else
|
||||
next=$((current - step))
|
||||
((next >= 0)) || next=0
|
||||
fi
|
||||
|
||||
pactl set-sink-mute "$sink" 0
|
||||
pactl set-sink-volume "$sink" "${next}%"
|
||||
else
|
||||
echo "Unknown volume action: $action"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
percent=$(volume_percent)
|
||||
if volume_muted || (( percent == 0 )); then
|
||||
if volume_muted || ((${percent:-0} == 0)); then
|
||||
icon="volume-muted"
|
||||
else
|
||||
icon="volume-high"
|
||||
fi
|
||||
|
||||
omarchy-osd -i "$icon" -p "$percent"
|
||||
omarchy-osd -i "$icon" -p "${percent:-0}"
|
||||
|
||||
@@ -3,9 +3,18 @@
|
||||
# omarchy:summary=Print PulseAudio sink availability for the shell
|
||||
# omarchy:group=audio
|
||||
|
||||
pactl list sinks 2>/dev/null | awk '
|
||||
# A speaker tuning is a virtual sink in front of the real speakers. Both exist
|
||||
# in the graph, but selecting the physical one would only bypass the tuning, so
|
||||
# report it unavailable and keep it out of the output list.
|
||||
fronted="$(omarchy-audio-tuning fronted-sink 2>/dev/null || true)"
|
||||
|
||||
pactl list sinks 2>/dev/null | awk -v fronted="$fronted" '
|
||||
function emit_sink() {
|
||||
if (name == "") return
|
||||
if (fronted != "" && name == fronted) {
|
||||
print name "\t0"
|
||||
return
|
||||
}
|
||||
print name "\t" ((port_count == 0 || available) ? 1 : 0)
|
||||
}
|
||||
|
||||
|
||||
Executable
+329
@@ -0,0 +1,329 @@
|
||||
#!/bin/bash
|
||||
|
||||
# omarchy:summary=Manage the speaker tuning for this laptop
|
||||
# omarchy:args=<on|off|status|match|fronted-sink> [--force]
|
||||
# omarchy:group=audio
|
||||
# omarchy:examples=omarchy audio tuning status | omarchy audio tuning on | omarchy audio tuning off
|
||||
|
||||
set -uo pipefail
|
||||
|
||||
tunings_dir="$OMARCHY_PATH/default/audio/tunings"
|
||||
config_home="${XDG_CONFIG_HOME:-$HOME/.config}"
|
||||
|
||||
# The tuning is hosted by its own PipeWire client, under its own config name, so
|
||||
# switching it needs no audio restart -- a restart drops every PulseAudio client's
|
||||
# connection, and applications that do not reconnect (Spotify) then have to be
|
||||
# restarted by hand. The name is deliberately not PipeWire's stock
|
||||
# filter-chain.conf, which merges every fragment in filter-chain.conf.d/ and would
|
||||
# make this service host unrelated user filters too.
|
||||
host_config_name=omarchy-speaker-tuning.conf
|
||||
host_config="$config_home/pipewire/$host_config_name"
|
||||
host_source="$OMARCHY_PATH/default/audio/filter-chain-host.conf"
|
||||
fragment="$config_home/pipewire/$host_config_name.d/90-tuning.conf"
|
||||
unit_name=omarchy-speaker-tuning.service
|
||||
unit="$config_home/systemd/user/$unit_name"
|
||||
unit_source="$OMARCHY_PATH/default/systemd/user/$unit_name"
|
||||
|
||||
# Earlier revisions loaded the tuning into the daemon, as a WirePlumber smart
|
||||
# filter, or into the shared filter-chain.conf.d namespace. Remove all three so
|
||||
# they cannot be loaded alongside the current one.
|
||||
stale_daemon="$config_home/pipewire/pipewire.conf.d/90-omarchy-speaker-tuning.conf"
|
||||
stale_wireplumber="$config_home/wireplumber/wireplumber.conf.d/90-omarchy-speaker-tuning.conf"
|
||||
stale_shared="$config_home/pipewire/filter-chain.conf.d/90-omarchy-speaker-tuning.conf"
|
||||
|
||||
sink_name=omarchy_speaker_tuning
|
||||
|
||||
action="${1:-status}"
|
||||
force=0
|
||||
[[ ${2:-} == "--force" ]] && force=1
|
||||
|
||||
sink_matching() {
|
||||
pactl list sinks short 2>/dev/null | awk -v p="$1" '$2 ~ p {print $2; exit}'
|
||||
}
|
||||
|
||||
# Print the tuning directory matching this laptop, if any. Matching is data, not
|
||||
# code: a tuning declares the DMI string it belongs to and the sink it expects, so
|
||||
# most tunings can be added as a directory with no new script. A tuning whose
|
||||
# hardware needs a sharper test can set match_command to any predicate instead.
|
||||
tuning_match() {
|
||||
local dir
|
||||
for dir in "$tunings_dir"/*/; do
|
||||
[[ -r $dir/tuning.conf ]] || continue
|
||||
|
||||
unset match_dmi match_command sink_pattern
|
||||
# shellcheck disable=SC1090
|
||||
source "$dir/tuning.conf"
|
||||
|
||||
# Deliberately does not look at the live audio graph. The install hooks run in
|
||||
# the ISO chroot with no audio server, and a match that depended on a present
|
||||
# sink would come back empty there -- so the machine would get neither the LV2
|
||||
# dependency nor the tuning, and nothing would retry.
|
||||
if [[ -n ${match_command:-} ]]; then
|
||||
"$match_command" 2>/dev/null || continue
|
||||
else
|
||||
[[ -n ${match_dmi:-} ]] || continue
|
||||
omarchy-hw-match "$match_dmi" 2>/dev/null || continue
|
||||
fi
|
||||
|
||||
# Required whichever way the tuning matched: the graph's target sink is
|
||||
# substituted from it, so a tuning without one cannot be installed and must
|
||||
# not be reported as a match.
|
||||
[[ -n ${sink_pattern:-} ]] || continue
|
||||
|
||||
printf '%s\n' "${dir%/}"
|
||||
return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# The physical sink the matched tuning is built for, taken from the tuning's own
|
||||
# sink_pattern rather than a hard-coded regex, so hardware with a different sink
|
||||
# name needs no change here.
|
||||
tuned_hardware_sink() {
|
||||
local dir found
|
||||
dir="$(tuning_match)" || return 1
|
||||
unset sink_pattern
|
||||
# shellcheck disable=SC1090
|
||||
source "$dir/tuning.conf"
|
||||
[[ -n ${sink_pattern:-} ]] || return 1
|
||||
found="$(sink_matching "$sink_pattern")"
|
||||
[[ -n $found ]] || return 1
|
||||
printf '%s\n' "$found"
|
||||
}
|
||||
|
||||
tuning_present() {
|
||||
pactl list sinks short 2>/dev/null | awk '{print $2}' | grep -qx "$sink_name"
|
||||
}
|
||||
|
||||
# Only real application streams may be moved. A filter-chain's own output is also
|
||||
# a sink input but carries no application.name, and moving it would rewire the
|
||||
# tuning itself.
|
||||
app_streams() {
|
||||
pactl list sink-inputs 2>/dev/null | awk '
|
||||
/^Sink Input #/ {id = substr($3, 2)}
|
||||
/application\.name = / {
|
||||
app = $0
|
||||
sub(/.*application\.name = "/, "", app)
|
||||
sub(/"$/, "", app)
|
||||
if (app != "EasyEffects") print id
|
||||
}'
|
||||
}
|
||||
|
||||
move_apps_to() {
|
||||
local target="$1" id
|
||||
for id in $(app_streams); do
|
||||
pactl move-sink-input "$id" "$target" 2>/dev/null || true
|
||||
done
|
||||
}
|
||||
|
||||
# WirePlumber can link the output elsewhere if the target is missing when the host
|
||||
# starts. node.dont-fallback guards against it, but verify rather than assume.
|
||||
tuning_downstream_sink() {
|
||||
omarchy-audio-output-sink "$sink_name" 2>/dev/null
|
||||
}
|
||||
|
||||
easyeffects_running() {
|
||||
pactl list sinks short 2>/dev/null | awk '{print $2}' | grep -qx easyeffects_sink ||
|
||||
pgrep -u "$(id -u)" -x easyeffects >/dev/null 2>&1 ||
|
||||
systemctl --user is-active --quiet easyeffects.service 2>/dev/null
|
||||
}
|
||||
|
||||
# Unloading a daemon-loaded drop-in is the one case that still needs an audio
|
||||
# restart, because the daemon only reads its own config at startup.
|
||||
drop_stale_daemon_config() {
|
||||
[[ -e $stale_daemon || -e $stale_wireplumber ]] || return 0
|
||||
rm -f "$stale_daemon" "$stale_wireplumber"
|
||||
omarchy-restart-audio >/dev/null 2>&1
|
||||
local _
|
||||
for _ in {1..40}; do
|
||||
pactl info >/dev/null 2>&1 && break
|
||||
sleep 0.25
|
||||
done
|
||||
}
|
||||
|
||||
case "$action" in
|
||||
match)
|
||||
tuning_match
|
||||
;;
|
||||
|
||||
fronted-sink)
|
||||
# The tuning is a virtual sink in front of the real speakers, so both exist in
|
||||
# the graph. Selecting the physical one would only bypass the tuning, so
|
||||
# callers keep it out of the output list while the tuning is up. This answers
|
||||
# "is a tuning in place", not "where should volume go" -- for the latter see
|
||||
# omarchy-audio-output-sink, which follows the current default output.
|
||||
tuning_present || exit 1
|
||||
tuned_hardware_sink
|
||||
;;
|
||||
|
||||
status)
|
||||
if [[ -r $fragment ]]; then
|
||||
echo "Installed: yes ($fragment)"
|
||||
else
|
||||
echo "Installed: no"
|
||||
fi
|
||||
# Both is-active and is-enabled print their answer *and* exit non-zero when
|
||||
# negative, so a "|| echo" fallback prints it twice.
|
||||
host_state="$(systemctl --user is-active "$unit_name" 2>/dev/null)"
|
||||
host_enabled="$(systemctl --user is-enabled "$unit_name" 2>/dev/null)"
|
||||
echo "Host service: ${host_state:-inactive} (${host_enabled:-disabled})"
|
||||
if tuning_present; then
|
||||
echo "Tuning sink: present"
|
||||
else
|
||||
echo "Tuning sink: absent"
|
||||
fi
|
||||
echo "Default sink: $(pactl get-default-sink 2>/dev/null)"
|
||||
if dir="$(tuning_match)"; then
|
||||
unset description
|
||||
# shellcheck disable=SC1090
|
||||
source "$dir/tuning.conf"
|
||||
echo "Matches: ${description:-?} ($(basename "$dir"))"
|
||||
else
|
||||
echo "Matches: nothing ships for this laptop"
|
||||
fi
|
||||
;;
|
||||
|
||||
off)
|
||||
if [[ ! -r $fragment && ! -r $unit && ! -r $stale_daemon && ! -r $stale_wireplumber &&
|
||||
! -r $stale_shared ]]; then
|
||||
echo "No speaker tuning installed."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
speakers="$(tuned_hardware_sink)" || speakers=""
|
||||
|
||||
systemctl --user disable --now "$unit_name" >/dev/null 2>&1
|
||||
rm -f "$fragment" "$host_config" "$unit" "$stale_shared"
|
||||
rmdir "$config_home/pipewire/$host_config_name.d" 2>/dev/null
|
||||
systemctl --user daemon-reload >/dev/null 2>&1
|
||||
drop_stale_daemon_config
|
||||
|
||||
for _ in {1..20}; do
|
||||
tuning_present || break
|
||||
sleep 0.25
|
||||
done
|
||||
|
||||
if [[ -n $speakers ]]; then
|
||||
pactl set-default-sink "$speakers" >/dev/null 2>&1
|
||||
# Streams left on the vanished tuning sink reconnect wherever PipeWire puts
|
||||
# them, which is not necessarily the speakers.
|
||||
move_apps_to "$speakers"
|
||||
fi
|
||||
echo "Speaker tuning removed."
|
||||
;;
|
||||
|
||||
on)
|
||||
[[ -d $tunings_dir ]] || {
|
||||
echo "No tunings shipped at $tunings_dir" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
selected="$(tuning_match)" || {
|
||||
echo "No speaker tuning matches this laptop."
|
||||
exit 0
|
||||
}
|
||||
|
||||
unset description sink_pattern
|
||||
# shellcheck disable=SC1090
|
||||
source "$selected/tuning.conf"
|
||||
|
||||
# At first-run the session is up but the sink can still be settling.
|
||||
for _ in {1..20}; do
|
||||
speaker_sink="$(sink_matching "$sink_pattern")"
|
||||
[[ -n $speaker_sink ]] && break
|
||||
sleep 0.5
|
||||
done
|
||||
[[ -n ${speaker_sink:-} ]] || {
|
||||
echo "A tuning applies to this laptop but no sink matching $sink_pattern" >&2
|
||||
echo "is present, so there is no audio server yet. Re-run after login:" >&2
|
||||
echo " omarchy audio tuning on" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
if easyeffects_running; then
|
||||
cat >&2 <<'EOF'
|
||||
EasyEffects is running. It moves any stream that follows the default sink to its
|
||||
own sink, so a tuning installed now would be bypassed.
|
||||
|
||||
Stop it first: systemctl --user disable --now easyeffects.service
|
||||
EOF
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Every tuning ends in a limiter, which is an LV2 plugin. Without it the graph
|
||||
# fails to instantiate and the tuning sink never appears.
|
||||
ls /usr/lib/lv2/lsp-plugins.lv2/limiter_stereo.ttl >/dev/null 2>&1 || {
|
||||
echo "lsp-plugins-lv2 is required for the tuning limiter." >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
rendered="$(mktemp)"
|
||||
trap 'rm -f "$rendered"' EXIT
|
||||
sed "s|@SPEAKER_SINK@|$speaker_sink|g" "$selected/filter-chain.conf" >"$rendered"
|
||||
|
||||
# Everything that makes the tuning current has to match, not just the graph:
|
||||
# an active-but-disabled service disappears at next login, and a stale unit
|
||||
# file would shadow later fixes to the shipped one indefinitely.
|
||||
if ((!force)) && [[ -r $fragment ]] && cmp -s "$rendered" "$fragment" &&
|
||||
[[ -r $host_config ]] && cmp -s "$host_source" "$host_config" &&
|
||||
[[ -r $unit ]] && cmp -s "$unit_source" "$unit" &&
|
||||
systemctl --user is-active --quiet "$unit_name" 2>/dev/null &&
|
||||
systemctl --user is-enabled --quiet "$unit_name" 2>/dev/null &&
|
||||
[[ "$(tuning_downstream_sink)" == "$speaker_sink" ]]; then
|
||||
echo "Speaker tuning already current: $description"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
drop_stale_daemon_config
|
||||
|
||||
rm -f "$stale_shared"
|
||||
install -Dm644 "$host_source" "$host_config"
|
||||
install -Dm644 "$rendered" "$fragment"
|
||||
install -Dm644 "$unit_source" "$unit"
|
||||
systemctl --user daemon-reload >/dev/null 2>&1
|
||||
systemctl --user enable "$unit_name" >/dev/null 2>&1
|
||||
systemctl --user restart "$unit_name" >/dev/null 2>&1
|
||||
echo "Installed speaker tuning: $description"
|
||||
|
||||
for _ in {1..40}; do
|
||||
tuning_present && break
|
||||
sleep 0.25
|
||||
done
|
||||
if ! tuning_present; then
|
||||
systemctl --user disable --now "$unit_name" >/dev/null 2>&1
|
||||
rm -f "$fragment" "$host_config" "$unit"
|
||||
systemctl --user daemon-reload >/dev/null 2>&1
|
||||
echo "Tuning sink never appeared, so it was removed. Audio is untouched." >&2
|
||||
echo "Check: systemctl --user status $unit_name" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Confirm the output really landed on the sink this tuning was measured for.
|
||||
for _ in {1..20}; do
|
||||
[[ "$(tuning_downstream_sink)" == "$speaker_sink" ]] && break
|
||||
sleep 0.25
|
||||
done
|
||||
downstream="$(tuning_downstream_sink)"
|
||||
if [[ $downstream != "$speaker_sink" ]]; then
|
||||
systemctl --user disable --now "$unit_name" >/dev/null 2>&1
|
||||
rm -f "$fragment" "$host_config" "$unit"
|
||||
systemctl --user daemon-reload >/dev/null 2>&1
|
||||
echo "The tuning output linked to ${downstream:-nothing} instead of" >&2
|
||||
echo "$speaker_sink, so it was removed rather than left tuning the wrong" >&2
|
||||
echo "device. Audio is untouched." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
pactl set-default-sink "$sink_name" >/dev/null 2>&1
|
||||
# A default sink only captures newly created streams, so anything already
|
||||
# playing would keep bypassing the tuning until its app was restarted.
|
||||
move_apps_to "$sink_name"
|
||||
|
||||
echo "Speakers now play through the tuning."
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Usage: omarchy-audio-tuning <on|off|status|match|fronted-sink> [--force]" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
@@ -115,6 +115,8 @@ run_first_run_step "set GNOME theme" \
|
||||
bash "$OMARCHY_PATH/install/user/first-run/gnome-theme.sh"
|
||||
run_first_run_step "set GTK primary paste" \
|
||||
bash "$OMARCHY_PATH/install/user/first-run/gtk-primary-paste.sh"
|
||||
run_first_run_step "apply speaker tuning" \
|
||||
bash "$OMARCHY_PATH/install/user/first-run/audio-tuning.sh"
|
||||
|
||||
wait_for_notifications
|
||||
run_first_run_step "show welcome notification" \
|
||||
|
||||
Reference in New Issue
Block a user