Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 95-speakersafetyd.rules
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ KERNEL=="pcmC*D2c", ATTRS{id}=="AppleJ613", TAG+="systemd", ENV{SYSTEMD_WANTS}="
KERNEL=="pcmC*D2c", ATTRS{id}=="AppleJ615", TAG+="systemd", ENV{SYSTEMD_WANTS}="speakersafetyd.service"

KERNEL=="pcmC*D2c", ATTRS{id}=="AppleJ813", TAG+="systemd", ENV{SYSTEMD_WANTS}="speakersafetyd.service"
KERNEL=="pcmC*D2c", ATTRS{id}=="AppleJ815", TAG+="systemd", ENV{SYSTEMD_WANTS}="speakersafetyd.service"

LABEL="speakersafetyd_end"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## speakersafetyd - a software Smart Amp implementation

Aurora J813 capped-profile details and qualification: [docs/j813.md](docs/j813.md).
Aurora J815 capped-profile details and qualification: [docs/j815.md](docs/j815.md).
speakersafetyd is a userspace daemon written in Rust that implements an
analogue of the Texas Instruments Smart Amp speaker protection model.

Expand Down
140 changes: 140 additions & 0 deletions conf/apple/j815.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# SPDX-License-Identifier: GPL-2.0-only
# J815 (MacBook Air 15-inch, M5) capped speaker profile. Sense layout qualified on hardware (2026-11-11 sweep).
# Provenance and qualification: docs/j815.md.
#
# Thermal/electrical constants: macOS ships one speaker-protection tuning for every 15-inch MacBook Air.
# AID43 (J815, acoustic-id 0x2b) is the same file (hard link) as AID21 (J615) and AID27 (J415); docs/audump.py
# on AID43 reproduces upstream j615.conf exactly. Those values are kept as they are.
# Limits are NOT Apple's: as on J813 (docs/j813.md) the model limit is a conservative 80 C with 5 C headroom
# (Apple: 140 C / 10 C), and the digital ceilings are J813's qualified -24 dB (woofers) / -32 dB (tweeters).
# Channel layout (6 SN012776, ADT speaker-config order = Apple's spp3 Channel0..5): pair k carries speaker k's
# sense, voltage first, as on J813. Left Woofer 1 (0x38) voltage lags its current by one sample, as on J813.
# Both measured on J815 hardware with a low-level sweep per speaker (docs/j815.md, testing/{make,verify}_j815_sweep.py).
[Globals]
visense_pcm = 2
t_ambient = 50.0
t_hysteresis = 5.0
t_window = 20.0
channels = 12
period = 4096
link_gains = True
uclamp_max = 64
max_volume_db = -24.0

[Controls]
vsense = VSENSE Switch
isense = ISENSE Switch
amp_gain = Amp Gain Volume
volume = Speaker Volume

# speaker-config 0: 0x38, V/I sense slots 0/2 (Apple W_L_1)
[Speaker/Left Woofer 1]
group = 1
tr_coil = 40.00
tr_magnet = 26.00
tau_coil = 3.00
tau_magnet = 35.00
t_limit = 80.0
t_headroom = 5.0
z_nominal = 4.20
z_shunt = 0.00
a_t_20c = 0.00352082
a_t_35c = 0.00328147
is_scale = 3.75
vs_scale = 14
vs_chan = 0
is_chan = 1
current_delay_samples = 1
current_delay_rate = 48000

# speaker-config 1: 0x3b, slots 4/6 (Apple W_R_1)
[Speaker/Right Woofer 1]
group = 1
tr_coil = 40.00
tr_magnet = 26.00
tau_coil = 3.00
tau_magnet = 37.00
t_limit = 80.0
t_headroom = 5.0
z_nominal = 4.20
z_shunt = 0.00
a_t_20c = 0.00352082
a_t_35c = 0.00328147
is_scale = 3.75
vs_scale = 14
vs_chan = 2
is_chan = 3

# speaker-config 2: 0x39, slots 8/10 (Apple T_L)
[Speaker/Left Tweeter]
max_volume_db = -32.0
group = 0
tr_coil = 124.00
tr_magnet = 89.80
tau_coil = 1.80
tau_magnet = 28.00
t_limit = 80.0
t_headroom = 5.0
z_nominal = 3.76
z_shunt = 0.00
a_t_20c = 0.00347480
a_t_35c = 0.00336649
is_scale = 3.75
vs_scale = 14
vs_chan = 4
is_chan = 5

# speaker-config 3: 0x3c, slots 12/14 (Apple T_R)
[Speaker/Right Tweeter]
max_volume_db = -32.0
group = 0
tr_coil = 129.00
tr_magnet = 87.20
tau_coil = 1.80
tau_magnet = 28.00
t_limit = 80.0
t_headroom = 5.0
z_nominal = 3.76
z_shunt = 0.00
a_t_20c = 0.00347480
a_t_35c = 0.00336649
is_scale = 3.75
vs_scale = 14
vs_chan = 6
is_chan = 7

