Log in

View Full Version : Need a commandline utility for normalizing .wav files


jamesN
18th June 2011, 17:08
Hi. . .
I have a lot of .wav files, some of them have too low volume and some have too high volume, some of them even have low parts and high parts(they are dialogues with background music if that matters)
Is there any utility up there to normalize those files?
I prefer that it has a cli version so that i can use it in a batch script.
Any help appreciated!

manolito
18th June 2011, 17:52
https://neon1.net/prog/normalize0253.zip


Cheers
manolito

jamesN
18th June 2011, 19:28
Thanks, manolito. I downloaded your link.
After I read some topics(correct me if I am wrong), but seems like i need "dynamic range compression" to fix files that have low-volume and high-volume parts, and this feature isn't there in the normalize.exe, if you are aware of any other utility, please help me.

smok3
18th June 2011, 20:12
Thanks, manolito. I downloaded your link.
After I read some topics(correct me if I am wrong), but seems like i need "dynamic range compression" to fix files that have low-volume and high-volume parts, and this feature isn't there in the normalize.exe, if you are aware of any other utility, please help me.

Check sox.
http://sox.sourceforge.net/
Compound is the name of the effect.

b66pak
18th June 2011, 20:29
use wavegain (http://www.rarewares.org/others.php#wavegain)...
_

jamesN
18th June 2011, 20:47
Thanks guys, trying the links. . .
I will reply as soon as possible

Blue_MiSfit
19th June 2011, 10:46
I like eac3to for this purpose. It can do a lot more, too :)

LoRd_MuldeR
19th June 2011, 12:20
Check sox.
http://sox.sourceforge.net/
Compound is the name of the effect.

Indeed, SoX is a very powerful command-line tool for audio editing/processing. I can recommend it!

I compiled a slightly modified version with support for Unicode file names:
https://github.com/lordmulder/LameXP/tree/master/res/tools

