No description
Find a file
atagen efb0c0f746 fix: kill bus-filter tremolo via larger ring + scheduling hints
Soak testing surfaced a continuous per-quantum tremolo on the
processed audio path. `pw-cli info` on the filter streams showed
`clock.quantum-limit = "8192"` (frames) — exactly matching the
ring's 16 384-sample capacity. With max buffer == ring capacity
there is zero headroom: each callback the capture pushed a full
buffer's worth into a half-empty ring (dropping the overflow) and
the very next playback callback found the ring under-filled
(zero-filling the deficit). At steady state ~32 k samples/sec
were each dropped on capture and zero-filled on playback —
audible as ~23 Hz amplitude modulation on whatever was playing.

Confirmed by plumbing `samples_starved` / `samples_dropped` (which
existed in `PlaybackState` / `CaptureState` but were never read)
through a shared `PlaybackTiming` so the AGC tick can log per-tick
deltas. Both counters climbed in lockstep, both idle and active —
the lockstep being the signature of buffer-size > ring-size.

Mitigation:
  * Bump `RING_CAPACITY` 16 384 → 65 536 (4× the documented
    max buffer × CHANNELS). Adds ~340 ms average ring latency,
    which is bad for competitive gaming but acceptable as a
    hold-the-line measure.
  * Set `node.latency = "256/48000"` on both filter halves so
    PipeWire targets a small buffer. The hint is advisory and
    the system's quantum-limit ceiling still wins, but it costs
    nothing and helps on systems with less aggressive defaults.
  * Set `node.link-group` on both halves to the same value —
    standard for `module-loopback`'s paired-stream pattern.
  * Set `audio.rate` and `node.passive = true` on the processed
    sink so it runs at the real sink's rate and follows the same
    driver. Eliminates a redundant resampler at the monitor →
    filter boundary and lands every headroom node under one
    driver (confirmed via pw-top: all show as `+` followers of
    Mbox).
  * Re-order runtime startup so the initial sample rate is
    computed before either the processed sink or the filter is
    built; both now boot at the same rate.

What this does not do: fix the underlying architectural issue.
The two `pw_stream`s communicate via an rtrb ring with no
PipeWire-graph dependency edge between them, so producer/consumer
ordering within a quantum isn't enforced — the fix is to switch
to a single `pw_filter` node (input + output ports on the same
node, ordering by construction). That rewrite is the next move;
this commit just gets the soak unblocked.
2026-05-22 10:04:45 +10:00
contrib/systemd 7: packaging — systemd user unit + Nix modules + README 2026-05-21 17:00:25 +10:00
crates fix: kill bus-filter tremolo via larger ring + scheduling hints 2026-05-22 10:04:45 +10:00
docs stage 2 2026-05-19 16:33:09 +10:00
nix 7: packaging — systemd user unit + Nix modules + README 2026-05-21 17:00:25 +10:00
profiles stage 2 2026-05-19 16:33:09 +10:00
.gitignore stage 2 2026-05-19 16:33:09 +10:00
Cargo.lock 8a: assert_no_alloc on audio-thread callbacks 2026-05-21 16:21:53 +10:00
Cargo.toml 5: monitor TUI + wire fill-ins 2026-05-21 13:35:27 +10:00
flake.lock drop flake-utils 2026-05-21 22:11:36 +10:00
flake.nix drop flake-utils 2026-05-21 22:11:36 +10:00
IPC.md stage 2 2026-05-19 16:33:09 +10:00
PLAN.md F5: document the limiter's rate-leakage caveat in PLAN §3.1 2026-05-21 18:43:58 +10:00
README.md 7: packaging — systemd user unit + Nix modules + README 2026-05-21 17:00:25 +10:00
rust-toolchain.toml stage 2 2026-05-19 16:33:09 +10:00

headroom

AGC + compressor + true-peak limiter daemon for PipeWire, in Rust.