# speaker-config 4: 0x3a, slots 16/18 (Apple W_L_2)
[Speaker/Left Woofer 2]
group = 1
tr_coil = 35.00
tr_magnet = 24.50
tau_coil = 3.00
tau_magnet = 35.00
t_limit = 80.0
t_headroom = 5.0
z_nominal = 4.00
z_shunt = 0.00
a_t_20c = 0.00352082
a_t_35c = 0.00328147
is_scale = 3.75
vs_scale = 14
vs_chan = 8
is_chan = 9

# speaker-config 5: 0x3d, slots 20/22 (Apple W_R_2)
[Speaker/Right Woofer 2]
group = 1
tr_coil = 35.00
tr_magnet = 24.50
tau_coil = 3.00
tau_magnet = 35.00
t_limit = 80.0
t_headroom = 5.0
z_nominal = 4.00
z_shunt = 0.00
a_t_20c = 0.00352082
a_t_35c = 0.00328147
is_scale = 3.75
vs_scale = 14
vs_chan = 10
is_chan = 11
97 changes: 97 additions & 0 deletions docs/j815.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# J815 capped speaker protection

`conf/apple/j815.conf` is the speaker-protection profile for the MacBook Air 15-inch (M5), J815. It drives all
six internal speakers at 48 kHz with the Aurora audio driver. Like the J813 profile, it targets comfortable
everyday playback rather than full macOS loudness. The amplifier ceilings are -24 dB for the four woofers and
-32 dB for the two tweeters, the values qualified on J813 (`docs/j813.md`).

The profile needs the J815 kernel audio support: six SN012776 codecs on i2c3, the AOP speaker back-end in its
six-amp layout, and the `apple,j815-macaudio` machine configuration with the kernel speaker interlock from
Linux #1000/#1048. The interlock keeps the amps at the safe level until this daemon holds the speaker lease and
relocks them when it goes away.

## Speakers and amplifiers

The six amplifiers are listed in the order of the ADT `audio-speaker` `speaker-config`: the primary amp
(0x38), then `speaker1` to `speaker5`. That is also the order of Apple's own speaker-protection channels.

| # | Speaker | I2C | V/I sense slots | Feedback channels (V, I) |
|---|---|---|---|---|
| 0 | Left Woofer 1 | 0x38 | 0 / 2 | 0, 1 |
| 1 | Right Woofer 1 | 0x3b | 4 / 6 | 2, 3 |
| 2 | Left Tweeter | 0x39 | 8 / 10 | 4, 5 |
| 3 | Right Tweeter | 0x3c | 12 / 14 | 6, 7 |
| 4 | Left Woofer 2 | 0x3a | 16 / 18 | 8, 9 |
| 5 | Right Woofer 2 | 0x3d | 20 / 22 | 10, 11 |

The section names must match each codec's `sound-name-prefix` in the device tree. The daemon finds each amp's
controls (`<name> VSENSE Switch` and so on) by these names.

## Where the values come from

- **Thermal and electrical constants: the 15-inch MacBook Air's, unchanged.** macOS ships one
speaker-protection tuning for the J415, J615 and J815. The files are hard links to the same inode, so they
are byte-identical. `docs/audump.py` prints exactly the values of `j615.conf` from both the J615 and J815
tunings. The J815 therefore uses the same speakers and protection constants as `j615.conf`.
- **Limits: deliberately below Apple's.** As on J813, the model limit is 80 °C with 5 °C headroom (Apple:
140 °C with 10 °C). The digital ceilings are -24 dB for woofers and -32 dB for tweeters. Lower limits only
make the governor act earlier.
- **Feedback layout: measured.** The 12 S16 feedback channels are one voltage/current pair per speaker, in
the order above, voltage first, as on J813. Left Woofer 1's voltage lags its current by one sample at
48 kHz, also as on J813, so its section sets `current_delay_samples = 1` with `current_delay_rate = 48000`.

The profile contains no Apple DSP code or tuning bundle.

## Hardware qualification

All measurements were taken on one J815 (macOS 27 firmware, Aurora Linux) with this profile and the
unmodified daemon from `main`.

- **Probe and ceilings.** All six amps probed. Every `VSENSE`/`ISENSE` switch, `Amp Gain Volume` and
`Speaker Volume` control was present. The feedback PCM opened with 12 channels at 48 kHz. With the daemon
running, the controls read back `Speaker Volume` 153 (-24 dB) on all four woofers and 137 (-32 dB) on both
tweeters.
- **Low-level electrical sweep.** The daemon was restarted with `-v --sense-capture`. One exponential sweep
per speaker was played through it, one speaker at a time: woofers 80 Hz to 10 kHz at -12 dBFS, tweeters
400 Hz to 16 kHz at -18 dBFS, 1.6 s each (`testing/make_j815_sweep.py`). That is about 2 mW per woofer
and 0.2 mW per tweeter. `testing/verify_j815_sweep.py` passed every speaker:

