Using MPD for ReplayGain

2021-01-05
,

Something like ~10 years ago, there was no easy way to apply ReplayGain to various audio files with different formats (e.g., flac vs mp3). Over the holiday break I discovered r128gain which is exactly the tool I wanted for many years. You just run

r128gain -r <folder>

and it will recursively tag all music files with ReplayGain information — in parallel, no less!

The only downside is that neither cmus nor mpv currently support the R128_TRACK_GAIN tag that r128gain generates (at least for *.opus files).1 However, I discovered that MPD (Music Player Daemon) supports R128_TRACK_GAIN.2 MPD is easy to start up and the basic minimal configuration was small enough:

music_directory     "~/Music"
# Automatically prune new/deleted files in the music_directory.
auto_update         "yes"

# Allow saving playlists from vimpc.
playlist_directory  "~/Music/playlists"

audio_output {
    type            "pulse"
    name            "My Pulse Output"
}

# Enable replay gain.
replaygain          "track"

As far as actually controlling MPD, I settled on vimpc — because Vi-like keybindings are too good to pass up.

Cheers!


  1. To be precise, cmus has a commit in master that adds support, and mpv has an open issue for it. And I’m too lazy to compile cmus from source.↩︎

  2. I had actually used MPD back in the day, but switched to cmus because it was simpler. And because cross-format ReplayGain tagging software was not available, MPD’s support for ReplayGain wasn’t very meaningful for me.↩︎