smok3
19th June 2011, 12:47
use wavegain (http://www.rarewares.org/others.php#wavegain)...
_

this wont help alone, since the loudness varies inside single entity, but one may construct a path like:

compund > replaygain ( actually the current fashion for loudness handling is ebu r128, check http://www.hydrogenaudio.org/forums/index.php?showtopic=86424 )

for each entity (personally i'd only bother with that if each entity is shorter that say 5 minutes).

nibus
19th June 2011, 23:58
I experimented with sox to compress some action movie audio for my iPad encodes... here is a couple settings that seem to work well for that:

Lighter DRC:
compand 0.3,1 6:-70,-60,-36 -5 -90 0.2

The -36 and -5 are what you'll want to experiment with. By setting -36 to higher numbers (say -25) it will increase compression, and the -5 limits clipping; you'll want to lower it (say -8) if you raise the compression much higher, to avoid clipping.

manolito
20th June 2011, 10:17
Ok, we really have to differentiate between two very different methods here. Normalizing / ReplayGain (which both do not touch the original dynamic range), and using compression to achieve an even loudness between different tracks.

If normalizing / ReplayGain does not lead to the desired result (which I suspect), then it gets a lot more complicated. The task is very similar to the one a mastering engineer has when he compiles an album which consists of tracks recorded and mixed by different engineers in different studio environments.

I will not say anything bad here about SoX, it is very powerful and offers great quality, but it is a commandline app after all, and that makes it very user unfriendly when it comes to complex tasks. Here is a sample command line for the mcompand effect:
play track1.wav gain −3 sinc 8000− 29 100 mcompand \
"0.005,0.1 −47,−40,−34,−34,−17,−33" 100 \
"0.003,0.05 −47,−40,−34,−34,−17,−33" 400 \
"0.000625,0.0125 −47,−40,−34,−34,−15,−33" 1600 \
"0.0001,0.025 −47,−40,−34,−34,−31,−31,−0,−30" 6400 \
"0,0.025 −38,−31,−28,−28,−0,−25" \
gain 15 highpass 22 highpass 22 sinc −n 255 −b 16 −17500 \
gain 9 lowpass −1 17801
Who in the world can manage that?

I believe there are easier ways to get good results. I have a recording studio background (some 20 years ago...), and at that time you had to pay a fortune for decent wave editor plugins. Today you can get amazing stuff for free.


So this is how I would do it:

Get one of the many good free wave editors (Acoustica, Audacity, WavePad). My favorite is WavePad, it even has a built-in batch mode. There is also a built-in effect called automatic gain. Maybe this is all you need...

Otherwise get some free mastering plugins. The best of them can be found here:
http://forum.cakewalk.com/tm.aspx?m=1391345
and here:
http://www.untidymusic.com/wordpress/vst-plugins/free-mastering/expanding-list-of-free-vst-mastering-plugins/

T-SLEDGE and Volcano are some of my favorites. They all come with mastering presets you can use as a starting point. And you can listen to the effects in realtime before deciding which settings are best for you...


Cheers
manolito

jamesN
20th June 2011, 14:49
sorry, but i couldn't understand how to use compand in sox, because the command seems to be play, and i couldnt find play.exe in the downloaded package from sourceforge, so how can i invoke play command?!
note that i thought it is an argument to sox, but that wasnt right!
could someone please write a complete command that i can open cmd, navigate to the sox directory, then paste it directly there!

jamesN
20th June 2011, 14:58
also, after i read more about dynamic range compression it seems that it will not fix the files, i want a tool that takes each sample in the .wav file, simply adds a specified gain to this sample(like normalize.exe) BUT, if that leads to distort the sample, then apply max possible gain(the max gain without distortion) to this sample, is there any cli tool that can do that?

Groucho2004
20th June 2011, 15:22
i want a tool that takes each sample in the .wav file, simply adds a specified gain to this sample(like normalize.exe) BUT, if that leads to distort the sample, then apply max possible gain(the max gain without distortion) to this sample, is there any cli tool that can do that?

That's the "algorithm" known as clipping. It leads to heavy distortion and I can't imagine that you want that.

LoRd_MuldeR
20th June 2011, 15:32
also, after i read more about dynamic range compression it seems that it will not fix the files, i want a tool that takes each sample in the .wav file, simply adds a specified gain to this sample(like normalize.exe) BUT, if that leads to distort the sample, then apply max possible gain(the max gain without distortion) to this sample, is there any cli tool that can do that?

I think what you want is a simple limiter. SoX' gain filter should be able to do this:
sox.exe --guard <infile> <outfile> gain -l 6

"This will apply 6 dB of gain but never clip. Note that limiting more than a few dB's more than occasionally (in a piece of audio) is not recommended as it can cause audible distortion."

b66pak
20th June 2011, 19:21
you can do this with wavegain too:

wavegain -r -y -n -l -f audio.log -t audio.wav

-t, --limiter Apply 6dB Hard Limiter to output.
_

jamesN
20th June 2011, 19:47
please, correct me, i noticed that distortion is caused when applying a high gain on a high-volume sample, so that there is a max volume that if exceeded then distortion occurs, and if i prevent that using the algorithm from my previous post, i am safe from distortion, am i right?

LoRd_MuldeR
20th June 2011, 19:52
please, correct me, i noticed that distortion is caused when applying a high gain on a high-volume sample, so that there is a max volume that if exceeded then distortion occurs, and if i prevent that using the algorithm from my previous post, i am safe from distortion, am i right?

Nope. You apply a constant gain on all samples, but all samples that would "clip" (i.e. exceed 0 dB) are "hard" limited to 0 dB.

Even though there won't be any "clipping", there still can be "audible distortions", if strong limiting is applied.

I think the better method would be applying a "downward compressor" first (to smooth out peaks) and then a standard "normalizer".

jamesN
20th June 2011, 20:18
that's right, the sox command of --guard caused distortion on high-volume samples,
then i guess the only way is dynamic range compression?!
if i have to compress dynamic range, could you please write a simple sox command to use it in my batch script, because i cant understand how to use it(as i mentioned in a previous post) and thanks again.

jamesN
20th June 2011, 20:22
then how is the "downward compressor" done in sox, also the normalization?!

LoRd_MuldeR
20th June 2011, 20:28
then how is the "downward compressor" done in sox, also the normalization?!

Try this:
sox.exe <infile> <outfile> contrast 75

Comparable with compression, this effect modifies an audio signal to make it sound louder. enhancement-amount controls the amount of the enhancement and is a number in the range 0−100. Note that enhancement-amount = 0 still gives a significant contrast enhancement.

Or use the "compand" filter, as suggested earlier in this thread...

jamesN
20th June 2011, 20:51
the problem is that i dont know how to use the compand effect, it has a lot of options, and "contrast" caused some distortion, also how to normalize using sox?!

LoRd_MuldeR
20th June 2011, 21:09
the problem is that i dont know how to use the compand effect, it has a lot of options, and "contrast" caused some distortion

...try lowering the strength ;)

also how to normalize using sox?!

sox.exe --norm <infile> <outfile>

manolito
21st June 2011, 07:53
After all these posts about how to use SoX you will probably have noticed that the process is quite time consuming (to say it in a friendly way).

I will say it again: Why don't you use a 'loudness maximizer" plugin in a wave editor. This way you can listen to all the changes you make to your settings at once without having to render the file first. Also a good loudness maximizer does a lot more than just applying compression paired with a limiter.

Personally I use the Waves UltraMaximizer+ plugin for such tasks with outstanding results, but this plugin is not really cheap. But again, many free tools in this category are available these days.


Cheers
manolito

jamesN
22nd June 2011, 20:41
Thanks lord_mulder, i will try normalizing and reply as soon as possible.
Monalito,the reason why i want a cli program is that i am trying to write a batch script that will normalize many .mp4 video files(h264+aac), so the batch script will first decode the aac audio in the mp4 using neroaacdec then normalize(and compand) the resulted .wav then reencode into aac(neroaacenc) then remux with the original video(mp4box), so i dont want to spend hours on each file normalizing and applying affects, . .
Thanks again for everybody!

nibus
23rd June 2011, 00:57
Thanks lord_mulder, i will try normalizing and reply as soon as possible.
Monalito,the reason why i want a cli program is that i am trying to write a batch script that will normalize many .mp4 video files(h264+aac), so the batch script will first decode the aac audio in the mp4 using neroaacdec then normalize(and compand) the resulted .wav then reencode into aac(neroaacenc) then remux with the original video(mp4box), so i dont want to spend hours on each file normalizing and applying affects, . .
Thanks again for everybody!

I doubt you'll be able to use one setting on all your movies. I'm betting some will be distorted and others will be too soft.

Here's a batch script I wrote that uses Sox -compand along with WaveBooster (written by LigH, similar to the boost built into besweet). WaveBooster is old but has worked great for me.

You are welcome to use it, and you might want to edit some of the values to suit your needs. I set up a few presets from "Very light" to "Very heavy" compression, as well as a custom option. You might need to experiment to get the right amount for each movie.

I've had some good results with some action movie soundtracks so far. I don't know how it would do with music. Note that the the higher the compression with Sox, the higher your limit will need to be. As long as you have under 100 clipped samples you should be okay for movies.

You need to put the batch file in the same directory as Sox (http://sourceforge.net/projects/sox/files/sox/14.3.2/sox-14.3.2-win32.zip/download) as well as WaveBooster (http://www.softpedia.com/progDownload/WaveBooster-Download-111503.html). The file input can't contain spaces.


@ECHO OFF


:INPUT
CLS
ECHO Add DRC and Maximize sound (WAV)
ECHO.
ECHO.
SET INPUT=
SET /P INPUT=Enter File: %=%
IF "%INPUT%"=="" GOTO :INPUT


:DRC
ECHO.& ECHO.
ECHO Select amount:
ECHO.
ECHO 1) Very Light (48db Range)
ECHO 2) Light (44db Range)
ECHO 3) Medium (40db Range)
ECHO 4) Heavy (36db Range)
ECHO 5) Very Heavy (32db Range)
ECHO.
ECHO 6) Custom Range
ECHO.& ECHO.

