MP3 normalization when encoding
Reply #17 – 2014-03-03 10:38:13
I'm new here as writer (it is my first post but years of silent reading) so hello to community and special thanks to LAME developers! ===How to normalize mp3s to have all peaks be at 0 dB maximum and prevent clipping. Hello, Neuron! Firstly I highly recommend you to read famous ff123's article named "Added Clipping" (I know of this article many years ago from some thread /actually multiple threads/ on this forum). Several years ago I also stand before "abovequoted" problem and had solved it by following simple (for me) way. 1. Source WAVs are analysed to find peak value. There are plenty of programs, I am using (for years) free tool Normalize from Chris Vaill . Command line is (no normalizing here /"discard" tool name/, just examining of files):c:\somepath\normalize.exe -n --peak --fractions --no-progress *.wav >> peak.txt Peak values (ranged 0..1) are in 2nd column, select maximum from them (maybe sort in capable texteditor). 2. Calculate needed value for --scale: scale=0.968/peak (0.968 is empiric value for lame 3.99.5 -V 0 encode). It is "draft" value (because we cannot say before encoding what exact "value" will be added if any) but for hi-quality (-V 0) it is good enough, not exactly at 0 dB (at 32767 in 16-bit output), but good. (The more scalevalue the more "draftness" in it, so for values like 2 /very rare but can be — for years I have encountered less than 10 wav album-sources with needed initial scalevalue greater than 2/ or so I make it slightly less.) 3. Encode:c:\somepath\lame.exe -V 0 --scale %scalevalue% --noreplaygain file.wav file.mp3 (I use --noreplaygain because not all of my players support this tag, so I slightly speed-up encode process.) 4. Check for actual peak.c:\somepath\mp3gain.exe /x /s s /o *.mp3 If maximum peak is 30000..32500 then it's ok for me. If maximum peak is less than 30000 (rarely because of calculation in (2)) then I may (or may not) recalculate scalevalue: go to (2). If maximum peak is more than 32500 (possibly but not frequent) then I definitely must (and will) recalculate scalevalue: go to (2). Yes I can use exact 32767 here but better I give some "slack space" for peaks. Actually mostly all work is done through CMD file (cannot be widely used because of several specific things so I will not post it here in entirety). I prefer to not adjust to exactly 0dB (32767 for 16-bit audio) because as I noted above: better I give some "slack space" for peaks (and for mp3 decoders). It is possibly to fully automatize abovementioned procedures (and scale adjusting loop) but for me is enough to manually calculate scalevalues. And yes, this procedure is performed for all album-files together, no track-normalizing (peak-adjusting) here.P.S. Clarification of math in "4 go to 2" path. 1. Say we got WAVs peak maximum value of 0.987654. 2. scale=0.968/0.987654=0.980. 3. Encode... 4. Actual peak maximum value is 34000 — too big, definitely is clipping, go to (2). 2.a) Note 0.968*32768=31719. 2.b) Proportion: 0.980/34000 = newscale/31719 >> newscale = 0.980*(31719/34000) = 0.914 2.c) New scale = 0.914. Go to (3). <<< OR >>> 4. Actual peak maximum value is 20000 — too low, definitely worth to "up", go to (2). 2.a) Note 0.968*32768=31719. 2.b) Proportion: 0.980/20000 = newscale/31719 >> newscale = 0.980*(31719/20000) = 1.554 2.c) New scale = 1.554. Go to (3).