Windows 响度均衡,逆向工程并移植到 PipeWire
Windows Loudness Equalization, reverse-engineered and ported to PipeWire

原始链接: https://github.com/xoxorwr/pw-loudness-eq

pw-loudness-eq 为 PipeWire 带来 Windows 风格的响度均衡和输出限制。响度模块对每个应用程序的播放流应用宽带自动增益控制,平衡安静与响亮部分。限制器模块对每个播放设备应用前瞻限幅器,防止提升导致削波。可选的 GTK3 窗口(或 `pw-loudness-eq`)可全局或按应用启用/禁用功能并设置释放时间。设置保存在 PipeWire 元数据中,立即生效,并在重启后保留。它需要 PipeWire 1.4+ 和 GTK3;使用 `make`/`make install` 安装,然后重启 PipeWire 服务。某些流不会被处理,包括 JACK 客户端、超过八通道的流以及直接使用 PipeWire 的 Flatpak 应用。DSP 使用基于 FFT 的响度频带、目标增益、交叉淡入淡出和 N 采样延迟;限制器则将输出延迟 L 帧,在峰值处降低增益并逐渐恢复。还支持离线文件处理和测试。

一条 Hacker News 帖子介绍了一个逆向工程 Windows 响度均衡并移植到 PipeWire 的项目。评论者对其价值展开争论:有人不喜欢压平动态范围,也有人希望用它平衡多个应用程序和系统声音。一位用户询问它是否听起来和 Windows 完全一样;另一人称赞逆向工程,并推测未来操作系统功能可能变得可移植。一位音频工程师警告隐藏的系统级 EQ/压缩器,并希望它不会默认启用。还出现了许可问题,有回复称 Claude 批准了 MIT 使用。还有人询问 Windows 功能是否只是双频段 RMS 压缩器。总体而言,该讨论涉及实用性、保真度、专业音频问题以及法律/技术细节。
相关文章

原文

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.

The Loudness Equalization window

  • 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.

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.

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.

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.

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).

A broadband automatic gain control. Despite the name, it doesn't equalize the spectrum.

  1. Frame size N = 2^⌈log2(fs/100)⌉ (512 at 44.1/48 kHz), with 50% overlap.
  2. 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.
  3. 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.
  4. 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.
  5. Target gain = min((1300/L)^1.6, 10), so at most +20 dB.
  6. 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.
  7. 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.

Ported from CAudioLimiter in AudioEng.dll. audiodg.exe puts it on every render device, after its effects, before the device.

  1. 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.
  2. 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.
  3. 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.

make check                                              # DSP and plugin tests, both modules
modules/loudness/build/leq-wav [-r release] in.wav out.wav       # process a file offline
联系我们 contact @ memedata.com