Code Monkey home page Code Monkey logo

wavegain's Introduction

ReplayGain for wave files, v1.3.2

WaveGain is an application of the ReplayGain algorithms to standard PCM wave
files. Calculated gain adjustments are applied directly to the audio data,
instead of just writing metadata as traditionally done for other formats
like MP3, FLAC and Ogg Vorbis.

The replaygain values can also be added as metadata in a custom RIFF chunk
named 'gain'. This could theoretically allow WAV files to have same lossless
functionality as other formats where audio data is not altered. But since no
current players are aware of this "standard", the metadata is used only by
WaveGain for the "--undo-gain" feature, which is lossy.


About replaygain
-------------------------------------------------------------------------------

Replaygain is a standard that allows compatible players to play audio files with
an adjusted volume gain so they have a consistent perceived loudness.

It is similar in concept to Normalization, but instead of using just the peak
value to calculate the gain, it relies on RMS (sound pressure "power") values
and psychoacoustics models to calculate a gain based on the perceived loudness
of an audio file by a human listener.

Loudness can be averaged either for each individual file, also called "Track" or
"Radio" mode, where every song is adjusted to the same standard loudness; or by
group, also called "Album" mode, where individual "songs" may sound louder or
quieter than others, but each "album" as a whole has the same average loudness
as other albums.

For more information,
http://en.wikipedia.org/wiki/ReplayGain
http://wiki.hydrogenaudio.org/index.php?title=Replaygain
http://wiki.hydrogenaudio.org/index.php?title=ReplayGain_specification


The saga of a Debian package for wavegain:
-------------------------------------------------------------------------------

- Current source code (in .zip format) and windows binaries are published at
	http://www.rarewares.org/others.php
	http://www.rarewares.org/files/others/

- An i386 binary .deb for version 1.2.6 (from 2005) was published at
	http://www.rarewares.org/debian/packages/unstable/index.php

- Later, Linux Mint hosted the source, amd64 and i386 packages for v1.2.8 (2010)
	http://packages.linuxmint.com/pool/import/w/wavegain/

This package is a combination of current upstream source, a proper Debian
packaging improved from the Mint release, and some patches to fix some
(serious) Linux issues.


Install how-to
-------------------------------------------------------------------------------

There are 2 approaches: you can build and install a .deb package, or simply
compile and install from source. For both I assume you are already at the
source directory (which is not the root directory of the cloned repository)

Debian method:
This is OUTDATED, UNMAINTANED and NON-WORKING! Use Traditional Method instead!
$ sudo apt-get install devscripts # if you don't already have debuild
$ debuild -- binary && sudo dpkg --install ../wavegain_*.deb

Traditional method:
$ make && sudo make install # by default installs to /usr/local/bin/wavegain
or
$ make && sudo make install prefix=/usr # to install to /usr/bin/wavegain

Currently, 64-bit binaries build fine but can generate corrupted audio on output
files, so to prevent this by default it builts a 32-bit executable instead,
which runs and works fine on 64-bit architectures. However, multi-arch libraries
and headers might be needed as a pre-requiste for compiling. On Debian/Ubuntu this
can be installed by:

	sudo apt install gcc-multilib


Pre-compiled binaries and old versions
-------------------------------------------------------------------------------
You can find pre-compiled .DEB binariy packages for i386 and amd64, as well
as as some other goodies, like a mega-archive of all previous versions
and a (lame and outdated) html manual in the Downloads section of GitHub:

https://github.com/MestreLion/wavegain/downloads


License and copyright
-------------------------------------------------------------------------------

WaveGain is Copyright (c) 2002-2010 John Edwards <[email protected]>,
a.k.a. John33, and several other co-authors and contributors are mentioned as
Copyright owners in the source files.

Originally released as LGPL-2.1 or later, although some source code simply says
GPL, and some others some says GPL2+. Despite this, the project as a whole
should be regarded as LGPL-2.1+, as per COPYING file. To avoid further confusion
in the future, I suggest source files be standartized with a common header and
re-licensed, preferably as GPL-3 or later (not LGPL).

