$ show AsahiLinux/speakersafetyd
speakersafetyd is a Rust system daemon that implements a software Smart Amp speaker protection model for Apple Silicon Macs running Linux. It reads voltage and current sense (V/ISENSE) data from a TAS2764-class codec via an ALSA capture PCM, simulates voice coil and magnet temperatures using per-machine configurable thermal parameters, and reduces speaker volume through ALSA mixer controls when temperatures approach limits. The daemon is fail-safe by design: the kernel keeps speakers volume-limited until the daemon writes an unlock magic value, and any panic causes the daemon to exit so the kernel can restore the safe state.
The LLM identified 3 files worth highlighting for reuse:
Self-contained Rust module that sets the calling process's scheduler utilization clamp (uclamp_min/uclamp_max) via raw sched_getattr/sched_setattr syscalls. It defines a #[repr(C)] SchedAttr struct and uses libc::syscall directly because libc doesn't expose these wrappers. This is safely extractable for any real-time or audio process that needs to constrain CPU frequency selection, and demonstrates non-obvious Linux scheduler API usage.
Collection of small, self-contained wrappers around the ALSA C API and configparser crate. It provides helpers for opening sound cards/PCMs, reading/writing control element values, locking elements, converting between integer and dB values, and parsing typed config keys with clear panic messages. The generic parse_int/parse_float wrappers are reusable for any Rust project using INI configs, and the ALSA wrappers are directly reusable for mixer/control applications.
Standalone Python script that parses Apple's proprietary CoreAudio DSP strip and audio unit preset files (plist + binary aupreset data) to extract speaker protection parameters (thermal resistances, time constants, temperature limits, channel mappings) and emit speakersafetyd config files. It decodes the binary TLV-like blocks with struct.unpack and maps numeric keys to human-readable labels for both spp3 and atsp protection modules. This is a reusable reverse-engineering tool for anyone working with Apple Silicon audio hardware or similar binary plist formats.