Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Clipping in MP3 (Read 1532 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Clipping in MP3

Hello

When replaygain scanning some newly converted mp3 files their peak is above 1 (1.3 -1.5). Their dynamic range scan shows they peak at 0dB. Does this mean the mp3 files are clipping? Should I lower the volume of the original lossless files before converting to avoid that situation? Should mp3 peak range stay up to 1?

Thank you for your advice

Re: Clipping in MP3

Reply #1
If the CD is close to full scale, the MP3 can clip upon decoding. You can use MP3Gain to adjust the volume of the MP3 file so it doesn't clip during playback, but AFAIK the clipping introduced by MP3 decoding is usually not audible. You definitely don't want to modify the original files before encoding them, as they would no longer be lossless if you did that.

Re: Clipping in MP3

Reply #2
Quote
When replaygain scanning some newly converted mp3 files their peak is above 1 (1.3 -1.5).   Their dynamic range scan shows they peak at 0dB.
I don't know but I generally trust ReplayGain and if you have it configured to avoid clipping it should reduce the volume if necessary, and that should take precedence over the ReplayGain adjustment.

I also trust Audacity to read-show the levels correctly.  If Audacity is set to Show Clipping it will show red where the peaks are over 0dB (or if you have several 0dB sample in a row).    Audacity shows potential clipping... It's not looking at the wave shape.    You can get false positives and false negatives.

MP3 can go over 0dB without clipping but you'll clip your DAC if you play it at "full digital volume".    But again, ReplayGain should reduce the level and prevent that possibility.

If the audio is really clipped (distorted), lowering the level won't fix it.

MP3 compression tends to make some peaks higher and some lower so the MP3 often goes over 0dB even though the uncompressed original didn't.   For that reason, many people normalize to -1dB, or so before compressing to MP3.

As far as I know, this slight clipping (when played at full-digital volume) isn't audible and if you hear a compression artifact it's probably something else.   And it's lossy compression anyway so you know it's not "perfect".    Lots of my MP3s ripped from CDs show red in Audacity and I don't worry about it.

Re: Clipping in MP3

Reply #3
It is possible to attenuate an MP3 in steps of 1.5 dB, losslessly (*), but as DVDdoug points out, MP3s may overshoot just as an artefact of the compression, and nothing says that the sound becomes worse if you clip these fake peaks that weren't in the original.


(*) OK, not completely losslessly in the bottom of the floating-point resolution, but you "lose nothing that was in the original" unless you deliberately attenuate by BIG numbers and then boost.


Re: Clipping in MP3

Reply #5
There is no need to reduce volume prior to encoding because clipping only happens during fixed point decoding. Even with music player that only supports fixed point decoding and does not support RG it can still be solved by using MP3Gain. Reducing volume prior to encoding can screw up things like gapless playback if users don't exactly know what they are doing.

The MAD decoder in some SoX builds decode to 28-bit fixed point with 4 bits of headroom, but SoX padded everything to the loudest bit and missed the chance of clipping prevention.

Re: Clipping in MP3

Reply #6
I can use foobar2000, Jriver media center or dbpoweramp. All three can adjust the volume during conversion or apply replaygain similarly to mp3gain (I think).
The mp3 files will be used in a portable player without replaygain support. I won't put my trust in its decoder to have 32fp processing. In that case I assume I should attenuate the volume to stop or reduce to minimum these clippings. Right?

Re: Clipping in MP3

Reply #7
Then you can use MP3Gain which is fully compatible with players without floating point and RG support. Especially, the GUI frontend of MP3Gain will list the file/album/aggregation of files and show the applied gain values, with undo metadata written on the files that you can revert if desired.

If you reduce the level before going into the encoder, there is no way to know how much volume you have reduced in the encoded files without referring to the original lossless input files.

Re: Clipping in MP3

Reply #8
Another alternative if the ability to undo is unimportant. You can do this on any existing mp3 files:
X
Reducing the level prior to encoding is hardly ideal as there is no way to know how much the encoded files will go over 1.0 (or not going over at all) before encoding, so you always need to encode > scan the encoded files to know the encoded peaks > discard the encoded files > re-encode from lossless. You can have some speculations by using fixed reduction value (e.g. 3dB) but this would be redundant for some files and at the same time not enough for some other files.

Re: Clipping in MP3

Reply #9
If mp3gain is a lossless process , meaning it doesn't re-encode the mp3 but only change its volume data and keeps all other audio intact - then indeed this sounds like the better way.
But still, if an mp3 is showing what seem to be clipping from and original that  was highly compressed but wasn't clipping, I understand from you guys' explanations that this is nothing to be worried about. It is how the encoder works. Did I understand correctly?

Re: Clipping in MP3

Reply #10
First, what is the purpose of generating these files? If these are expendable files (meaning: if they sound bad, you just delete them and re-encode) for use on devices that are not ReplayGain aware, then maybe apply ReplayGain is precisely what you want - you get your music played back on closer to constant loudness.

Then on to:

If mp3gain is a lossless process , meaning it doesn't re-encode the mp3 but only change its volume data and keeps all other audio intact - then indeed this sounds like the better way.
Explanation here: https://hydrogenaud.io/index.php/topic,34154.msg299025.html#msg299025
You may incur losses somewhere below -200 dB. Of course that shouldn't worry you - but it means you can sabotage it: if you want a 3 dB attenuation, and try to attenuate 240 dB and then boost 237 dB, then well ... so don't do that (except out of curiosity).

But still, if an mp3 is showing what seem to be clipping from and original that  was highly compressed but wasn't clipping, I understand from you guys' explanations that this is nothing to be worried about. It is how the encoder works. Did I understand correctly?
Yes ... but with some reservations. There are encoders that can - with the (in)appropriate command switch - alter the volume. If you did employ those, ...


Re: Clipping in MP3

Reply #11
If mp3gain is a lossless process , meaning it doesn't re-encode the mp3 but only change its volume data and keeps all other audio intact - then indeed this sounds like the better way.
Yes.  MP3Gain is an adjustment factor applied (reversibly) within the MP3 data itself, whereas ReplayGain is a setting in a tag.  Neither alter the actual audio data, but (as I understand it) MP3Gain is a feature of the MP3 specification whereas ReplayGain is an add-on which requires additional support.  However, ReplayGain is relevant to any audio format which includes tags, not just MP3.
It's your privilege to disagree, but that doesn't make you right and me wrong.

Re: Clipping in MP3

Reply #12
Reducing the level prior to encoding is hardly ideal as there is no way to know how much the encoded files will go over 1.0 (or not going over at all) before encoding, so you always need to encode > scan the encoded files to know the encoded peaks > discard the encoded files > re-encode from lossless.
Just to add that even with such a laborious approach it can still end up with something undesired.
X
original.wav is the input file with highest peak below 1.0
original v0.mp3 is directly encoded from original.wav

So it seems that reducing original.wav by 8dB into the encoder should be enough if the goal is clipping prevention instead of loudness normalization, turns out it is wrong. After 8dB reduction it is still 0.63dB above full scale even when using the same encoding settings (V0) because reducing level prior to encoding means the original input data is already different and the psychoacoustic model will do different things. This phenomenon varies among characteristics of input signal, encoders and settings of individual encoders, it is also possible that the highest encoded peak would be lower than expected after you adjusted the level before going into the encoder.

I attached the files so try to encode original.wav and see what would show up, and be careful as the file is very loud.

Re: Clipping in MP3

Reply #13
ReplayGain and MP3 gain both "fix" the audio and you no longer have "clipping".    (The MP3 isn't "clipped"...  It goes over 0dB and it will clip your DAC when played at full volume, or if decoded to an integer format.)
 
The original WAV file appears to be clipped but MP3 is lossy and it's going to change the wave shape in any case.    It might be "more accurate" to leave the levels alone.    MP3 "hides" the clipping but it doesn't fix the sound of distortion in the file.   (I'm not hearing distortion in the noise-file.)

Re: Clipping in MP3

Reply #14
The purpose of my post is to explain the differences between changing the input level to the encoder (which the OP originally proposed) versus changing the level of the encoded file in a way that works with audio players with no floating point and RG support.

It is not a listening test.

Re: Clipping in MP3

Reply #15
But still, if an mp3 is showing what seem to be clipping from and original that  was highly compressed but wasn't clipping, I understand from you guys' explanations that this is nothing to be worried about. It is how the encoder works. Did I understand correctly?
Yes. MP3 is lossy, so when you decode it to play the audio, the decoded samples won't exactly match the samples that went into the decoder. If the CD is close to full scale, the samples you get from the MP3 file might go over full scale sometimes. The solution is to use MP3Gain to reduce the overall volume of the MP3 by a few dB so that the audio doesn't go over full scale when you decode it anymore. Will you actually hear any difference? Probably not, but it doesn't hurt to play it safe.