I claim no copyright over the C source code, including patches I made.

The Debianization and aditional material, like this README and Makefile, is
Copyright (c) 2012 Rodrigo Silva (MestreLion)


Documentation (from wavegain --help)
-------------------------------------------------------------------------------

Copyright (c) 2002-2010 John Edwards <[email protected]>
Additional code by Magnus Holmgren, Gian-Carlo Pascutto, and Tycho

 Usage: wavegain [options] input.wav [...]

 OPTIONS
  -h, --help       Prints this help information.
  -a, --album      Use ReplayGain Audiophile/Album gain setting, or
  -r, --radio      Use ReplayGain Radio/Single Track gain setting(DEFAULT).
  -q, --adc        Apply Album based DC Offset correction.
                   DEFAULT is Track based DC Offset correction.
  -p, --no_offset  Do NOT apply DC Offset correction.
  -c, --calculate  Calculates and prints gain settings, and DC Offsets BUT
                   DOES NOT APPLY THEM - This is the DEFAULT.
  -x, --scale      Writes scale values to stdout in the format: n.nnnnnn
                   In Album mode it only writes the Album Scale value, and
                   in Title mode it only writes the Title Scale values.
                   ONLY works in Calculation mode.
  -y, --apply      Calculates and APPLIES gain settings, and applies
                   DC Offset correction.
  -w, --write      Writes a 'gain' chunk into the Wave Header.
                   Stores the scalefactor applied to the wave data as a
                   double floating point number. Only written when gain
                   is applied. Presence will result in file being skipped
                   if reprocessed.
                   (Unless '--force' or '--undo-gain' are specified.)
      --force      Forces the reprocessing of a file that contains a 'gain'
                   chunk and will result in the new scalefactor overwriting
                   the existing value.
      --undo-gain  Reads the scalefactor in the 'gain' chunk and uses the
                   value to reverse the previously applied gain. This will NOT
                   recreate a bit identical version of the original file, but
                   it will be rescaled to the original level.
  -z, --recursive  Search for files recursively, each folder as an album
  -l, --log        Write log file.(Default filename = WGLog.txt)
  -f, --logfile    Specify log filename. (Assumes -l if present.)
  -n, --noclip     NO Clipping Prevention.
  -d, --dither X   Dither output, where X =
               0   for       dither OFF (default).
               1   for       dither without Noise Shaping.
               2   for       dither with Light Noise Shaping.
               3   for       dither with Medium Noise Shaping.
               4   for       dither with Heavy Noise Shaping.
  -t, --limiter    Apply 6dB Hard Limiter to output.
  -g, --gain X     Apply additional Manual Gain adjustment in decibels, where
             X = any floating point number between -20.0 and +12.0.
                   Clipping Prevention WILL be applied UNLESS '-n' is used.
  -s, --fast       Calculates and prints gain settings - DOES NOT APPLY THEM.
                   NOTE: This method does NOT process all samples, it only
                         processes 200 x 16k chunks of samples. Results will
                         NOT be as accurate as a full analysis but, with most
                         material, will be within +/- 0.5db. Files of 8,192,000
                         real samples, or less, will be analysed in full.
                         DC Offset is neither calculated nor corrected in
                         FAST mode.
  -o, --stdout     Write output file to stdout.
 FORMAT OPTIONS (One option ONLY may be used)
  -b, --bits X     Set output sample format, where X =
             1     for        8 bit unsigned PCM data.
             2     for       16 bit signed PCM data.
             3     for       24 bit signed PCM data.
             4     for       32 bit signed PCM data.
             5     for       32 bit floats.
             6     for       16 bit 'aiff' format.
         NOTE:     By default, the output file will be of the same bitwidth
                   and type as the input file.
 INPUT FILES
  WaveGain input files may be 8, 16, 24 or 32 bit integer, or floating point
  wave files with 1 or 2 channels and a sample rate of 96000Hz, 88200Hz,
  64000Hz, 48000Hz, 44100Hz, 32000Hz, 24000Hz, 22050Hz, 16000Hz, 12000Hz,
  11025Hz or 8000Hz.
  16 bit integer 'aiff' files are also supported.
  Wildcards (?, *) can be used in the filename, or '-' for stdin.


