R128GAIN

Copyright © 2011, 2012 by Peter Belkner (http://home.snafu.de/pbelkner/)

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

R128GAIN is a FFmpeg and SoX based EBU R128 compliant loudness scanner. It helps you normalizing the loudness of your audio and video files to the same level.

Home:   http://r128gain.sourceforge.net/
R128GAIN at HA Forum:   http://www.hydrogenaudio.org/forums/index.php?showtopic=85978
Project:   http://sourceforge.net/projects/r128gain/
Download:   http://sourceforge.net/projects/r128gain/files/r128gain/1.0/
 
For playback see also:   http://in-ffsox.sourceforge.net/

2012-10-14 1.0-α-6
  • Added ATSC A/85 support.
  • Added ReplayGain2 support.
  • Added an option "--reference" in order to define the reference loudness (EBU R128: -23 LUFS).
  • Added an option "--db" in order to force dB as unit instead of LU/TP.
  • Added an option "--quiet" in order to suppress any writing to stdout.
  • Fixed loading "libsox.so.1".
  • Fixed overwriting of files.
2012-08-17 1.0-α-4
  • The core library "lib1770" was restructured in order to avoid duplicated computations. Scanning the EBU R128 test vector demonstrates that there is performance boost of about 40% (without true peak computation).
  • The new "lib1770" now supports parallel computations. As demonstrated by the multithreaded "example2" program compared to sequential "example1" program parallelism may give another performance boost of about 50% (not yet used by R128GAIN).
2012-08-15 1.0-α-3
  • Added "--ffmpeg" and "--sox" command line options in order to allow for providing the path to the respective shared libraries.
  • Fixed missing the "TP", "TPDB", "AP", and "APDB" environment variables.
2012-05-27 1.0-α-2
  • Added a CLI (command line) only version (i.e. without GUI.)
  • Provided Linux 64 bit builds.
  • Fixed crashing CLI on Windows XP.
2012-05-18 1.0-α-1
  • Unicode/UTF16 support for Win32.
  • GTK2 and GTK3 GUIs for Linux.
  • GTK2 GUI for Win32.
  • No static buffers any longer.
  • 75% rewrite (BS.1770 algorithm unchanged).
2012-04-06 0.9.7 Added an option to the command line (--tags=[rg|bwf]) and the GUI (drop down box) for letting R128GAIN write BWF tags instead of ReplayGain tags. The following BWF tags are currently supported (depending on the format they may appear converted to upper case):
  • LoudnessValue
  • LoudnessRange
  • MaxTruePeakLevel
2012-03-18 0.9.6-3
  • Fixes a bug that under certain circumstances a file was written twice.
  • Upgraded to SoX 14.4.0.
2012-02-11 0.9.6
  • According to FFmpeg.org: FFmpeg development has gone into OVERDRIVE. As a consequence R128GAIN wasn't compiling any longer using the latest FFmpeg versions. This release ports R128GAIN to the latest FFmpeg API.
  • Added a command line and GUI option to allow choosing between the EBU R128-2 (current, dating from 2011) and EBU R128-1 (former, dating from 2010) standards.
  • The release requires "avformat-54.dll" and "avcodec-54.dll", and is now again in line with the latest FFmpeg builds from http://ffmpeg.zeranoe.com/builds/win32/shared/.
2012-02-07 0.9.5
  • Fixed a bug in 0.9.4 that only either the loudness or the loudness range could be computed but not both together.
2012-02-04 0.9.4
  • Implemented the EBU R128 loudness range (LRA) algorithm (not available for the ReplayGain and BS.1770 sequence algorithms.)
  • Provided four respective environment variables for the command option:
    • %TR%: The track loudness range.
    • %TRDB%: The track loudness range in dB/LU.
    • %AR%: The album loudness range.
    • %ARDB%: The album loudness range in dB/LU.
  • The API of LIB1770 (implementing the loudness range algorithm) has slightly changed in order to allow for providing the length of a block (either 400 ms or 3000 ms.)
2012-01-06 0.9.3
  • Provided four more environment variables for the command option:
     
    • %TL%: The track loudness relative to full scale.
    • %TLDB%: The track loudness relative to full scale in dB/LUFS.
    • %AL%: The album loudness relative to full scale.
    • %ALDB%: The album loudness relative to full scale in dB/LUFS.
2011-12-18 0.9.2
2011-12-09 0.9.1
  • Provided more environment variables for the command option:
    • %RATE%: The sample rate.
    • %NCH%: The number of channels.
    • %BITS%: The bit depth.
  • Added more presets for the command option:
    • Physically apply the track gain using SoX (default):
      sox "%TRACK%" "%DN%\%BN%.wav" gain %TGDB%
    • Convert to MP3 and physically apply the track gain using lame (very useful for creating MP3s to be used with your mobile MP3 player, requires "lame.exe" to be copied into the subfolder "r128gain"):
      lame --noreplaygain --scale %TG% -V2 "%TRACK%" "%DN%\%BN%.mp3"
    • Decode using SoX and convert to MP3 by physically applying the track gain using lame (very useful for creating MP3s to be used with your mobile MP3 player, requires "lame.exe" to be copied into the subfolder "r128gain"):
      sox --no-dither "%TRACK%" -t raw - | lame --noreplaygain --scale %TG% -r --bitwidth %BITS% -s %RATE% -V2 - "%DN%\%BN%.mp3"
  • Fixed a glitch regarding switching between the "command" and other output modes.
2011-11-20 0.9
  • Set default gate to -10.0 LUFS and default block overlap to 75% (according to the latest EBU R128 and BS1770-2 specifications.)
  • Avoid division by zero in LIB1770 (implies a slight API change.)
  • Further improved GUI synchronization.
2011-10-08 0.8.8
  • Implemented some GUI synchronization with respect to the "command" feature.
  • Wrapped arguments in the "command" preset with double quotation marks (").
  • Extended number of lines in input list.
  • Distribute limited versions of "sox.exe" and "ffmpeg.exe" for usage whithin the "command".
2011-10-03 0.8.7
  • Implemented an alternate BS.1770 statistics using a histogram as proposed in "http://lac.linuxaudio.org/2011/download/lm-pres.pdf". The histogram based statistics avoids memory overflow and appears to improve performance. The new histogram based statistics is default.
     
  • The public API of lib1770 is changed slightly in order to allow for choosing the statistcs algorithm, either histogram or sequence.
     
  • Provided an option to execute a command in addition to the build-in actions to be enabled via the "Format" drop down box. The command's environment provides the following variables:
     
    • %PATH%: The systems's path extended by the sub-directory "r128gain".
    • %TRACK%: The complete path to the source track.
    • %NAME%: The name of the source track including the extension.
    • %BN%: The base name of the source track, i.e. excluding the extension.
    • %EXT%: The extension of the source track.
    • %DN%: The output directory.
    • %TG%: The track gain.
    • %TGDB%: The track gain in dB.
    • %TP%: The track peak.
    • %TPDB%: The track peak in dB.
    • %AG%: The album gain.
    • %AGDB%: The album gain in dB.
    • %AP%: The album peak.
    • %APDB%: The album peak in dB.
2011-07-10 0.8.6 Allow choosing the BS.1770 block overlap by parameter partition (1, 2, 3, ...). The corresponding overlap in % is (1 - 1/partition) * 100%.
2011-05-15 0.8.5 Important: Requires "bumped" FFmpeg, i.e. "avformat-53.dll", "avcodec-53.dll", and "avutil-51.dll". For upgrading to the latest full FFmpeg build get the respective DDLs from
http://ffmpeg.zeranoe.com/builds/win32/shared/, or
http://www.bizzeh.com/ffmpeg/free/shared/.
Please note that FFmpeg's MP3 muxer (in "avformat-53.dll") now calculates a XING header, i.e. MP3s processed with R128GAIN now contain the correct length information.

R128GAIN supports a variety of configuration options:

  1. Of course, EBU 128 mode is the default:

  2. Instead you may choose ReplayGain compliance:

  3. Finally you may choose your own profile. The following seems to be the most wanted:

Further options:

Command line syntax:

$ r128gain --help
An EBU R128 (http://tech.ebu.ch/loudness) compliant loudness scanner.
For details refer to "http://r128gain.sourceforge.net/".

Usage: r128gain [options] (file|directory)+ [-o <directory> [flac|mkv]]
Options:
  --r128              Run in EBU R128-2011 compliance mode (default).
  --r128-2011         Run in EBU R128-2011 compliance mode (default).
  --r128-2010         Run in EBU R128-2010 compliance mode.
  --a85               Run in ATSC A/85:2011 compliance mode.
  --a85-2011          Run in ATSC A/85:2011 compliance mode.
  --rg2               Run in ReplayGain2 compliance mode.
  --rg                Run in ReplayGain compliance mode.
  --reference=<float>  Set reference loudness in LUFS.
  --r128-compatible   Calibrate output according to EBU R128.
  --rg-compatible     Calibrate output according to ReplayGain.
  --db                Use dB as unit rather then LU/TP.
  --partition=<int>   BS.1770 overlap
                      (overlap in % = (1 - 1/partition) * 100%,
                      default: 4, i.e. 75% overlap).
  --gate=<float>      BS.1770 gate (-10.0 .. -8.0, default: -10.0).
  --rg-calibration=<float>  Aequivalent to use for ReplayGain
                      loudness (default: -18.0).
  --no-peak
  --sample-peak
  --true-peak
  --range=on,--range  Calculate loudness range (default).
  --range=off,--no range  Don't calculate loudness range.
  --tags=[rg|bwf]     Write ReplayGain (default) or BWF tags.
  --fast              Switch off up-sampling and don't calculate
                      loudness range.
  --mono=off          Treat mono as stereo (default).
  --mono=on,--mono    Don't treat mono as stereo.
  --quiet             Supress output to stdout.
  --progress=on       Display progress (default).
  --progress=off      Don't display progress.
  --traditional       Format output traditionally.
  --command=<string>  Run command on each track.
  --overwrite         Overwrite already existing output files.
  --in-place          Overwrite original files.
  --loglevel=<integer>  Set FFmpeg loglevel.
  --regression        Calculate linear regression between EBU R128
                      and ReplayGain.
  --duration          Print out duration.
  --version           Display version information.
  --ffmpeg=<path>     Directory of the FFmpeg shared libraries.
  --sox=<path>        Directory of the SoX shared libraries.
  --help              Display this information.

Results for the EBU R128 test vector:

Test cases for Loudness Metering (tech3341.pdf):

$ r128gain ~/ebu-loudness-test-setv03/*3341*.wav
SoX sucessfully loaded.
FFmpeg sucessfully loaded.
analyzing ...
  [1/9] "seq-3341-1-16bit.wav": -23.0 LUFS (-0.0 LU)
      peak: -22.9 TPFS, range: 1.8 LU
  [2/9] "seq-3341-2011-8_seq-3342-6-24bit-v02.wav": -23.0 LUFS (0.0 LU)
      peak: -2.6 TPFS, range: 15.2 LU
  [3/9] "seq-3341-2-16bit.wav": -33.0 LUFS (10.0 LU)
      peak: -32.7 TPFS, range: 1.8 LU
  [4/9] "seq-3341-3-16bit-v02.wav": -23.0 LUFS (0.0 LU)
      peak: -23.0 TPFS, range: 13.0 LU
  [5/9] "seq-3341-4-16bit-v02.wav": -23.0 LUFS (0.0 LU)
      peak: -23.0 TPFS, range: 13.0 LU
  [6/9] "seq-3341-5-16bit-v02.wav": -23.0 LUFS (-0.0 LU)
      peak: -20.0 TPFS, range: 6.0 LU
  [7/9] "seq-3341-6-5channels-16bit.wav": -23.0 LUFS (0.0 LU)
      peak: -24.0 TPFS, range: 1.8 LU
  [8/9] "seq-3341-6-6channels-WAVEEX-16bit.wav": -23.0 LUFS (0.0 LU)
      peak: -24.0 TPFS, range: 1.8 LU
  [9/9] "seq-3341-7_seq-3342-5-24bit.wav": -23.0 LUFS (0.0 LU)
      peak: -8.9 TPFS, range: 6.3 LU
  [ALBUM]: -23.2 LUFS (0.2 LU)
      peak: -2.6 TPFS, range: 15.4 LU
done.

Test cases for Loudness Range (tech3342.pdf):

$ r128gain ~/ebu-loudness-test-setv03/*3342*.wav
SoX sucessfully loaded.
FFmpeg sucessfully loaded.
analyzing ...
  [1/6] "seq-3341-2011-8_seq-3342-6-24bit-v02.wav": -23.0 LUFS (0.0 LU)
      peak: -2.6 TPFS, range: 15.2 LU
  [2/6] "seq-3341-7_seq-3342-5-24bit.wav": -23.0 LUFS (0.0 LU)
      peak: -8.9 TPFS, range: 6.3 LU
  [3/6] "seq-3342-1-16bit.wav": -22.6 LUFS (-0.4 LU)
      peak: -20.0 TPFS, range: 10.0 LU
  [4/6] "seq-3342-2-16bit.wav": -16.8 LUFS (-6.2 LU)
      peak: -15.0 TPFS, range: 5.0 LU
  [5/6] "seq-3342-3-16bit.wav": -20.0 LUFS (-3.0 LU)
      peak: -20.0 TPFS, range: 20.0 LU
  [6/6] "seq-3342-4-16bit.wav": -24.5 LUFS (1.5 LU)
      peak: -20.0 TPFS, range: 15.0 LU
  [ALBUM]: -21.2 LUFS (-1.8 LU)
      peak: -2.6 TPFS, range: 17.1 LU
done.