Tracks that are too loud and too soft

dos2unix

Well-Known Member
Joined
May 3, 2019
Messages
4,408
Reaction score
4,601
Credits
41,638
Formatted, and assisted by Claude Ai. Prompted by myself.

Taming the Volume Wars: ReplayGain on Linux with Strawberry and r128gain

If you've ever been listening to a playlist and found yourself lunging for the volume knob every few songs, you've experienced the loudness problem firsthand. One track is barely audible, the next blasts you out of your chair. This isn't your imagination or your speakers — it's the result of decades of inconsistent audio mastering, and it affects every music collection of any size.

The fix is called ReplayGain, and on Linux it's surprisingly easy to implement. This article walks through the complete workflow: understanding the problem, tagging your files with r128gain, configuring Strawberry to use those tags, and verifying everything with eyeD3.


The Loudness War

From the 1990s onward, the music industry engaged in what audio engineers call the "loudness war." Record labels and mastering engineers pushed the average loudness of recordings higher and higher, believing louder tracks would stand out on radio and in stores. The result was music that was heavily compressed and limited — dynamic range was sacrificed to maximize perceived volume.

The numbers tell the story clearly. Here's a real-world comparison from a mixed music collection, showing the ReplayGain adjustment needed to normalize each track to a consistent loudness:

Artist / TrackEraTrack GainPeak Level
Benjamin Orr — Stay The Night1984 (remaster)-12.00 dB1.000
Heavy Duty Projects — Kaleidoscope BlissModern-11.50 dB1.000
Lee Ann Womack — I Hope You Dance2000-7.40 dB1.000
Neil Diamond — Stones1971+0.50 dB0.757
Olivia Newton-John — I Honestly Love You1974-0.90 dB0.585
The Stylistics — You Make Me Feel Brand New1974+1.20 dB0.756
Vince Gill — Look At Us1991+2.00 dB0.623
Tim McGraw — She's My Kind of Rain2002+2.80 dB0.712

Notice the pattern. Tracks from the 1970s have peak levels well below maximum and need only minor adjustment. Modern and remastered tracks are slammed against the 1.000 ceiling — fully brick-walled — and need to be pulled down by 7 to 12 dB. Without ReplayGain, jumping from Benjamin Orr to Vince Gill means your ears experience a 14.8 dB swing. That's enormous.


What ReplayGain Actually Does

ReplayGain solves this non-destructively. It analyzes each audio file, calculates how much louder or quieter it is relative to a reference loudness level, and stores that adjustment as metadata tags directly in the file. The audio data itself is never touched.

When a ReplayGain-aware player (like Strawberry) plays the file, it reads those tags and adjusts the playback volume on the fly. You get consistent loudness across your entire collection without permanently altering your files.

Two gain values are calculated and stored:

Track gain — normalizes each song independently. Best for shuffle and mixed playlists.
Album gain — normalizes the album as a whole, preserving intentional dynamic contrast between tracks. Best for listening to full albums as the artist intended.

Both values can be stored simultaneously, and your player can be configured to use whichever is appropriate.

The tags written to your files look like this:

Code:
REPLAYGAIN_TRACK_GAIN = -7.40 dB
REPLAYGAIN_TRACK_PEAK = 1.000000
REPLAYGAIN_ALBUM_GAIN = -6.80 dB
REPLAYGAIN_ALBUM_PEAK = 1.000000


Installing r128gain

r128gain is a Python-based command-line tool that handles MP3, FLAC, OGG, and Opus files. Because it's a pip package, installation is identical across all major distros:

Code:
pip3 install r128gain --break-system-packages

Verify the install:

Code:
r128gain --version

Note: r128gain is not available in most distro repos as of this writing. The pip route is the most reliable cross-distro approach. An alternative is loudgain, which requires compiling from source on Fedora but is available via apt on Debian/Ubuntu and pacman on Arch.


Tagging Your Files

Single file:

Code:
r128gain song.mp3

All files in a directory:

Code:
r128gain -r ~/Music

Recursive with album gain tags:

Code:
r128gain -r -a ~/Music

The -r flag scans recursively through subdirectories. The -a flag adds album gain tags in addition to track gain — recommended if you listen to full albums.

On a modern system, r128gain processes files quickly — a batch of 200 MP3s completes in under 30 seconds. For large collections the recursive command can be left running unattended. Since it's pure local CPU processing with no network dependency, there are no rate limits or interruption concerns.


Configuring Strawberry

Strawberry Music Player is the recommended Linux music player for collections of this type — actively maintained, excellent format support, and first-class ReplayGain handling.

To enable ReplayGain playback in Strawberry:

1. Open Settings (toolbar or Edit menu)
2. Navigate to Playback
3. Locate the ReplayGain section
4. Set mode to Track (for playlists/shuffle) or Album (for full album listening)
5. Ensure it is not set to Disabled

