diff --git a/95-speakersafetyd.rules b/95-speakersafetyd.rules index 303385a..ccf749c 100644 --- a/95-speakersafetyd.rules +++ b/95-speakersafetyd.rules @@ -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" diff --git a/README.md b/README.md index e232fc1..4eedcdd 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/conf/apple/j815.conf b/conf/apple/j815.conf new file mode 100644 index 0000000..fa59c7f --- /dev/null +++ b/conf/apple/j815.conf @@ -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 diff --git a/docs/j815.md b/docs/j815.md new file mode 100644 index 0000000..70c7304 --- /dev/null +++ b/docs/j815.md @@ -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 (` 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. diff --git a/testing/make_j815_sweep.py b/testing/make_j815_sweep.py new file mode 100755 index 0000000..588dde0 --- /dev/null +++ b/testing/make_j815_sweep.py @@ -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) diff --git a/testing/verify_j815_sweep.py b/testing/verify_j815_sweep.py new file mode 100755 index 0000000..a5b05ef --- /dev/null +++ b/testing/verify_j815_sweep.py @@ -0,0 +1,237 @@ +#!/usr/bin/env python3 +"""Analyse a J815 speaker sweep recorded through speakersafetyd's sense capture. + +usage: verify_j815_sweep.py [j815.conf] [report.json] + +The sweep dir holds signal.json (from make_j815_sweep.py), sense.raw or sense.raw.gz (from the daemon's +--sense-capture while the sweep played) and, optionally, daemon.log (the daemon's -v output for the power replay). + +For each of the six speakers (played one at a time) it checks, from speakersafetyd's raw 12-channel S16 sense capture: + 1. map: which sense pair answers, and that the other five stay quiet (crosstalk); + 2. order: voltage vs current inside the pair. With the right order the impedance has a resonance PEAK and rises + at high frequency (voice-coil inductance); swapped, both invert (|Z_swapped| ~ 13.9 / |Z|); + 3. lag: the current-vs-voltage sample offset. A one-sample error is ~75 deg of phase at 10 kHz, so only one lag + leaves the high-frequency phase physical (between 0 and +80 deg, positive real part everywhere). + Sign: lag +n = the current channel lags the voltage by n samples; speakersafetyd's + current_delay_samples = n means the VOLTAGE lags (p = v[k] * i[k-n]), i.e. lag -n here; + 4. R: the impedance minimum in the band (~ the voice-coil resistance) against the profile's z_nominal. +It also replays the daemon's per-period SENSE power lines (-v) against the capture, as testing/verify_j813_power.py +does for J813. Nothing here raises a limit; it only says whether the profile's channel layout is right. +""" +import gzip, json, math, re, sys +from pathlib import Path +import numpy as np + +FS = 48000 +CH = 12 + + +def load_conf(path): + spk, cur, glob = {}, None, {} + for line in Path(path).read_text().splitlines(): + line = line.split('#', 1)[0].strip() + if not line: + continue + m = re.fullmatch(r'\[Speaker/(.+)\]', line) + if m: + cur = spk.setdefault(m[1], {}); continue + if line.startswith('['): + cur = glob if line == '[Globals]' else None; continue + if cur is not None and '=' in line: + k, v = (x.strip() for x in line.split('=', 1)); cur[k] = v + return glob, spk + + +def smooth(x, n): + if n < 2: + return x + k = np.ones(n) / n + return np.convolve(x, k, mode='same') + + +def impedance(v, i, f1, f2, lag, nfft=4096, hop=512): + """Z(f) = V/I (H1 estimate: averaged cross-spectrum over Hann blocks), current shifted by `lag` samples + (positive: the current channel lags the voltage), inside [f1, f2].""" + if lag > 0: + v, i = v[:-lag], i[lag:] + elif lag < 0: + v, i = v[-lag:], i[:lag] + win = np.hanning(nfft) + svi = np.zeros(nfft // 2 + 1, complex); sii = np.zeros(nfft // 2 + 1); svv = np.zeros(nfft // 2 + 1) + for a in range(0, len(v) - nfft + 1, hop): + V = np.fft.rfft(v[a:a + nfft] * win); I = np.fft.rfft(i[a:a + nfft] * win) + svi += V * np.conj(I); sii += np.abs(I) ** 2; svv += np.abs(V) ** 2 + f = np.fft.rfftfreq(nfft, 1 / FS) + coh = np.abs(svi) ** 2 / np.maximum(svv * sii, 1e-30) + band = (f >= f1) & (f <= f2) & (coh > 0.9) + return f[band], svi[band] / sii[band] + + +def octave_smooth(f, z, frac=6): + """1/frac-octave smoothing of complex Z on a log grid.""" + grid = np.geomspace(f[0] * 2 ** (0.5 / frac), f[-1] / 2 ** (0.5 / frac), 160) + out = [] + for g in grid: + sel = (f >= g * 2 ** (-0.5 / frac)) & (f <= g * 2 ** (0.5 / frac)) + out.append(np.median(z[sel].real) + 1j * np.median(z[sel].imag) if sel.any() else np.nan) + return grid, np.array(out) + + +def judge(fz, z, znom): + mag = np.abs(z); ph = np.degrees(np.angle(z)) + top = fz >= fz[-1] / 2 ** 0.75 + low = fz <= fz[0] * 4 + i_min = int(np.nanargmin(mag)) + i_pk = int(np.nanargmax(np.where(fz <= fz[-1] / 4, mag, -np.inf))) + r_min = float(mag[i_min]) + return dict( + r_min=r_min, f_rmin=float(fz[i_min]), r_peak=float(mag[i_pk]), f_peak=float(fz[i_pk]), + peak_over_min=float(mag[i_pk] / r_min), + hf_rise=float(np.nanmedian(mag[top]) / r_min), + hf_phase=float(np.nanmedian(ph[top])), + min_real=float(np.nanmin(z.real)), + low_mag=float(np.nanmedian(mag[low])), + r_ratio=float(r_min / znom) if znom else None, + ) + + +def physical(j): + return (0.0 <= j['hf_phase'] <= 80.0) and j['min_real'] > 0.5 * j['r_min'] and j['hf_rise'] >= 1.0 + + +def main(): + d = Path(sys.argv[1]) + conf = sys.argv[2] if len(sys.argv) > 2 and sys.argv[2] else str(Path(__file__).resolve().parents[1] / 'conf/apple/j815.conf') + out = Path(sys.argv[3]) if len(sys.argv) > 3 else d / 'SPKSWEEP-REPORT.json' + glob, spk = load_conf(conf) + sig = json.loads((d / 'signal.json').read_text()) + rawp = d / 'sense.raw.gz' + raw = np.frombuffer(gzip.open(rawp).read() if rawp.exists() else (d / 'sense.raw').read_bytes(), ' 0.10: + verdict.append(f'crosstalk {xtalk:.1%} on another pair') + if order_margin < 1.5 and order_from != 'phase': + verdict.append(f'voltage/current order unclear (envelope variation {cv_even:.3f} vs {cv_odd:.3f})') + if (vch, ich) != (vs, is_): + verdict.append(f'voltage is channel {vch}, current {ich}; profile has vs_chan {vs}, is_chan {is_}') + if best is None: + verdict.append('no current lag gives a physical impedance') + else: + lag = best[1]; jb = hyps[best] + if -lag != cfg_delay: + verdict.append(f'current lag {lag:+d} sample(s) (= current_delay_samples {-lag}); profile has {cfg_delay}') + if len(cand) > 1: + verdict.append(f'lag ambiguous: {sorted(k[1] for k in cand)} all physical') + if not (0.8 <= jb['r_ratio'] <= 1.3): + verdict.append(f'resistance {jb["r_min"]:.2f} ohm vs z_nominal {znom:.2f} ({jb["r_ratio"]:.2f}x)') + print(f'\n envelope variation: ch{2 * act} {cv_even:.3f}, ch{2 * act + 1} {cv_odd:.3f} -> voltage = ch{vch}' + f' (order from {order_from}); crosstalk raw {xtalk_raw:.1%}, above noise {xtalk:.1%}') + ok = not verdict + ok_all &= ok + print(f'\n== {name}: pair {act}, crosstalk {xtalk:.2%}, {"PASS" if ok else "CHECK: " + "; ".join(verdict)}') + print(' order lag R_min(ohm)@Hz peak(ohm)@Hz pk/min HFrise HFphase minRe phys') + for k, j in sorted(hyps.items(), key=lambda kv: (kv[0][2], kv[0][1])): + mark = '<-' if k == best else ' ' + print(f' {"V=%d I=%d" % (k[2], k[3]):9} {k[1]:+d} {j["r_min"]:6.2f} @{j["f_rmin"]:6.0f} {j["r_peak"]:6.2f} @{j["f_peak"]:6.0f}' + f' {j["peak_over_min"]:5.2f} {j["hf_rise"]:5.2f} {j["hf_phase"]:+6.1f} {j["min_real"]:5.2f} {"y" if j["physical"] else "-"} {mark}') + results.append(dict(name=name, pair=act, crosstalk=xtalk, crosstalk_raw=xtalk_raw, order_from=order_from, passed=ok, problems=verdict, envelope_cv=[cv_even, cv_odd], + best=None if best is None else dict(v_chan=best[2], i_chan=best[3], lag=best[1], **hyps[best]), + profile=dict(vs_chan=vs, is_chan=is_, current_delay_samples=cfg_delay, z_nominal=znom))) + + # Replay the daemon's SENSE power lines (speakersafetyd -v) against the capture, if they are there. + replay = {} + log = (d / 'daemon.log').read_text(errors='replace') if (d / 'daemon.log').exists() else '' + if 'panicked' in log: + print('\nWARNING: speakersafetyd panicked during the sweep'); ok_all = False + rows = {} + for m in re.finditer(r'SENSE name=(.*?) frames=(\d+) rate=(\d+) delay=(\d+) priming=(\d+) power=(-?[\d.]+)', log): + rows.setdefault(m[1], []).append((int(m[2]), int(m[4]), float(m[6]))) + for name, rr in rows.items(): + c = spk[name]; vs = int(c['vs_chan']); is_ = int(c['is_chan']); dl = int(c.get('current_delay_samples', 0)) + at, prev, errs = 0, None, [] + for frames, delay, power in rr: + if at + frames > len(raw): + break + v = raw[at:at + frames, vs] * float(c['vs_scale']) / 32768 + i = raw[at:at + frames, is_] * float(c['is_scale']) / 32768 + if dl: + al = np.empty_like(i); al[dl:] = i[:-dl]; al[:dl] = prev if prev is not None else float(c['is_scale']) * np.sign(v[0]); prev = i[-1] + else: + al = i + errs.append(abs(float(np.mean(v * al)) - power)); at += frames + replay[name] = dict(periods=len(errs), max_abs_error_W=max(errs) if errs else None) + if replay: + print('\ndaemon power replay (max |error| W per speaker):', {k: v['max_abs_error_W'] for k, v in replay.items()}) + report = dict(all_passed=bool(ok_all), signal_offset_frames=off, speakers=results, daemon_replay=replay, + note='Layout check only; raising the ceilings is a separate, stepwise decision.') + out.write_text(json.dumps(report, indent=1) + '\n') + print(f'\n{"ALL PASS" if ok_all else "NOT ALL PASS"} -> {out}') + + +if __name__ == '__main__': + main()