SET CHOICE=& SET /P CHOICE=Select Option: %=%
IF "%CHOICE%"=="1" SET DRC=48& SET LIMIT=5& GOTO :GO
IF "%CHOICE%"=="2" SET DRC=44& SET LIMIT=6& GOTO :GO
IF "%CHOICE%"=="3" SET DRC=40& SET LIMIT=6& GOTO :GO
IF "%CHOICE%"=="4" SET DRC=36& SET LIMIT=7& GOTO :GO
IF "%CHOICE%"=="5" SET DRC=32& SET LIMIT=8& GOTO :GO

IF "%CHOICE%"=="6" GOTO :CUSTOM
IF "%CHOICE%"=="" GOTO :DRC

:CUSTOM
ECHO.
SET DRC=& SET /P DRC=Specify Range (eg 20-50): %=%
ECHO.
SET LIMIT=& SET /P LIMIT=Specify dB Limit (eg 20-5): -%=%

:GO

CLS
ECHO Applying Dynamic Range Compression...
ECHO.
sox.exe "%INPUT%" "%INPUT%_Range_%DRC%db_Limit_-%LIMIT%db.wav" compand 0.3,1 5:-70,-60,-%DRC% -%LIMIT% -90 0.2

:MAX
ECHO.& ECHO.
ECHO Maximizing audio...
ECHO.& ECHO.

BOOSTCLI.EXE /i="%INPUT%_Range_%DRC%db_Limit_-%LIMIT%db.wav" /o="%INPUT%_Range_%DRC%db_Limit_-%LIMIT%db_Maximized.wav" /a=-12 /m=-.5


:FINISH
ECHO.
ECHO.
ECHO Audio encoded to:
ECHO.
ECHO %INPUT%_Range_%DRC%db_Limit_-%LIMIT%db
ECHO.
ECHO and Maximized to:
ECHO.
ECHO %INPUT%_Range_%DRC%db_Limit_-%LIMIT%db_Maximized.wav
ECHO.
ECHO.
PAUSE
CLS
GOTO :INPUT


You might want to adjust "/a=-12 /m=-.5" - the -12 is the boost factor and -.5 is the limit.

Before and after:

http://dl.dropbox.com/u/5637223/Clipboard02.jpg

http://dl.dropbox.com/u/5637223/Clipboard01.jpg

Obviously you wouldn't want this audio for home use, but it works great for loud listening environments like in the car with an iPad. If it's too compressed, you might want to try only WaveBooster by itself.

EDIT: You will need to use these eac3to switches for WaveBooster to work: -simple -down16