Once enabled, Strawberry reads the gain tags written by r128gain and applies the volume adjustment transparently during playback.


Verifying Tags with eyeD3

eyeD3 is a Python-based ID3 tag editor that can read and write metadata for MP3 files. It's useful for confirming that ReplayGain tags were written correctly.

Install on Fedora:

Code:
sudo dnf install eyeD3

On Debian/Ubuntu/Mint:

Code:
sudo apt install eyed3

Check a single file:

Code:
eyeD3 'Lee Ann Womack - I Hope You Dance.mp3' | grep -A1 -i replay

Output:

Code:
UserTextFrame: [Description: REPLAYGAIN_TRACK_GAIN]
-7.40 dB
UserTextFrame: [Description: REPLAYGAIN_TRACK_PEAK]
1.000000

To check all MP3s in a directory with filename headers:

Code:
for i in *.mp3; do echo "=== $i ==="; eyeD3 "$i" | grep -A1 -i replay; done

Pipe to less for long collections:

Code:
for i in *.mp3; do echo "=== $i ==="; eyeD3 "$i" | grep -A1 -i replay; done | less

Save to a file for reference:

Code:
for i in *.mp3; do echo "=== $i ==="; eyeD3 "$i" | grep -A1 -i replay; done > replaygain_report.txt


Finding Outliers

This script identifies tracks with extreme gain values — loudness war victims at -7 dB or below, and quietly mastered tracks at +1 dB or above:

Code:
for i in *.mp3; do
  gain=$(eyeD3 "$i" | grep -A1 "REPLAYGAIN_TRACK_GAIN" | tail -1)
  echo "$gain|$i"
done | awk -F'|' '{
  gsub(/ dB/,"",$1); val=$1+0
  if(val <= -7) print "LOUD: " $2 " -> " $1 " dB"
  else if(val >= 1) print "QUIET: " $2 " -> " $1 " dB"
}'

Sample output from a real collection:

Code:
LOUD: Benjamin Orr - Stay The Night (HQ).mp3 -> -12.00 dB
LOUD: Heavy Duty Projects - Kaleidoscope Bliss.mp3 -> -11.50 dB
LOUD: Lee Ann Womack - I Hope You Dance.mp3 -> -7.40 dB
QUIET: The Stylistics - You Make Me Feel Brand New.mp3 -> 1.20 dB
QUIET: Vince Gill - Look At Us.mp3 -> 2.00 dB
QUIET: Tim McGraw - She's My Kind of Rain.mp3 -> 2.80 dB


Handling Large Collections

For collections of several thousand files, a full recursive scan is practical with a few strategies:

Process in batches by artist or letter. Navigate to your Music directory and process alphabetically, making it easy to track progress and resume if interrupted.

Skip already-tagged files. r128gain checks for existing ReplayGain tags by default and skips files that are already tagged. You can safely re-run it without double-processing.

Drum tracks and instrumentals. ReplayGain scanning works purely on audio data — no metadata required. These files will be processed correctly regardless of missing artist or title tags.

FLAC, OGG, and Opus files. r128gain handles all of these natively and writes the correct tag format automatically. eyeD3 is MP3-specific — for verifying FLAC or OGG tags use metaflac or vorbiscomment respectively.


Summary

The complete workflow:

1. Install r128gain via pip
2. Run r128gain -r -a ~/Music to tag your collection
3. Enable ReplayGain in Strawberry's playback settings
4. Optionally verify tags with eyeD3 and the batch scripts above

The result is a music collection that plays at consistent volume regardless of when or how the tracks were mastered — no more reaching for the volume knob mid-playlist.

Tested on Fedora 43 with Strawberry and r128gain 1.0.7.

EDIT::
Note: Not all players support ReplayGain tags. If your player doesn't recognize them, it will simply play files at their original recorded volume and the tags are ignored. I tested this on my 2025 car's USB media player — even on a fairly new head unit, the ReplayGain tags were not honored. Loud tracks stayed loud, quiet tracks stayed quiet, and I was back to adjusting the volume manually between songs. ReplayGain is most reliable on software players like Strawberry on Linux, or other ReplayGain-aware applications on desktop and mobile.
 


If your player doesn't recognize them, it will simply play files at their original recorded volume and the tags are ignored.

Some players also have normalization in them. There's even an option for it on YouTube -- except it doesn't always appear.

Not too long ago, I gave someone directions on how to do so in VLC.
 
The "Loudness Wars" were an audiophile's worst nightmare. To learn more about the science behind why, and why it even happened (maybe still is?; and mentioned in the OP) read the link below. As you can see from the website address, it was written 13½ years ago as it was in full swing.

Over The Limit - Ceiling Unlimited
 


Follow Linux.org

Members online


Top