Automatic equalizing of MP3 volume level
MP3 is great, but there is something annoying: MP3 files from different
sources are usually not recorded at the same volume level. This makes them
inappropriate for unattended music boxes because the volume may change randomly
from song to song by a substantial amount. If you don't have the volume control
handy it might be very unpleasant, at least.
One might use the, per file, preamp or gain adjustment that many mp3
players incorporate as a feature. The problem here is to adjust by ear the gain
of literally hundreds or thousands of mp3 files. You have to listen carefully
to all of them and compare, who has time for that? :-)
I searched Internet for a player or a utility to solve this problem with no
success. While it seems there are some programs able to do this task, actually
they have some inconveniences: some do not handle mp3, some do it only when
writing to an audio CD and some are commercial programs you have to buy.
Nevertheless I did not search either exhaustively or for long time, therefore I
might have missed a good solution. I did not employ much time searching because
it seemed so simple to me that I decided to do it myself.
My usual setup is a Linux box which automatically starts playing music with
XMMS at boot (it shuts down simply with the
sequence Ctrl-Alt-F1 + Ctrl-Alt-Del, so no monitor is needed), thus I chose to
make use of the auto-load preset feature of this nice player. So I only needed
a program to generate automatically the preset file. Here is where my
Volume level perception by human ear depends on the RMS value of the audio
signal logarithmically. Therefore I just had to write a program to calculate
the rms value of each file and generate the appropriate preset file. Actually
the audio utility sox already calculates rms since recent versions.
The program which generates the preset file is the csh script mkpreset. You just have to run mkpreset in the same
directory where xmms.m3u lies (don't forget to set the execution permission,
the download will remove it). Of course I designed it to run on linux, but
surely will run without problems on any other UNIX. The script needs the mpg123 and sox utilities as well as other standard
unix commands. Those utilities come with any Linux distribution or any other
unix (or at least the source code is available and compilable). They should
also be in the execution path.
The script is specially prepared for mp3 because so is the vast majority of
music files out there, but it works with any other kind of music files as long
as they are supported by sox.
You have to take into account two things about the playlist file xmms.m3u:
first, file names should be unique because xmms bases its preset file only in
the names (it excludes paths); second, the character '%' should not appear in
the file, otherwise rename the files containing that character or replace it in
the script for other character not present in the file.
The auto-load preset file, eq.auto_preset, is left in the working directory
after the script is done. Then you just have to copy it to the .xmms directory
in the home directory of the user(s) who wants to run xmms with the playlist
xmms.m3u automatically equalized in volume. Of course you have to activate the
equalizer and the auto-load feature in xmms (click on the 'on' and 'auto'
buttons in the equalizer window).
If you get more music files after you generated your preset file you don't
need to run mkpreset over all files again, something which can be quite time
consuming if you have lots of files. Better generate a second preset file only
for the new files but passing two arguments to mkpreset. The first one has to
be the final volref value mkpreset displayed on screen when you run it for the
first preset file. The second argument has to be the number of the first preset
entry to generate, that is, add one to the last preset entry in your former
preset file. Don't forget to rename your old preset file if you are running
mkpreset in the same directory, otherwise you will loose it because mkpreset
will silently overwrite it. When you have both preset files you just have to
merge them by hand, it shouldn't be difficult. Nevertheless I recommend to use
mkpreset for all files in one run (whenever possible) because this will
optimize the dynamic range (xmms preamp is limited to the range from -20dB to
As a closing remark I should say that the automatic equalizing is not
perfect, it reduces differences but sometimes not enough. In some cases the
differences in volume are still noticeable. I don't know the reason yet, I
believe it is related to the sound spectrum. RMS is calculated using the same
weight for all data in the sample, however music equipment doesn't have a flat
response. For those cases you can fine tune by hand. I keep looking for
E-mail: padilla at
domain "gae ucm es" (my PGP/GPG public key)
First version: 26-Aug-2002, last update: 26-Oct-2005
This link: http://www.gae.ucm.es/~padilla/extrawork/mp3.html
Go to the parent page: Cheap Hi-Tech.