- Python 95.2%
- Shell 4.8%
| tests | ||
| .gitignore | ||
| drcd | ||
| install.sh | ||
| LICENSE | ||
| README.md | ||
drcd
Dynamic Range (DR) meter for audio CDs and audio files — measures DR on the same scale as https://dr.loudness-war.info (the DR14 / Pleasurize Music Foundation / TT Dynamic Range Meter scale), so the numbers are directly comparable with the values published on that site.
Pop a CD in the drive, run one command, read the DR number off the screen:
$ drcd
Ripping with cdparanoia … ✓ 12 tracks
[ 1/12] 01 - Track name DR12
...
[12/12] 12 - Track name DR9
/media/cdrom (HL-DT-ST DVDRAM GP65NB60)
# DR Peak dB RMS dB Length Title
--------------------------------------------------------------------
1 DR12 -0.20 -14.35 3:45 01 - Track name
...
12 DR9 -0.09 -12.02 4:11 12 - Track name
--------------------------------------------------------------------
Album DR 11 (tracks 12, min 7, max 14)
measured in 3:41
log: /home/you/DR-logs/Artist - Album - DR.txt
The number to write down when comparing two copies is the Album DR (the same figure loudness-war.info lists in its "DR" column, with min/max as the per-track extremes).
Install
Needs python3 + numpy, ffmpeg, and a CD ripper if you want to read
discs. ./install.sh installs the script into ~/.local/bin, checks the
dependencies and solves the awkward one (numpy) by itself.
Linux (Arch / CachyOS / Debian / Ubuntu …)
sudo pacman -S python-numpy ffmpeg cdparanoia # Arch / CachyOS / Manjaro
sudo apt install python3-numpy ffmpeg cdparanoia # Debian / Ubuntu / Mint
./install.sh
Drive permissions (once): your user must be able to read /dev/sr0. On Arch
add yourself to the optical group and re-login; on Debian it is cdrom:
sudo usermod -aG optical "$USER"
After pulling updates, run ./install.sh again (or invoke the copy in the
repo, ./drcd): ~/.local/bin/drcd is a copy, so an updated repo does not
change the installed command until you re-install it. A log's first line names
the version that produced it (drcd 1.2.0 — DR14 (…)), which is the quickest
way to tell whether you are running the version you think you are.
macOS
brew install ffmpeg libcdio-paranoia # note: there is no brew cdparanoia formula
git clone ssh://git@git.hofburg.pub:2222/kaiser/drcd.git
cd drcd && ./install.sh # also makes a private venv holding numpy
drcd # disc in the drive — no device argument
macOS specifics, all of which the tool already handles:
- Ripping. Homebrew doesn't package
cdparanoia;libcdio-paranoiaprovidescd-paranoia— the same Paranoia 10.2 code on top of libcdio, with the same options (-Q,-B,-w,-Z,-X) and the same printed output, so the rip and the measurement are identical.drcdlooks for either name. MacPorts alternative if you prefer the Xiph build:sudo port install cdparanoia. - No
--deviceneeded. macOS has no/dev/sr0;drcddetects that and lets the ripper find the drive itself (cdparanoia -Qwith no-d). - The drive. Modern Macs have none built in — use any USB CD/DVD drive. macOS shows it as an "Audio CD" and Music.app may offer to import it; that doesn't interfere, but you can stop it in Music → Settings → General → When you insert a CD.
- python3. Apple only ships
python3once the developer tools are installed:xcode-select --install(orbrew install python). Check withpython3 -Vbefore you install drcd, since the venv below is built with it. - numpy. macOS ships no numpy, and Homebrew's python refuses global pip
installs (PEP 668, "externally managed environment"). So
install.shcreates a private venv at~/.local/share/drcd/venvwith numpy in it, anddrcdre-execs itself into that interpreter automatically when the python3 it started under has no numpy. Nothing to export, no--break-system-packages. (Preferred alternative:brew install python numpy, then it isn't needed.) - Eject.
drcd --ejectusesdrutil tray ejecton macOS,ejecton Linux. - Apple Silicon vs Intel. Nothing to configure — whichever Homebrew prefix
your PATH points at (
/opt/homebrewor/usr/local) is used.
No ripper at all? You can still measure: Music.app rips bit-exactly to ALAC or AIFF with error correction enabled (Music → Settings → Files → Import Settings → "Use error correction when reading Audio CDs"), and then
drcd ~/Music/Music/Media.localized/Music/<Artist>/<Album>
measures those files — ffmpeg and numpy are the only extras it needs.
Set the import format to AIFF or Apple Lossless first: Music.app's default is AAC, which is lossy, and a DR measured from a lossy encode is not the CD's DR (it can also differ by a point from another tool's rip of the same file). Third-party rippers work just as well — XLD is the usual macOS choice and can write FLAC, which Music.app cannot.
Usage
drcd # rip the CD in the drive and measure it
drcd /dev/sr1 # pick a specific drive (Linux; USB drives: check ls /dev/sr*)
drcd ~/Music/Album # measure a folder of files (FLAC/WAV/MP3/…)
drcd track1.flac track2.flac # measure specific files
drcd --mb # CD mode: MusicBrainz titles (this is the default)
drcd --no-mb # never contact MusicBrainz (works offline)
drcd --keep-rip ~/rips # CD mode: also keep the ripped WAV files
drcd --history # show every measurement so far
drcd -j # JSON output (for scripting)
drcd --fast # skip cdparanoia's error correction (quicker, riskier)
drcd --strict # treat a scratched/unreadable track as a failure
On macOS, omit --device entirely — the drive is autosensed.
Useful extras: --artist / --album (name the disc yourself instead of
MusicBrainz), --eject, --no-log, --log FILE, --outdir DIR
(default ~/DR-logs), --no-color, --resample 44100, --blocks exact.
Use --strict when you are comparing two copies and want to be sure a
scratched disc can't win on a mis-read: cdparanoia normally interpolates over
unreadable sectors (and the exit status warning tells you when that happened).
Log files are written in the plain-text DR log format that
dr.loudness-war.info accepts for uploads ("DR/Peak/RMS/Duration/Title",
Number of tracks, Official DR value). If a log with the same name
already exists, the new one gets a timestamp appended instead of overwriting.
Comparing two copies of the same CD
That is what the history file is for. Run the tool on copy A, then on copy B; on the second run you get:
NOTE: this disc was measured before:
2026-10-11 18:22 DR9 Stevie Ray Vaughan / Texas Flood identical
keep the copy with the higher DR.
Copies are recognized three ways, in order of confidence:
- the disc's own table of contents (the MusicBrainz disc ID) — the same pressing;
- artist + album — another pressing of the same album, which has a
different TOC and therefore a different disc ID. These names come from
MusicBrainz (on by default in CD mode, see below) or from
--artist/--album; - the album's shape — with no metadata and no network at all: same track
count (4+) and every track within 2 seconds. The note then says
matched by same track layout (another pressing?)so you can see why it matched.
Real example: two copies of Texas Flood (SRV) — different pressings, so
different disc IDs and, with --no-mb, no names either. They matched on
layout and both measured album DR 13 (tracks 12,13,14,13,12,11,15,13,13,14),
i.e. a tie: keep either.
drcd --history prints the whole log; drcd --history "pink floyd" filters it.
MusicBrainz lookup (on by default for CDs)
In CD mode drcd asks MusicBrainz for the artist, album and track titles
using the disc's table of contents — so logs carry real titles and the
comparison above works across pressings. Details:
- Needs the TOC, so it can't work when the TOC itself is unreadable (it says so and carries on).
- Rate-limited by MusicBrainz to about one request/second, so it retries the
503/429"server is busy" responses a few times before giving up. - One disc ID can be attached to several releases (original pressing, reissue,
SACD layer…).
drcdprefers the medium that actually lists your disc ID, a plain CD over an SACD layer, a track count matching your disc, and the earliest date. - The outcome is printed and written to the log, so a log is self-documenting:
MusicBrainz lookup: Stevie Ray Vaughan and Double Trouble — Texas Flood (1983, CD)orunavailable (HTTP 503) — no titles. --no-mbdisables it entirely (nothing leaves the machine);--artist/--albumoverride or supply the names yourself.
Empty and silent files are not tracks
cdparanoia's batch mode sometimes writes a bogus track00.cdda.wav before
track 1 — documented behavior, and it depends on the drive, not the disc
(usually a fraction of a second of silence, sometimes a few seconds of it).
Digital silence scores DR 0, so left alone it drags the album average down and
makes two copies of the same album look different.
drcd therefore ignores any ripped file that is shorter than 0.5 s or that
contains nothing but silence: it stays out of the table and out of the album
DR. The runs that produce one say so:
[ 9/ 9] track 00 ignored — empty file (0.1 s)
...
Album DR 12 (tracks 8, min 11, max 14, 1 empty/silent ignored)
ignored: track 00 — empty file (0.1 s) (not counted in the album DR)
and the log records the same under Ignored:, so nothing is silently dropped.
Titles are keyed by the disc's own track number (taken from the file name), so
a phantom file can't shift every title by one either.
What the numbers mean
- DR — for each track, the level difference in dB between the track's near-highest peak and the RMS level of its loudest 20% (in 3-second blocks), averaged over the channels. Higher = more dynamics preserved.
- Peak dB — highest sample level (0 dB = digital full scale).
overmeans the file contains samples above full scale (clipping/intersample peaks); the master is probably clipped. - RMS dB — average level of the whole track.
- Rough guide used on loudness-war.info: for rock/metal, DR 8+ is considered fine; DR 5–7 is heavily compressed; DR 3–4 is a brick; classical/jazz can reach DR 14–20.
A CD rip is bit-exact, so the DR you measure from a disc is the DR of that pressing. Two pressings of the "same" album (or a CD vs. a later remaster) often differ by several DR points — that is the whole point of this tool.
Algorithm (and why the numbers should match the site)
This is a faithful re-implementation of the published DR14 procedure used by the TT DR Offline Meter (the tool behind the DR database) and by dr14_t.meter (the reference Linux implementation):
- Split the track into blocks of 3 seconds (non-overlapping).
- Per block and channel:
peak = max|x|,rms = sqrt(2*Σx²/N)— the √2 makes a full-scale sine read 0 dB on both, which is the meter's internal convention. - Sort blocks by RMS; take the loudest
K = max(1, floor(0.2*M))blocks and average their power:R = sqrt(Σ rms²/K). - Reference peak = the second-highest block peak (skipping the single highest makes it robust against one isolated click).
DR_channel = 20*log10(reference_peak / R); silent or out-of-range channels count as 0; the track's DR is the mean over channels, rounded.- Track peak/RMS are the true maxima/averages over the file; the album ("Official") DR is the rounded mean of the track DRs, exactly like the reference tools.
Deliberate quirks kept for compatibility: at 44.1 kHz the classic meter uses
132480-sample blocks (3.0041 s), i.e. 3×(44100+60) — this is what
--blocks old (the default) reproduces. --blocks exact uses plain 3*fs
blocks, which is what the Windows meter effectively measures after it
resamples to 44.1 kHz; on real music the two usually agree to the same
integer, and in our tests they never disagreed.
Validation
Measured with this script, compared against the reference tools and against values published on dr.loudness-war.info:
| Material | Reference | Reference result | drcd result |
|---|---|---|---|
| 5 synthetic signals (sine, decaying bursts, limited mix, quiet/loud noise) | dr14_t.meter 2.1.1 | DR 0/0/2/10/14, peaks & RMS to 0.01 dB | identical |
| Nine Inch Nails, Ghosts V tracks 01/02/05, official MP3 download | published on dr.loudness-war.info (log by Dr14 T.meter 1.0.16) | DR 8 / 9 / 5, peaks −0.00 / −0.21 / −0.09 dB | DR 8 / 9 / 5, same peaks |
| 20-minute 44.1 kHz file | dr14_t.meter 2.1.1 | DR 10, peak −4.26 dB, RMS −18.14 dB | identical |
| 6-track "CD" (44.1 kHz 16-bit) | dr14_t.meter 2.1.1 | DR 14/2/10 each, peaks/RMS identical | identical |
| same material, resampled to 44.1 kHz | simple-dr-meter (independent implementation, loudness-war-compliant) | DR 8 / 9 / 5 | DR 8 / 9 / 5 |
Other checks: 74-minute CD-length file measured in 24 s with 57 MB peak RSS
(the file is streamed, never fully loaded); a silent track yields DR 0
instead of a crash; a 0.02 s file is handled; a MusicBrainz disc ID computed
from a cdparanoia -Q table of contents matches MusicBrainz's own published
test vector.
Two test files ship with it:
| Test | Covers |
|---|---|
tests/test_drcd_core.py |
disc-ID vector, TOC parser, album-DR rounding, block lengths, live MusicBrainz lookup |
tests/test_cd_path.py |
the whole CD path against a stub ripper: Linux layout, macOS layout (cd-paranoia only, no /dev/sr*, autosensed drive), explicit device, unparseable TOC, read-error exit status |
tests/test_cd_path.py needs no optical drive — it fakes one — and its key
assertion is an invariant rather than a hardcoded number: measuring a disc
must give exactly the same DR values as measuring the same audio as plain
files, which catches any bug in the rip/wiring path.
Not yet verified on real hardware: the CD path was developed where no
optical drive existed (Linux container) and no Mac was available, so the
cdparanoia invocation, the TOC parsing and the macOS autosense path have only
been tested against the tools' documented output (including their source) plus
a simulated drive in both layouts. If the first real run misbehaves, the
useful diagnostics are drcd --verbose and cdparanoia -Q / cd-paranoia -Q
run by hand.
Known limits
- Pre-emphasis and HDCD flags on a disc are not applied (a pre-emphasised CD will measure a few tenths of a dB differently than a de-emphasised rip).
- MP3/AAC sources measure the decoded audio; decoders differ by a hair, so lossy values can wobble by ±1 DR versus somebody else's rip of the same file.
- The last sample of a file is ignored in the block analysis — inherited from the reference implementation on purpose (it changes nothing measurable).
- Measuring takes roughly 1–2 minutes per CD (rip time dominates on slow drives; analysis is ~8 s for a full disc on a modern CPU).
License
GPL-3.0-or-later — see LICENSE. The measurement procedure is the one
documented by the Pleasurize Music Foundation and implemented by the
GPL-licensed dr14_t.meter and simple-dr-meter projects, so this
implementation is released under the same terms.