[LAU] Gain and clipping wav -> lame

From: Martin Cracauer <cracauer@email-addr-hidden>
Date: Thu Jul 25 2013 - 21:21:50 EEST

Does anybody know why wav files that do not have clipping would clip
when encoding them with lame?

I have a bunch of self-made clips that for various reasons don't have
enough gain. I wrote a wav->wav conversion that determines maximum
gain (as in highest or lowest absolute value) and uses sox' volume
argument to boost. Inspecting it with same gain tools and listening
to it shows the expected gain raise, but not clipping.

Then, when encoding in lame it gets clipped. Lame warns about it and
the values have been boosted to the max. When doing the boost, with
the same factor, directly in lame (feeding in the unboosted wav) I get
the same problem. Very roughly a clip with 3% headroom ends up being
too high by 16%, or about a 20% boost.

What's going on? I assume there is something about mp3 encoding I
don't quite understand.

Is there anything more efficient that I can do about that doing one
lame run to get an appropriate boost value and then doing another
encoding pass?

Here are the stats of a boosted wav file and the resulting lame:

t02c02.tmp.wav_maxgain_tmp.wav:
Samples read: 36900960
Length (seconds): 384.385000
Scaled by: 2147483647.0
Maximum amplitude: 0.969208
Minimum amplitude: -0.970673
Midline amplitude: -0.000732
Mean norm: 0.213396
Mean amplitude: 0.000000
RMS amplitude: 0.274775
Maximum delta: 1.675323
Minimum delta: 0.000000
Mean delta: 0.193639
RMS delta: 0.245325
Rough frequency: 6820
Volume adjustment: 1.030

mp3:
Samples read: 36907776
Length (seconds): 384.456000
Scaled by: 2147483647.0
Maximum amplitude: 1.000000
Minimum amplitude: -1.000000
Midline amplitude: -0.000000
Mean norm: 0.203464
Mean amplitude: 0.000010
RMS amplitude: 0.262007
Maximum delta: 1.636044
Minimum delta: 0.000000
Mean delta: 0.185782
RMS delta: 0.235408
Rough frequency: 6863
Volume adjustment: 1.000
/opt/good-sox/bin/sox WARN sox: `-' input clipped 725 samples
/opt/good-sox/bin/sox WARN sox: `/tmp/cracauer/l.wav' output clipped
360 samples; decrease volume?

Encoding output:
lame -h -b 160 --replaygain-accurate --clipdetect t02c02.tmp.wav_maxgain_tmp.wav t02c02.tmp.wav_maxgain_tmp.mp3_tmp '&&' mv t02c02.tmp.wav_maxgain_tmp.mp3_tmp t02c02.tmp.wav_maxgain_tmp.mp3
+ sh
LAME version 3.96.1 (http://lame.sourceforge.net/)
Using polyphase lowpass filter, transition band: 18000 Hz - 18581 Hz
Encoding t02c02.tmp.wav_maxgain_tmp.wav to t02c02.tmp.wav_maxgain_tmp.mp3_tmp
Encoding as 48 kHz 160 kbps j-stereo MPEG-1 Layer III (9.6x) qval=2
    Frame | CPU time/estim | REAL time/estim | play/CPU | ETA
 16015/16018 (100%)| 0:22/ 0:22| 0:22/ 0:22| 17.121x| 0:00
average: 160.0 kbps LR: 2551 (15.93%) MS: 13467 (84.07%)

Writing LAME Tag...done
ReplayGain: -9.1dB
WARNING: clipping occurs at the current gain. Set your decoder to decrease
         the gain by at least 1.3dB or encode again using --scale <arg>
         (For a suggestion on the optimal value of <arg> encode
         with --scale 1 first)

-- 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Martin Cracauer <cracauer@email-addr-hidden>   http://www.cons.org/cracauer/
_______________________________________________
Linux-audio-user mailing list
Linux-audio-user@email-addr-hidden
http://lists.linuxaudio.org/listinfo/linux-audio-user
Received on Fri Jul 26 08:15:01 2013

This archive was generated by hypermail 2.1.8 : Fri Jul 26 2013 - 08:15:02 EEST