wavegain-1.3.2

wavegain's People

Contributors

bwagner avatar mestrelion avatar xiaoxiongwang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

wavegain's Issues

wavegain seems to chop up the audio when normalizing

I have an audio file of the following specs:

Input File : 'outsox.wav'
Channels : 2
Sample Rate : 44100
Precision : 24-bit
Duration : 00:01:00.00 = 2646000 samples = 4500 CDDA sectors
File Size : 15.9M
Bit Rate : 2.12M
Sample Encoding: 24-bit Signed Integer PCM

When I try to normalize it with wavegain -y I get a file with the audio being chopped up. It also seems to have a pitch an octave higher than the original, which would point to metadata being wrongly interpreted...

The original file: http://bernhardwagner.net/outsox.wav
The file generated by "wavegain -y": http://bernhardwagner.net/outsox_wavegain.wav

This is wavegain v1.3.1 on Mac OSX 10.8.4, compiled from source.

Thank you
Bernhard

Floating Point Exception

Tested in Ubuntu 16.04, 64bit

I use the following command with the file:

./wavegain wavegain_floting_point_exception.wav

and get:

Floating point exception

I use gdb to analysis the bug and get the below information:

gdb-peda$ set args wavegain_floting_point_exception.wav
gdb-peda$ r
Starting program: wavegain wavegain_floting_point_exception.wav
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGFPE, Arithmetic exception.

[----------------------------------registers-----------------------------------]
RAX: 0x5e00e84b 
RBX: 0x7fffffffd4e0 --> 0x7fffffffd700 --> 0x7fffffffd9b0 --> 0x0 
RCX: 0x60c00000bf00 --> 0x0 
RDX: 0x0 
RSI: 0x3 
RDI: 0x0 
RBP: 0x7fffffffd500 --> 0x7fffffffd540 --> 0x7fffffffd630 --> 0x7fffffffd720 --> 0x7fffffffd9d0 --> 0x4197d0 (<__libc_csu_init>:	push   r15)
RSP: 0x7fffffffd340 --> 0xc00000002 --> 0x0 
RIP: 0x40a5cc (<wav_open+3809>:	idiv   rdi)
R8 : 0x61600000fd60 --> 0x0 
R9 : 0x7fffffffd2d0 --> 0x5e00e84b61746164 
R10: 0x7ffff7fc5780 (0x00007ffff7fc5780)
R11: 0x7ffff692bf90 --> 0xfffda370fffda09f 
R12: 0xffffffffa70 --> 0x0 
R13: 0x7fffffffd380 --> 0x41b58ab3 
R14: 0x7fffffffd380 --> 0x41b58ab3 
R15: 0x0
EFLAGS: 0x10206 (carry PARITY adjust zero sign trap INTERRUPT direction overflow)
[-------------------------------------code-------------------------------------]
   0x40a5c0 <wav_open+3797>:	imul   edx,DWORD PTR [rbp-0x19c]
   0x40a5c7 <wav_open+3804>:	movsxd rdi,edx
   0x40a5ca <wav_open+3807>:	cqo    
=> 0x40a5cc <wav_open+3809>:	idiv   rdi
   0x40a5cf <wav_open+3812>:	mov    rcx,rax
   0x40a5d2 <wav_open+3815>:	mov    rax,QWORD PTR [rbp-0x1b0]
   0x40a5d9 <wav_open+3822>:	add    rax,0x10
   0x40a5dd <wav_open+3826>:	mov    rdx,rax
