Repository navigation
Add speakerguard-xlim, a look-ahead excursion and peak limiter - #9
Closed
RyanTheTide wants to merge 1 commit into
Closed
RyanTheTide wants to merge 1 commit into
RyanTheTide wants to merge 1 commit into
Conversation
This adds a LADSPA plugin for the J700 speaker graph in PipeWire's
filter-chain. It predicts the cone displacement of every sample from
the driver's lumped model. The model is a closed box with no coil
inductance:
X/V = (Bl/Re) / (Mms s^2 + (Rms + Bl^2/Re) s + Kms)
It is bilinear-mapped and prewarped at resonance. The plugin lowers the
gain just enough, ahead of time, that the cone stays under 0.9 of Xmax
and no sample passes full scale. A velocity limit is there too, off by
default.
The gain is a sliding minimum of each frame's requirement, ramped by a
running mean over 3.333 ms. The ramp ends 4 ms before the frame that
needs it goes out. Those 4 ms are the cone's memory: its ringing at
resonance decays by e in 1.2 ms, and a gain falling while the cone still
rings is not a gain applied to it. Without the hold the cone passed
Xmax by up to 13 % on random programs. The model's prediction is held
at 0.89 of Xmax, so the gain changes left inside the memory keep the
true cone under 0.9. The release is 200 ms. The two channels share
one gain.
The latency is 351 frames at 48 kHz (7.3 ms), reported on the latency
port. The defaults are the MacBook Neo's driver values: Bl 0.74 T m,
Mms 0.16 g, Kms 1720 N/m, Rms 0.14 kg/s, Re 4.3 ohm, 7.30/7.33 V at full
scale, Xmax 0.565 mm.
The audio thread never allocates. The memory for the longest window
and hold is taken at instantiation, and a control change only
reconfigures. An invalid control keeps the last valid set; before any
valid set the output is silence. A sample that is not finite is taken
as silence.
Tests (make filter-test, on x86_64 and aarch64 Linux):
- the model's DC gain and resonance;
- transparency: below the limits the output is the delayed input, bit
for bit;
- the limits on loud tones and bursts;
- an impulse delayed by exactly the reported latency, within a 352-frame
budget;
- non-finite input;
- no drift after ten minutes of limiting;
- no allocation in run() (glibc);
- invalid controls.
test_random drives the limiter against an independent model of the
cone: its continuous equation of motion, integrated by Runge-Kutta at
eight steps a sample. The inputs are random programs (tones, bursts,
chirps, square waves, steps, impulses, noise, random block sizes) plus
172 worst-case shapes: steps, impulse trains around resonance, square
waves at it and its odd fractions, and quiet-to-full-scale jumps. Over
87000 random programs and the shapes, the worst cone was 0.8956 of
Xmax. With the prediction held at 0.9 instead, or with a 2 ms hold,
the test fails.
make filter and make install-filter build and install the plugin apart
from the daemon. The daemon is unchanged.
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Assisted-by: LLM
This was referenced Oct 24, 2026
Closed
Contributor
Author
|
Superseded by #27: this PR's head is already contained in the 0.1.13 release candidate branch (fu-speakerguardd-rc), so it lands with that PR. Closing to keep one release PR (fewer, bigger PRs). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
speakerguard-xlim, a look-ahead limiter for the MacBook Neo (J700) speaker graph, infilter/. It is a LADSPA plugin for PipeWire's filter-chain. The daemon is unchanged.What it does
The plugin predicts the cone displacement of every sample from the driver's lumped model and lowers the gain just enough, ahead of time, to keep the cone under 0.9 of Xmax and every sample under full scale.
Timing
Real-time safety
Tests
make filter-testpasses on x86_64 and aarch64 Linux.test_randomchecks the limiter against an independent model of the cone: its continuous equation of motion, integrated by Runge-Kutta at eight steps a sample.test_xlimcovers:test_ladspaloads the plugin as a host would and covers:run()(glibc);Using it
make install-filterinstalls$(LIBDIR)/ladspa/speakerguard-xlim.so. The J700 graph that uses it is a separate, off-by-default variant in aurora-silicon/asahi-audio (fleet2/j700-xlim).Draft: nothing has played through it yet. The first listen on the Neo starts at -40 dBFS for transparency, and anything louder waits for an attended session.
Assisted-by: LLM
🤖 Generated with Claude Code