| Crates.io | headroom |
| lib.rs | headroom |
| version | 1.4.2 |
| created_at | 2026-01-12 16:37:41.299882+00 |
| updated_at | 2026-01-23 09:38:56.663964+00 |
| description | Audio loudness analyzer and gain adjustment tool for mastering workflows |
| homepage | |
| repository | https://github.com/M-Igashi/headroom |
| max_upload_size | |
| id | 2038142 |
| size | 98,978 |
Audio loudness analyzer and gain adjustment tool for mastering and DJ workflows.
headroom simulates the behavior of Rekordbox's Auto Gain feature, but with a key difference: it identifies files with available headroom (True Peak below the target ceiling) and applies gain adjustment without using a limiter.
This tool is designed for DJs and producers who want to maximize loudness while preserving dynamics, ensuring tracks hit the optimal True Peak ceiling without clipping.
| Format | Extension | Method | Precision | Notes |
|---|---|---|---|---|
| FLAC | .flac | ffmpeg | Arbitrary | Lossless re-encode |
| AIFF | .aiff, .aif | ffmpeg | Arbitrary | Lossless re-encode |
| WAV | .wav | ffmpeg | Arbitrary | Lossless re-encode |
| MP3 | .mp3 | mp3rgain (built-in) | 1.5dB steps | Truly lossless (global_gain modification) |
| MP3 | .mp3 | ffmpeg re-encode | Arbitrary | For files needing precise gain |
| AAC/M4A | .m4a, .aac, .mp4 | ffmpeg re-encode | Arbitrary | Always requires re-encode |
headroom intelligently chooses the best method for each MP3 file:
For MP3 files with ≥1.5 dB headroom to bitrate-aware ceiling:
For MP3 files with headroom but <1.5 dB to ceiling:
Files already at or above the target ceiling are not processed.
AAC/M4A files are supported with the following characteristics:
Same principles apply as MP3 re-encoding:
Based on AES TD1008 recommendations:
| Format | Method | Ceiling | Rationale |
|---|---|---|---|
| Lossless (FLAC, AIFF, WAV) | ffmpeg | -0.5 dBTP | Will be distributed via high-bitrate streaming |
| MP3 ≥256kbps (lossless) | mp3rgain | -0.5 dBTP | Requires TP ≤ -2.0 dBTP for 1.5dB steps |
| MP3 <256kbps (lossless) | mp3rgain | -1.0 dBTP | Requires TP ≤ -2.5 dBTP for 1.5dB steps |
| MP3 ≥256kbps (re-encode) | ffmpeg | -0.5 dBTP | High-bitrate codecs have minimal overshoot |
| MP3 <256kbps (re-encode) | ffmpeg | -1.0 dBTP | Lower bitrates cause more codec overshoot |
| AAC ≥256kbps | ffmpeg | -0.5 dBTP | High-bitrate AAC has minimal overshoot |
| AAC <256kbps | ffmpeg | -1.0 dBTP | Lower bitrates cause more codec overshoot |
$ cd ~/Music/DJ-Tracks
$ headroom
╭─────────────────────────────────────╮
│ headroom v1.4.1 │
│ Audio Loudness Analyzer & Gain │
╰─────────────────────────────────────╯
▸ Target directory: /Users/xxx/Music/DJ-Tracks
✓ Found 28 audio files
✓ Analyzed 28 files
● 3 lossless files (ffmpeg, precise gain)
Filename LUFS True Peak Target Gain
track01.flac -13.3 -3.2 dBTP -0.5 dBTP +2.7 dB
track02.aif -14.1 -4.5 dBTP -0.5 dBTP +4.0 dB
track03.wav -12.5 -2.8 dBTP -0.5 dBTP +2.3 dB
● 2 MP3 files (native lossless, 1.5dB steps, target: -2.0 dBTP)
Filename LUFS True Peak Target Gain
track04.mp3 -14.0 -5.5 dBTP -2.0 dBTP +3.0 dB
track05.mp3 -13.5 -6.0 dBTP -2.0 dBTP +3.0 dB
● 2 MP3 files (re-encode required for precise gain)
Filename LUFS True Peak Target Gain
track06.mp3 -12.0 -1.5 dBTP -0.5 dBTP +1.0 dB
track07.mp3 -11.5 -1.2 dBTP -0.5 dBTP +0.7 dB
● 2 AAC/M4A files (re-encode required)
Filename LUFS True Peak Target Gain
track08.m4a -13.0 -2.5 dBTP -0.5 dBTP +2.0 dB
track09.m4a -12.5 -1.8 dBTP -0.5 dBTP +1.3 dB
✓ Report saved: ./headroom_report_20250109_123456.csv
? Apply lossless gain adjustment to 3 lossless + 2 MP3 (lossless gain) files? [y/N] y
ℹ 2 MP3 + 2 AAC/M4A files have headroom but require re-encoding for precise gain.
• Re-encoding causes minor quality loss (inaudible at 256kbps+)
• Original bitrate will be preserved
? Also process these files with re-encoding? [y/N] y
? Create backup before processing? [Y/n] y
✓ Backup directory: ./backup
✓ Done! 9 files processed.
• 3 lossless files (ffmpeg)
• 2 MP3 files (native, lossless)
• 2 MP3 files (re-encoded)
• 2 AAC/M4A files (re-encoded)
| Platform | Command |
|---|---|
| macOS | brew install M-Igashi/tap/headroom |
| Windows (Scoop) | scoop bucket add headroom https://github.com/M-Igashi/scoop-bucket && scoop install headroom |
| Windows (Binary) | Download from Releases |
| All platforms | cargo install headroom + install ffmpeg |
headroom requires one external tool:
Note: As of v1.3.0, mp3rgain is built-in as a library dependency. No separate installation required. v1.4.1 uses mp3rgain 1.4.0.
brew install M-Igashi/tap/headroom
ffmpeg is installed automatically as a dependency.
scoop bucket add headroom https://github.com/M-Igashi/scoop-bucket
scoop install headroom
ffmpeg is installed automatically as a dependency.
If you have Rust installed, you can install headroom via cargo:
cargo install headroom
Then install ffmpeg for your platform:
# macOS
brew install ffmpeg
# Ubuntu/Debian
sudo apt install ffmpeg
# Fedora
sudo dnf install ffmpeg
# Arch
sudo pacman -S ffmpeg
# Windows (winget)
winget install ffmpeg
# Windows (choco)
choco install ffmpeg
Download pre-built binaries from the Releases page:
| Platform | File |
|---|---|
| macOS (Universal) | headroom-vX.X.X-macos-universal.tar.gz |
| Linux x86_64 | headroom-vX.X.X-linux-x86_64.tar.gz |
| Linux ARM64 | headroom-vX.X.X-linux-aarch64.tar.gz |
| Windows x86_64 | headroom-vX.X.X-windows-x86_64.zip |
Note: You must install ffmpeg separately (see platform-specific commands above).
git clone https://github.com/M-Igashi/headroom.git
cd headroom
cargo build --release
# Binary location:
# - Unix: target/release/headroom
# - Windows: target\release\headroom.exe
cd ~/Music/DJ-Tracks
headroom
The tool will guide you through:
| Filename | Format | Bitrate (kbps) | LUFS | True Peak (dBTP) | Target (dBTP) | Headroom (dB) | Method | Effective Gain (dB) |
|---|---|---|---|---|---|---|---|---|
| track01.flac | Lossless | - | -13.3 | -3.2 | -0.5 | +2.7 | ffmpeg | +2.7 |
| track04.mp3 | MP3 | 320 | -14.0 | -5.5 | -2.0 | +3.5 | mp3rgain | +3.0 |
| track06.mp3 | MP3 | 320 | -12.0 | -1.5 | -0.5 | +1.0 | re-encode | +1.0 |
| track08.m4a | AAC | 256 | -13.0 | -2.5 | -0.5 | +2.0 | re-encode | +2.0 |
./
├── track01.flac ← Modified
├── track04.mp3 ← Modified
├── track08.m4a ← Modified
├── subfolder/
│ └── track06.mp3 ← Modified
└── backup/ ← Created by headroom
├── track01.flac ← Original
├── track04.mp3 ← Original
├── track08.m4a ← Original
└── subfolder/
└── track06.mp3 ← Original
._*) are automatically ignoredThe MP3 format stores a "global_gain" value as an 8-bit integer (0-255). When decoding, samples are multiplied by 2^(gain/4):
2^(1/4) = +1.5 dB2^(-1/4) = -1.5 dBThis is a fundamental limitation of the MP3 format, not a tool limitation. headroom uses the built-in mp3rgain library to directly manipulate this field in each MP3 frame's side information.
With 1.5dB step limitation, the ceiling is calculated based on bitrate to match re-encode targets:
Unlike MP3, AAC doesn't have a lossless gain adjustment mechanism like the global_gain field. The only way to apply gain to AAC files is through re-encoding. However, at high bitrates (≥256kbps), the quality loss is imperceptible.
When re-encoding is chosen:
libmp3lame encoder with -q:a 0 (best VBR quality)libfdk_aac (highest quality), falls back to built-in aac encoderAt 320kbps, the re-encode introduces quantization noise below -90dB—far below audible threshold.
| Method | Format | Precision | Quality Loss | External Deps | Use Case |
|---|---|---|---|---|---|
| ffmpeg (lossless) | FLAC, AIFF, WAV | Arbitrary | None | ffmpeg | Lossless files |
| mp3rgain (built-in) | MP3 | 1.5dB steps | None | None | MP3 with ≥1.5dB to bitrate ceiling |
| ffmpeg re-encode | MP3 | Arbitrary | Inaudible at ≥256kbps | ffmpeg | MP3 needing precise gain |
| ffmpeg re-encode | AAC/M4A | Arbitrary | Inaudible at ≥256kbps | ffmpeg | AAC files (always) |
MIT