pw-loudness-eq 把 Windows 音量平衡功能移植到 PipeWire
Windows Loudness Equalization, reverse-engineered and ported to PipeWire
不同應用程式的音量差很多時,聽音樂或看影片常得一直調音量。
- pw-loudness-eq 把 Windows 的 Loudness Equalization 移植到 PipeWire,會在混音前調整各應用程式的播放音量,並用限幅器避免音量突然變大後超出上限。
- 也能設定哪些程式不處理。它需要 PipeWire 1.4 以上版本,並非所有播放串流都支援,例如 JACK 使用者端、超過 8 聲道的串流,以及直接使用 PipeWire 的 Flatpak 應用程式都不會處理。
AI 伴隨問答
針對這篇報導有疑問?可直接點選快捷問題或向 AI 追問背景脈絡與技術細節:
Windows' Loudness Equalization for PipeWire, reverse engineered from WMALFXGFXDSP.dll. It evens out the volume of each application, so quiet and loud parts play at a similar level.
modules/loudness/: the PipeWire module and the DSP plugin. It processes every app's playback stream.modules/limiter/: the output limiter of Windows' audio engine (AudioEng.dll), on every playback device. It keeps the boost from clipping.app/: an optional window (GTK3) to turn it on or off, globally or per app, and set the release time.
Install
Requires PipeWire ≥ 1.4, and GTK 3 for the window.
# Arch: sudo pacman -S pipewire gtk3 pkgconf make gcc # Debian: sudo apt install libpipewire-0.3-dev libspa-0.2-dev libgtk-3-dev pkg-config make gcc make sudo make install systemctl --user restart pipewire pipewire-pulse wireplumber
To install only one part, use make -C modules/loudness, make -C modules/limiter or make -C app. To uninstall, run sudo make uninstall and restart the same services.
Usage
Open Loudness Equalization from your application menu, or run pw-loudness-eq.
The settings live in a PipeWire metadata object, so they can also be scripted:
pw-metadata -n loudness-eq 0 enabled false # turn off pw-metadata -n loudness-eq 0 release 6 # release time, 2 (fast) to 7 (slow) pw-metadata -n loudness-eq 0 disabled-apps '["Discord"]' Spa:String:JSON # leave these apps alone pw-metadata -n loudness-eq # show settings
Changes apply immediately and are kept across restarts.
Configuration
Defaults are in /usr/share/pipewire/pipewire.conf.d/60-loudness-eq.conf. To override them, copy it to ~/.config/pipewire/pipewire.conf.d/.
| Arg | Default | |
|---|---|---|
enabled |
true |
Start enabled |
release |
4 |
Windows "Release Time", 2 (fast) to 7 (slow). 4 is the Windows default |
stream.rules |
Never process some apps: [ { matches = [ { application.name = "Discord" } ] actions = { loudness-eq = false } } ] |
Settings changed at runtime are saved in ~/.local/state/pw-loudness-eq/state.conf and take precedence over this file.
How it works
The loudness module sets audioconvert.filter-graph.90 on each app's playback stream, so the plugin runs inside that stream, before its volume and before mixing, like a Windows stream effect.
The limiter module does what Windows' audio engine does on every playback device: after the mix and the software volume, it runs the output through a look-ahead limiter. It's always on, independent of Loudness Equalization, as on Windows.
Not processed: JACK clients, streams with more than 8 channels, and Flatpak apps that use PipeWire directly (those going through PulseAudio are processed).
The algorithm
A broadband automatic gain control. Despite the name, it doesn't equalize the spectrum.
- Frame size N = 2^⌈log2(fs/100)⌉ (512 at 44.1/48 kHz), with 50% overlap.
- Each channel is windowed with
w[n] = 16384·(1 − cos(2π(n+½)/N)) / (N/2)and run through a real FFT to get the power spectrum. - Power is summed into 25 bands with edges at 100, 200, 300, 400, 510, 630, 770, 920, 1080, 1270, 1480, 1720, 2000, 2320, 2700, 3150, 3700, 4400, 5300, 6400, 7700, 9500, 12000, 15500 and 24000 Hz. Channels are summed together.
- Loudness
L = 1.72 · Σ max(E_b − T_b, 1e-32)^0.25, with T =1000, 100, 31.6, 10, 3.16, 2, 1, 1, .316, .316, 1×11, 4, 10, 100, 1000. - Target gain
= min((1300/L)^1.6, 10), so at most +20 dB. - When the target is lower than the current gain, the gain jumps to it instantly. Otherwise it moves toward it by
w = (N/128)·(44100/fs)·0.1^min(r,3)·0.316^(min(r,7)−min(r,3))per block. At r = 4 that's a time constant of about 4.6 s. - The gain is crossfaded linearly across each half-frame. Latency is N samples.
The boost can push pure tones such as a whistle well above full scale; the limiter catches that.
The limiter
Ported from CAudioLimiter in AudioEng.dll. audiodg.exe puts it on every render device, after its effects, before the device.
- The output is delayed by L frames (64 at 44.1/48 kHz; 16, 32 or 128 at other rates) to look ahead. That's the device's added latency.
- When a frame entering the delay peaks above the tracked peak (initially 0.985), the gain ramps down linearly over those L frames to
0.985 / peak, reaching it as that frame leaves. All channels share one gain. - The gain only recovers once the signal peaks at half the tracked peak or less: it rises by
e^(2.205/fs)per frame (about 19 dB/s) while the tracked peak decays by the same factor.
On Windows the device's software volume comes before the limiter; in PipeWire it comes after the device's filter graphs. So the plugin gets the volume of each channel (kept in sync by the module), measures peaks on the signal as it will be after the volume, and applies only its gain. Once PipeWire applies the volume, the result is the same as Windows'. Hardware volume comes after the limiter on both.
Development
make check # DSP and plugin tests, both modules modules/loudness/build/leq-wav [-r release] in.wav out.wav # process a file offline
