[LAU] Gain and clipping wav -> lame

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <linux-audio-user@...>
Date: Thursday, July 25, 2013 - 6:21 pm

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
(For a suggestion on the optimal value of encode
with --scale 1 first)

--
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Martin Cracauer http://www.cons.org/cracauer/
_______________________________________________
Linux-audio-user mailing list
Linux-audio-user@lists.linuxaudio.org
http://lists.linuxaudio.org/listinfo/linux-audio-user

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[LAU] Gain and clipping wav -> lame, Martin Cracauer, (Thu Jul 25, 6:21 pm)
Re: [LAU] Gain and clipping wav -&gt; lame, Fons Adriaensen, (Thu Jul 25, 7:40 pm)
Re: [LAU] Gain and clipping wav -&gt; lame, Martin Cracauer, (Thu Jul 25, 8:14 pm)
Re: [LAU] Gain and clipping wav -&gt; lame, Fons Adriaensen, (Thu Jul 25, 9:44 pm)
Re: [LAU] Gain and clipping wav -&gt; lame, Ralf Mardorf, (Fri Jul 26, 4:29 am)
Re: [LAU] Gain and clipping wav -&gt; lame, Will Godfrey, (Thu Jul 25, 9:09 pm)
Re: [LAU] Gain and clipping wav -&gt; lame, Marc , (Thu Jul 25, 8:46 pm)
Re: [LAU] Gain and clipping wav -&gt; lame, Martin Cracauer, (Fri Jul 26, 10:35 pm)
Re: [LAU] Gain and clipping wav -&gt; lame, Marc , (Sun Jul 28, 4:45 am)
Re: [LAU] Gain and clipping wav -&gt; lame, Fons Adriaensen, (Sun Jul 28, 11:27 am)
Re: [LAU] Gain and clipping wav -&gt; lame, Jörn Nettingsmeier, (Sun Jul 28, 12:44 pm)
Re: [LAU] Gain and clipping wav -&gt; lame, Ralf Mardorf, (Sun Jul 28, 1:21 pm)
Re: [LAU] Gain and clipping wav -&gt; lame, Jörn Nettingsmeier, (Mon Jul 29, 1:29 am)
Re: [LAU] Gain and clipping wav -&gt; lame, Ralf Mardorf, (Mon Jul 29, 6:00 am)
Re: [LAU] Gain and clipping wav -&gt; lame, Marc , (Sun Jul 28, 2:21 pm)
Re: [LAU] Gain and clipping wav -&gt; lame, Edgar Aichinger, (Sun Jul 28, 12:00 pm)
Re: [LAU] Gain and clipping wav -&gt; lame, Ralf Mardorf, (Sun Jul 28, 12:21 pm)
Re: [LAU] Gain and clipping wav -&gt; lame, Ralf Mardorf, (Sun Jul 28, 11:47 am)
Re: [LAU] Gain and clipping wav -&gt; lame, Fons Adriaensen, (Sat Jul 27, 9:18 am)
Re: [LAU] Gain and clipping wav -&gt; lame, Martin Cracauer, (Mon Jul 29, 6:13 pm)
Re: [LAU] Gain and clipping wav -&gt; lame, Fons Adriaensen, (Mon Jul 29, 7:56 pm)
Re: [LAU] Gain and clipping wav -&gt; lame, Marc , (Sun Jul 28, 11:50 pm)
Re: [LAU] Gain and clipping wav -&gt; lame, Fons Adriaensen, (Mon Jul 29, 9:25 am)
Re: [LAU] Gain and clipping wav -&gt; lame, Philipp , (Mon Jul 29, 9:45 am)
Re: [LAU] Gain and clipping wav -&gt; lame, Fons Adriaensen, (Mon Jul 29, 10:13 am)
Re: [LAU] Gain and clipping wav -&gt; lame, Philipp , (Mon Jul 29, 1:27 pm)
Re: [LAU] Gain and clipping wav -&gt; lame, Fons Adriaensen, (Mon Jul 29, 2:15 pm)
Re: [LAU] Gain and clipping wav -&gt; lame, Philipp , (Mon Jul 29, 4:22 pm)
Re: [LAU] Gain and clipping wav -&gt; lame, Jörn Nettingsmeier, (Mon Jul 29, 1:27 am)
Re: [LAU] Gain and clipping wav -&gt; lame, Philipp , (Sat Jul 27, 7:10 am)