gain

By Hal Canary, 2009-08-29 09:49:02 (link)
#computers-code;#music

Back on the CD-ripping project. For popular music, the album titles and artists names are easy and the online databases almost always give me the right answer. But for classical music, there are always discrepancies. So I always change the artist field to be Composer, Performers.

After ripping a few CDs with Sound Juicer, I then run mp3gain (sudo apt-get install --yes mp3gain) on the album.

#!/bin/sh
## ~/bin/mp3gain-a-directory
## Written 2009 Hal Canary, #DTPD#
renice 10 $$ > /dev/null
for dir in "$@" ; do
  if [ ! -d "${dir}" ] ; then
    echo "'${dir}' is not a directory" >&2
  else
    if ( /bin/ls "${dir}/"*.mp3 > /dev/null 2>&1 ) ; then
      /usr/bin/mp3gain -k -a "${dir}/"*.mp3
    else
      echo "'${dir}' has no .mp3 files in it." >&2
    fi
  fi
done

That little script takes a list of directories as arguments, treats all of the mp3 files in a directory as an album and applies the same gain (-a) to each mp3 file in the directory. The -k tells it “of course I don't want to clip the sound; don't ask me every time.” Since this operation is processor- and I/O-intensive, the renice is always appreciated.

Or, if I want to all of the directories at once, I can run this command:

find "${HOME}/Music/CDs" -type d -exec mp3gain-a-directory "{}" \;

mp3gain is nice in that it notices that it's already modified a mp3 and won't waste time on it again.


(back)