[------------------------------------stack-------------------------------------]
0000| 0x7fffffffd340 --> 0xc00000002 --> 0x0 
0008| 0x7fffffffd348 --> 0x60200000eff0 --> 0xff042546464952 
0016| 0x7fffffffd350 --> 0x60c00000bf80 --> 0x40a8be (<wav_read>:	push   rbp)
0024| 0x7fffffffd358 --> 0x61600000fc80 --> 0xbebebebefbad2488 
0032| 0x7fffffffd360 --> 0x100000000 --> 0x0 
0040| 0x7fffffffd368 --> 0x60400000dfd0 --> 0xbebebebe00080000 
0048| 0x7fffffffd370 --> 0x24 ('$')
0056| 0x7fffffffd378 --> 0x0 
[------------------------------------------------------------------------------]
Legend: code, data, rodata, value
Stopped reason: SIGFPE
0x000000000040a5cc in wav_open (in=0x61600000fc80, opt=0x60c00000bf80, oldbuf=0x60200000eff0 "RIFF%\004\377", buflen=0xc) at audio.c:790
790				opt->total_samples_per_channel = len/(format.channels*samplesize);
gdb-peda$ bt
#0  0x000000000040a5cc in wav_open (in=0x61600000fc80, opt=0x60c00000bf80, oldbuf=0x60200000eff0 "RIFF%\004\377", buflen=0xc) at audio.c:790
#1  0x0000000000407833 in open_audio_file (in=0x61600000fc80, opt=0x60c00000bf80) at audio.c:362
#2  0x0000000000414ded in get_gain (filename=0x60700000df40 "wavegain_floting_point_exception.wav", track_peak=0x60600000efd8, track_gain=0x60600000efd0, dc_offset=0x60600000efe0, 
    offset=0x60600000eff0, settings=0x7fffffffd8f0) at wavegain.c:181
#3  0x000000000041198d in process_files (file_list=0x60600000efc0, settings=0x7fffffffd8f0, dir=0x41f1a0 ".") at main.c:197
#4  0x000000000041453f in main (argc=0x2, argv=0x7fffffffdab8) at main.c:729
#5  0x00007ffff67b7830 in __libc_start_main (main=0x4139ca <main>, argc=0x2, argv=0x7fffffffdab8, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffdaa8)
    at ../csu/libc-start.c:291
#6  0x0000000000401ce9 in _start ()

Suggestion: Increment version

@MestreLion Since 1.3.1, you've added a number of really critical improvements; in particular, the issue with temporary file names tripped me up when using that version, and is now corrected in your master. Since your code has been stable for a while, could you increment the version number to encourage distro maintainers to use it?

Memory leaks detected

Tested in Ubuntu 16.04, 64bit

I use the following command with the file:

./wavegain wavegain_memory_gain.wav

and get:

Warning: INVALID format chunk in wav header.
 Trying to read anyway (may not work)...