| Speaker | Pair | Crosstalk above noise | V/I order from | Lag (samples) | R_min (Ω) | z_nominal (Ω) |
|---|---|---|---|---|---|---|
| Left Woofer 1 | 0 | 5.7 % | envelope | voltage 1 late | 3.93 | 4.20 |
| Right Woofer 1 | 1 | 5.1 % | envelope | 0 | 3.99 | 4.20 |
| Left Tweeter | 2 | 0.0 % | phase | 0 | 3.37 | 3.76 |
| Right Tweeter | 3 | 0.0 % | phase | 0 | 3.59 | 3.76 |
| Left Woofer 2 | 4 | 5.6 % | envelope | 0 | 3.94 | 4.00 |
| Right Woofer 2 | 5 | 5.2 % | envelope | 0 | 4.07 | 4.00 |

Each speaker answered on its own pair; the other five pairs stayed at or below 5.7 % of it. With the profile's order and lag, each impedance is physical: a
positive real part across the band, a resonance peak, and a rise toward high frequency from the voice-coil
inductance. With the pair swapped or the lag changed, it is not. The impedance minimum is 0.90 to 1.02 of
`z_nominal`. The daemon's per-period power lines matched an independent float64 replay of the capture
within 7e-9 W.
- **Listening.** The sweep and ordinary playback at these ceilings were clear to the operator.

### How the sweep tools decide

- *Order:* during a sweep the amp's drive voltage is nearly flat while the current follows the impedance.
For the woofers, the flatter channel of the pair is the voltage. The tweeters' drive rises over their
sweep, so for them the order is the one that gives a physical impedance phase.
- *Lag:* a one-sample error at 48 kHz is about 75° of phase at 10 kHz. Only one lag leaves the
high-frequency phase between 0 and +80°.
- *Crosstalk:* the other five pairs' level, measured above the capture's own noise floor during the lead-in
silence.

## Not covered

This qualification covers the feedback layout and the capped ceilings. Higher ceilings, Apple's 140 °C
limit, other sample rates, and desktop routing and equalization are outside it. Each of those needs its own
qualification with sustained-playback thermal data. Keep the kernel locks, the profile limits and the
read-back checks throughout testing.

## Attribution

- **Asahi Linux Contributors:** upstream `speakersafetyd` and `j615.conf`, whose constants this profile keeps.
- **Acelogic:** the J813 capped profile, feedback-delay handling, gain ceilings and sense capture that this
profile and its qualification follow.
- **Thomas Glanzmann (sithglan):** the J813 kernel audio work this machine's audio support builds on.
31 changes: 31 additions & 0 deletions testing/make_j815_sweep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python3
"""Generate the J815 low-level speaker sweep: one exponential sine sweep per speaker, one speaker at a time.

usage: make_j815_sweep.py sweep.wav signal.json

Six S32 channels at 48 kHz in the speaker PCM's slot order. Woofers sweep 80 Hz-10 kHz at -12 dBFS, tweeters
400 Hz-16 kHz at -18 dBFS, 1.6 s each. Play it only with speakersafetyd running on the capped profile.
"""
import array, json, math, sys, wave
FS = 48000
order = ["Left Woofer 1", "Right Woofer 1", "Left Tweeter", "Right Tweeter", "Left Woofer 2", "Right Woofer 2"]
woofer = dict(f1=80.0, f2=10000.0, dbfs=-12.0)
tweeter = dict(f1=400.0, f2=16000.0, dbfs=-18.0)
LEAD, DUR, GAP, TAIL, FADE = 1.0, 1.6, 0.5, 0.5, 0.01
n_total = int(FS * (LEAD + len(order) * (DUR + GAP) + TAIL))
data = array.array("i", bytes(4 * 6 * n_total))
segs = []
for ch, name in enumerate(order):
p = tweeter if "Tweeter" in name else woofer
start = int(FS * (LEAD + ch * (DUR + GAP))); n = int(FS * DUR)
amp = 10 ** (p["dbfs"] / 20) * 2147483647
k = math.log(p["f2"] / p["f1"])
for s in range(n):
t = s / FS
g = min(1.0, t / FADE, (DUR - t) / FADE)
ph = 2 * math.pi * p["f1"] * DUR / k * (math.exp(t * k / DUR) - 1)
data[(start + s) * 6 + ch] = int(amp * g * math.sin(ph))
segs.append(dict(name=name, slot=ch, start_s=start / FS, dur_s=DUR, **p))
with wave.open(sys.argv[1], "wb") as w:
w.setnchannels(6); w.setsampwidth(4); w.setframerate(FS); w.writeframes(data.tobytes())
json.dump(dict(rate=FS, frames=n_total, segments=segs), open(sys.argv[2], "w"), indent=1)
Loading