Skip to content

Own Apple speaker safety and fix the silent mic mapping in omarchy-mac - #535

Merged
maralcbr merged 11 commits into
quattro-upstreamfrom
mac/37-audio
Sep 25, 2026
Merged

maralcbr merged 11 commits into
quattro-upstreamfrom
mac/37-audio

Conversation

@maralcbr

Copy link
Copy Markdown
Member

Ticket 37 (audio safety and microphone), stacked on #514 (mac/13-hw-platform). Covers gap-audit rows A1–A3 and Q1, and retargets #462 and #502 from quattro.

What changed

  • speakersafetyd has one enabler: omarchy-mac. The package ships 80-omarchy-mac-audio.preset, and omarchy-mac-setup-system applies it once speakersafetyd is installed. /etc presets, masks and later explicit disables win. A live run restarts a daemon a start-limit left dead, which the desktop leaf used to do. install/hardware/apple/audio.sh no longer enables anything: it installs the stack and calls omarchy-setup-mac --system.
  • alsa-ucm-conf-asahi joins the stack the desktop leaf installs (mx-mac fix: preserve arguments in focus launch wrappers #239: without it there is no speaker path, and speakersafetyd keeps the amps locked).
  • Speaker pop: mx-mac's WirePlumber no-suspend policy is now a vendor drop-in in omarchy-mac, so the amplifiers stay powered between streams. User setup retires exact per-user copies from either mx-mac revision.
  • Mic mapping (omarchy-audio-asahi-mic-map switches the default source to a silent omarchy_asahi_mic.monitor (J314s) #505): the mapper used to make its stereo monitor the default source once the links existed, even when the monitor carried only digital silence. It now takes a brief float sample of the monitor with parec first.
    • Only a monitor with signal becomes the default, and a silent default goes back to the DSP source.
    • The mapping stays, and the condition is logged.
    • A default mapping is sampled once per mapping, not on every audio event.
    • A sample that can't be taken changes nothing.
    • A muted mapping, on either side, is the user's mic mute. It is never sampled or swapped for the unmuted DSP. With the monitor as the default, Omarchy's mute key mutes the sink side (checked in PipeWire 1.6.9).
    • I couldn't find omarchy-audio-asahi-mic-map switches the default source to a silent omarchy_asahi_mic.monitor (J314s) #505's root cause in a simulated graph (passive filter-chain source, PipeWire 1.6.9): audio flowed. The fix covers whatever the J314s cause is.
  • fix(install): skip asahi mic user-bus calls without XDG_RUNTIME_DIR #462: omarchy-mac-setup-user reaches the user bus only through XDG_RUNTIME_DIR, so a sudo -i resume no longer aborts.
  • Pin screen recording audio at 48 kHz after loudnorm #502: the screen recording finalize pass pins -ar 48000, so loudnorm no longer writes 96 kHz files that trip speakersafetyd. Drop it when Pin recording audio sample rate at 48 kHz omarchy#11092 lands.

#478 (J456 iMac fallback) is left with its author: it is a draft awaiting hardware checks and would need a rebase onto packages/omarchy-mac.

Needed elsewhere

  • 04/09 (omarchy-mac-boot): drop enable speakersafetyd.service from 80-omarchy-mac.preset and 80-omarchy-apple.preset, and drop speakersafetyd from the first-boot hand-off (systemctl enable speakersafetyd.service sddm.service). Until then both packages enable it.
  • 23 (image builder): apply_presets must also apply omarchy-mac's preset (or run preset-all), and the bootstrap check's hand-off links must stop expecting speakersafetyd from the boot package.
  • 08 (recipe): on the next re-pin, add asahi-audio alsa-ucm-conf-asahi rtkit pipewire-alsa to depends. asahi-audio pulls speakersafetyd.
  • 43 (mx-mac adapter): mx-mac's /etc/wireplumber/.../asahi-audio-no-suspend.conf belongs to omarchy-settings-dev, so the package swap removes it. Setup deliberately leaves /etc alone.

Tests

  • packages/omarchy-mac/test/all passes at every commit (Arch Linux ARM container). New coverage:
    • speakersafetyd preset, mask, /etc preset and disable, checked with real systemctl --root
    • live start-limit recovery
    • mx-mac user-policy retirement
    • the sudo -i bus case (fails on the old code)
    • silent, muted and racing monitor choices in the mapper (the new cases fail on the old mapper)
    • the real parec probe against a stub
  • Probe checked against a real PipeWire/pipewire-pulse server: a silent null-sink monitor returns no signal after the timeout, and a playing one returns signal in 50 ms.
  • Runtime suite (./test/all, non-root): 292 files. Only the base branch's 4 environment failures remain (config, hermes-remove, snapper, unowned-system-paths: sibling repos absent in the container). update-lock-test failed once under load and passes alone. The affected files and ./test/cli pass again after the review fixes.
  • test/shell.d/screenrecording-sample-rate-test.sh runs a real ffmpeg finalize: 48000 Hz with the fix, 96000 Hz without.
  • Second review: 8 findings, all fixed with tests. The high one was that the mute key mutes the mapping sink, so the first version could hand a muted mic to the unmuted DSP. The re-review found a stale sample cache after audio restarts, also fixed.

Hardware (not done here)

The M2 Max was inspected read-only (mx-mac stack): speakersafetyd enabled through the boot preset, and the no-suspend policy in /etc (owned by omarchy-settings-dev) and ~/.config. The mic mapper is not installed, and the default source is effect_output.j416-mic. Speaker and mic acceptance on the converged image belongs to 25/51. Run this in the owner's session there. --no-sound skips the 3 s capture and the tone.

audio-check.sh
#!/bin/bash
# Ticket 37 hardware check. Run on the Mac, in the owner's desktop session, from
# the converged image: bash m2max-audio-check.sh [--no-sound]
# Read-only apart from a 3 s microphone capture and a 2 s speaker tone, both
# in memory. Listen for the tone and for a pop when it starts and stops.
# --no-sound skips the capture and the tone.
set -u
sound=1
[[ ${1:-} == "--no-sound" ]] && sound=0
export XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-/run/user/$(id -u)}
status=0
check() { if eval "$2" >/dev/null 2>&1; then echo "PASS $1"; else echo "FAIL $1"; status=1; fi; }

check "audio stack installed" "pacman -Q omarchy-mac alsa-ucm-conf-asahi asahi-audio speakersafetyd rtkit pipewire-alsa"
check "speakersafetyd enabled and active" "systemctl is-enabled --quiet speakersafetyd && systemctl is-active --quiet speakersafetyd"
presets=$(grep -l 'speakersafetyd' /usr/lib/systemd/system-preset/*.preset /etc/systemd/system-preset/*.preset 2>/dev/null)
echo "speakersafetyd presets: ${presets:-none}"
check "only omarchy-mac presets speakersafetyd" "[[ \$(pacman -Qqo $presets 2>/dev/null | sort -u) == omarchy-mac ]]"
check "speaker amps unlocked this boot" "journalctl -b -u speakersafetyd --no-pager | grep -q 'unlocked'"
check "speaker DSP sink present" "pactl list short sinks | grep -q 'convolver'"
check "speaker and headphone sinks never suspend" "pw-dump | python3 -c \"
import json, sys
nodes = [o['info']['props'] for o in json.load(sys.stdin) if o.get('type', '').endswith(':Node')]
alsa = [p for p in nodes if p.get('media.class') == 'Audio/Sink' and str(p.get('api.alsa.path', '')).startswith('hw:AppleJ') and str(p.get('api.alsa.path', '')).endswith((',0', ',1'))]
sys.exit(not alsa or any(int(p.get('session.suspend-timeout-seconds', 5)) != 0 for p in alsa))
\""
check "mic mapper running" "systemctl --user is-active --quiet omarchy-asahi-mic.service"
source=$(pactl get-default-source)
echo "default source: $source"
journalctl --user -b -u omarchy-asahi-mic.service --no-pager | tail -n 5
(( sound )) || exit $status
check "default source carries microphone signal" "timeout 3 parec --device='$source' --raw --format=s16le --channels=2 --rate=48000 | python3 -c \"
import array, sys
samples = array.array('h', sys.stdin.buffer.read())
peak = max(map(abs, samples)) if samples else 0
print('peak', peak, file=sys.stderr)
sys.exit(peak < 8)
\""
echo "Playing a 2 s tone on the default sink ($(pactl get-default-sink))"
python3 -c "
import math, struct, sys
sys.stdout.buffer.write(b''.join(struct.pack('<hh', v, v) for v in (int(3000 * math.sin(2 * math.pi * 440 * i / 48000)) for i in range(96000))))
" | pacat --raw --format=s16le --channels=2 --rate=48000
echo "Listen: tone audible, no pop at start or stop. Record the result by hand."
exit $status

maralcbr and others added 10 commits September 25, 2026 19:27
omarchy-mac-setup-system is now the only enabler of speakersafetyd: it
applies the package's 80-omarchy-mac-audio.preset once the daemon is
installed, so /etc presets, masks and explicit disables win, and a live run
restarts a daemon a start-limit left dead. The desktop audio leaf keeps
installing the protected stack, now with alsa-ucm-conf-asahi (without it
there is no speaker path), and hands enablement to the package.

The package also ships mx-mac's WirePlumber no-suspend policy so the
speaker amplifiers stay powered between streams instead of popping, and
retires exact per-user copies mx-mac left behind.
systemctl --user reaches the session bus only through XDG_RUNTIME_DIR. A
guided resume under sudo -i clears it while /run/user/UID/bus still
exists, so the old fallback called systemctl --user and aborted setup. The
wants link already activates the mapper at the next graphical session.

Retargeted from #462 against quattro.

Co-authored-by: Z23 <3616196+z23@users.noreply.github.com>
The mapper switched the default input to its stereo monitor once the ports
and links existed, without checking that audio flowed. On a J314s that
monitor carried only digital silence, so every default-source recorder got
zeros (#505). A muted mapping sink, which the volume keys hit while
WirePlumber briefly makes the new null sink the default output, has the
same effect.

Before selecting the monitor, or while it is the default, sample it
briefly through parec: only a monitor with a non-zero sample becomes the
default, and a silent default goes back to the DSP source. The mapping
stays in place and the condition is logged. A muted monitor is the user's
microphone mute, so it is never sampled or swapped for the unmuted DSP.
loudnorm declares 192 kHz output, so without -ar the finalize pass writes
96 kHz AAC and undoes wf-recorder's -R 48000. Playing that file switches
the Asahi speaker PCM to 96 kHz, speakersafetyd panics on bad IV-sense
data and the kernel locks the amps.

Retargeted from #502 against quattro; drop it once omacom#11092
lands upstream.

Co-authored-by: Issac Trotts <issac.trotts@gmail.com>
Muting the monitor while it is sampled silences it, and the mapper then
moved the default input to the unmuted DSP. Re-read the monitor after
sampling so that mute keeps the monitor selected.
While the monitor is the default source, the mute key mutes the mapping
sink, not the monitor. The mapper read only the monitor, so the next
event sampled the resulting silence and switched to the unmuted DSP. A
mute on either side is now the user's microphone mute.

The supervisor samples a default mapping once instead of on every audio
event, which opened the microphone each time. Samples are read as floats,
so a quiet monitor is not mistaken for digital silence, and a sample that
could not be taken changes nothing instead of counting as silence.
The no-suspend policy matched every node on the Apple card's first two
PCM devices, so a capture node there would never close after use. Match
sinks only.

The desktop audio leaf warns instead of aborting hardware setup when the
omarchy-mac hand-off fails, like the rest of that leaf. Preset wording now
says which /etc presets outrank the package's.
The once-per-mapping cache is keyed on PipeWire port IDs, which are
reused. The mapper outlives an audio restart, so a rebuilt mapping could
match a key sampled before it and skip sampling. Clear the cache whenever
the mapper loads a new mapping module.
@maralcbr
maralcbr changed the base branch from mac/13-hw-platform to quattro-upstream September 25, 2026 09:53
# Conflicts:
#	packages/omarchy-mac/README.md
#	packages/omarchy-mac/bin/omarchy-mac-setup-user
#	packages/omarchy-mac/test/systemd-test.sh
@maralcbr
maralcbr merged commit 7b1b825 into quattro-upstream Sep 25, 2026
5 checks passed
maralcbr added a commit that referenced this pull request Sep 25, 2026
Brings in the password sync (#532), audio (#535), display (#533), Wi-Fi
resume (#529) and battery charge limit (#525) work.

omarchy-drive-password takes #532's version. It already carries what #503
added (no tracing, the new password over stdin), and it has no Apple branch.
#503's drive-password-apple-test.sh asserted that the disk password never
changes the login or root password, which ticket 19 replaced with a
journaled LUKS-first sync for the system disk; drive-password-test.sh covers
the shared behaviour, so the Apple copy goes.
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.

1 participant