*** buffer overflow detected ***: ./wavegain terminated
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7f090b3a57e5]
/lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x5c)[0x7f090b44715c]
/lib/x86_64-linux-gnu/libc.so.6(+0x117160)[0x7f090b445160]
/lib/x86_64-linux-gnu/libc.so.6(__fread_chk+0x165)[0x7f090b445855]
./wavegain[0x40f797]
./wavegain[0x410ee0]
./wavegain[0x41e20d]
./wavegain[0x41c660]
./wavegain[0x40374e]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f090b34e830]
./wavegain[0x403ca9]
======= Memory map: ========
00400000-0042a000 r-xp 00000000 103:01 20397804                          wavegain/wavegain
00629000-0062a000 r--p 00029000 103:01 20397804                          wavegain/wavegain
0062a000-0062b000 rw-p 0002a000 103:01 20397804                          wavegain/wavegain
0062b000-00668000 rw-p 00000000 00:00 0 
00a1c000-00a3d000 rw-p 00000000 00:00 0                                  [heap]
7f090b118000-7f090b12e000 r-xp 00000000 103:01 10490464                  /lib/x86_64-linux-gnu/libgcc_s.so.1
7f090b12e000-7f090b32d000 ---p 00016000 103:01 10490464                  /lib/x86_64-linux-gnu/libgcc_s.so.1
7f090b32d000-7f090b32e000 rw-p 00015000 103:01 10490464                  /lib/x86_64-linux-gnu/libgcc_s.so.1
7f090b32e000-7f090b4ee000 r-xp 00000000 103:01 10487655                  /lib/x86_64-linux-gnu/libc-2.23.so
7f090b4ee000-7f090b6ee000 ---p 001c0000 103:01 10487655                  /lib/x86_64-linux-gnu/libc-2.23.so
7f090b6ee000-7f090b6f2000 r--p 001c0000 103:01 10487655                  /lib/x86_64-linux-gnu/libc-2.23.so
7f090b6f2000-7f090b6f4000 rw-p 001c4000 103:01 10487655                  /lib/x86_64-linux-gnu/libc-2.23.so
7f090b6f4000-7f090b6f8000 rw-p 00000000 00:00 0 
7f090b6f8000-7f090b800000 r-xp 00000000 103:01 10487658                  /lib/x86_64-linux-gnu/libm-2.23.so
7f090b800000-7f090b9ff000 ---p 00108000 103:01 10487658                  /lib/x86_64-linux-gnu/libm-2.23.so
7f090b9ff000-7f090ba00000 r--p 00107000 103:01 10487658                  /lib/x86_64-linux-gnu/libm-2.23.so
7f090ba00000-7f090ba01000 rw-p 00108000 103:01 10487658                  /lib/x86_64-linux-gnu/libm-2.23.so
7f090ba01000-7f090ba27000 r-xp 00000000 103:01 10485855                  /lib/x86_64-linux-gnu/ld-2.23.so
7f090bbf5000-7f090bbf9000 rw-p 00000000 00:00 0 
7f090bc25000-7f090bc26000 rw-p 00000000 00:00 0 
7f090bc26000-7f090bc27000 r--p 00025000 103:01 10485855                  /lib/x86_64-linux-gnu/ld-2.23.so
7f090bc27000-7f090bc28000 rw-p 00026000 103:01 10485855                  /lib/x86_64-linux-gnu/ld-2.23.so
7f090bc28000-7f090bc29000 rw-p 00000000 00:00 0 
7ffde0294000-7ffde02b6000 rw-p 00000000 00:00 0                          [stack]
7ffde0339000-7ffde033c000 r--p 00000000 00:00 0                          [vvar]
7ffde033c000-7ffde033e000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Aborted

I use AddressSanitizer to build wavegain, this file can memory leak with the following command:

./wavegain wavegain_memory_gain.wav

This is the ASAN information:

Warning: INVALID format chunk in wav header.
 Trying to read anyway (may not work)...
Warning: Unexpected EOF in reading WAV header
 Unrecognized file format for wavegain_memory_gain.wav

 WaveGain Processing completed normally

=================================================================
==3874==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 92 byte(s) in 1 object(s) allocated from:
    #0 0x7f6ca685030f in strdup (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x6230f)
    #1 0x4111bc in alloc_node wavegain/main.c:70
    #2 0x4113d3 in add_to_list wavegain/main.c:104
    #3 0x403d7e in process_argument wavegain/recurse.c:583
    #4 0x4144f1 in main wavegain/main.c:718
    #5 0x7f6ca613b82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Direct leak of 40 byte(s) in 1 object(s) allocated from:
    #0 0x7f6ca6886602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0x4097e8 in wav_open wavegain/audio.c:646
    #2 0x407832 in open_audio_file wavegain/audio.c:362
    #3 0x414dec in get_gain wavegain/wavegain.c:181
    #4 0x41198c in process_files wavegain/main.c:197
    #5 0x41453e in main wavegain/main.c:729
    #6 0x7f6ca613b82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

SUMMARY: AddressSanitizer: 132 byte(s) leaked in 2 allocation(s).

Provide executables?

I think it would be nice if executables of version 1.3.2 could be provided as part of the release assets. Currently those assets only consist of the zip and tar.gz files, which is basically the same as selecting the 1.3.2 tag in GitHub then clicking on "Code" and then on "Download ZIP".

I understand that it might not be possible for every OS (e.g. Mac OS) but maybe for Windows and Linux executables could be added?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.