Headroom puts a per-application audio safety net between noisy sources (browsers, voice chat, random video) and your speakers, while leaving the things you don't want compressed (music players, games, DAWs) untouched.

  • Hard 0.1 dBTP ceiling on the processed route, with proper inter-sample-peak handling, enforced inline so the contract holds regardless of control-plane state. Streams routed bypass ride the real sink directly and are not in scope of the contract — that's the trade-off that makes the per-app exclusion useful.
  • Per-app exclusion with profile-driven rules.
  • Layer A per-app level control (peak + RMS detector → smoothed channelVolumes writes) for taming individual streams without touching the bus path. Zero added signal-path latency; safe to use on bypass-routed streams.
  • Single binary daemon + CLI, controlled over a Unix-domain socket with a documented JSON wire protocol (see IPC.md).
  • First-party Rust crate (headroom-client) for programmatic use; third-party clients (Qt panels, status bars, …) target the wire protocol directly.
  • Live profile reload — edit a TOML file in $XDG_CONFIG_HOME/headroom/profiles/ and the daemon picks up changes within ~500 ms; the audio thread doesn't glitch.

See PLAN.md for the full design and roadmap.

Status

Alpha. The signal chain (AGC, compressor, two-tier limiter, Layer A per-app), the routing engine (explicit-link enforcement, sink hotplug, sticky default sink), the IPC server with topic subscriptions, the headroom monitor TUI, and live profile reload all work end-to-end. Packaging exposes a systemd user unit and Nix modules. What's missing is real-world soak time on multi-rate / Bluetooth setups and other distros' init systems.

Installing

Nix (flake)

This repo is a flake; the daemon plus its systemd user unit and the canonical profiles are exposed as a package.

nix run github:amaanq/headroom -- daemon          # one-shot run
nix profile install github:amaanq/headroom        # add to $PATH

For Home Manager, add the flake as an input and enable the module:

{
  inputs.headroom.url = "github:amaanq/headroom";

  # In your Home Manager configuration:
  imports = [ inputs.headroom.homeModules.default ];
  services.headroom.enable = true;
}

The module symlinks the shipped profiles into $XDG_CONFIG_HOME/headroom/profiles/, drops the systemd user unit into the user's services dir, and the unit starts after PipeWire and WirePlumber come up. services.headroom.extraProfiles lets you add your own.

For NixOS (system-wide binary install + systemd-user discovery):

{
  inputs.headroom.url = "github:amaanq/headroom";

  # In your NixOS configuration:
  imports = [ inputs.headroom.nixosModules.default ];
  programs.headroom.enable = true;
}

Then any user can systemctl --user enable --now headroom.

Other distros (manual)

cargo install --path crates/headroom-cli   # or: cargo build --release
# Profiles
mkdir -p ~/.config/headroom/profiles
cp profiles/*.toml ~/.config/headroom/profiles/
# systemd user unit (edit the ExecStart path to point at your binary)
install -Dm644 contrib/systemd/headroom.service \
  ~/.config/systemd/user/headroom.service
sed -i "s|@bindir@|$(dirname "$(command -v headroom)")|" \
  ~/.config/systemd/user/headroom.service
systemctl --user daemon-reload
systemctl --user enable --now headroom

Usage

Once the daemon is running:

headroom status                 # JSON snapshot — sinks, streams, active profile
headroom profile list           # available profiles
headroom profile use night      # activate one
headroom monitor                # full-screen TUI (bus gauges + per-stream)
headroom monitor --json meters  # line-delimited JSON, for scripting
headroom route set firefox processed
headroom set compressor.threshold_db -28
headroom bypass on              # kill switch — straight to the real sink

See headroom --help for the full surface.

Building

nix develop          # toolchain + pipewire dev libs + helpers
cargo build          # iterate
cargo test --workspace
nix build            # final packaged headroom binary

License

GPL-3.0-or-later for the daemon and CLI. headroom-dsp and headroom-ipc are MPL-2.0 so they can be reused by non-GPL plugin hosts and clients.