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 5168 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.

Re: Clipping in MP3

Reply #16
Oh, so I'm not alone in this quest of dealing with MP3 clipping.

Quote
I often come across 44 kHz 16 bit lossless songs with True Peak between -0.5dB and 0dB, which is calculated using the recommended EBUR128 of Foobar2000 player. When converting to MP3 using LAME, I see that True Peak changes noticeably, it becomes between+0.5dB and +1.5dB, sometimes even higher. By trial and error, I found that using a preamp of -1.5dB in the conversion chain helps keeping True Peak in MP3 files around 0. But it's a manual method, more suitable when all songs to be converted have no headroom to spare, and if any song has enough headroom on its own, its volume seems to be reduced for nothing. So what is the best course of action here, or am I worrying in vain?

I see the solution was to use MP3Gain app. I tried it and didn't understand how to automate the workflow properly. It allows me to considerably lower the volume of an audio file ('apply Track gain', much like Replaygain does) or raise it without going above zero ('apply Max No-clip gain'). But how to automatically process only clipped MP3 without making the rest of them sound too quiet or too loud? That is, if lossless TP is -1.5dB and MP3 TP is 1.5dB, make the latter slightly below 0, not say -7dB. And if lossless TP is -15dB and MP3 TP is -13.5dB, then do not touch it at all.

For example, LAME 3.99.5 has an option --clip-detect which offers a proper --scale # flag after processing an audio file to eliminate the clipping if one is detected, but, as you may guess, it requires two manual passes.

Perhaps, Foobar's DSP component called ReplayGain Alternative might be the very answer?

• Join our efforts to make Helix MP3 encoder great again
• Opus complexity & qAAC dependence on Apple is an aberration from Vorbis & Musepack breakthroughs
• Let's pray that D. Bryant improve WavPack hybrid, C. Helmrich update FSLAC, M. van Beurden teach FLAC to handle non-audio data

Re: Clipping in MP3

Reply #17
Quote
I see the solution was to use MP3Gain app. I tried it and didn't understand its relevance in this case. It allows me to considerably lower the volume of an audio file (so-called 'apply Track gain', much like Replaygain does) or raise it without going above zero (so-called 'apply Max No-clip gain'), but I didn't find how to make clipping disappear only without making the rest of the sound too quiet or too loud. That is, if lossless TP is -1.5dB and MP3 TP is 1.5dB, make the latter slightly below 0, not say -7dB. And if lossless TP is -15dB and MP3 TP is -13.5dB, then do not touch it at all.
By default, MP3Gain (and ReplayGain) will avoid clipping.   (There is an option to turn that off.)

Quote
I tried it and didn't understand its relevance in this case. It allows me to considerably lower the volume of an audio file (so-called 'apply Track gain', much like Replaygain does) or raise it without going above zero (so-called 'apply Max No-clip gain'
It can go up or down depending on the target loudness (which is calibrated to a dB SPL reference).   Because most commercial recordings (including quiet-sounding ones) are 0dB normalized and can't be increased without clipping, the target loudness tends to LOWER the volume of MOST recordings so everything can be volume matched.

Quote
but I didn't find how to make clipping disappear only without making the rest of the sound too quiet or too loud.
The whole idea is make the volume of all songs about the same.   Some quiet songs should be boosted but most will be lowered.

Note that (unlike ReplayGain) MP3Gain works in 1.5dB steps because the MP3 volume can be adjusted in 1.5dB steps without decompressing-recompressing.  That means you can usually volume-match to within 0.75dB.

Quote
That is, if lossless TP is -1.5dB and MP3 TP is 1.5dB, make the latter slightly below 0, not say -7dB. And if lossless TP is -15dB and MP3 TP is -13.5dB, then do not touch it at all.
"True Peak" is an estimate of the peak in the reconstructed analog waveform.  (i.e. inter-sample peaks).  It doesn't (necessarily) exist in the digital data.  I assume the analog side of most DACs can go over 0dB without clipping and I don't worry about it.  It's the digital data that's hard-limited to 0dB. 

...As far as I know, any clipping resulting the MP3 "accidently" going over 0dB (as a compression artifact) is not audible.    I've never heard it and I've never heard about it being tested.  If you're hearing a compression artifact it's probably something else, and by choosing MP3 you've already accepted a lossy (imperfect) format.  ;)

Re: Clipping in MP3

Reply #18
Thanks to @Aleron Ives from Mp3gain Usage Guide topic, I learned that it is impossible to automate applying 'max no-clip gain' to clipped mp3s, because there is no corresponding flag in the console version of MP3Gain. Then I wrote to the author of ReplayGain Alternative DSP mentioned above, and he offered a non-console option, but at least related to Foobar2000, that kinda replicates 'max no-clip gain' functionality:

* Scan mp3 files via Replaygain scanner and select those with positive True Peak
* Context menu -> ReplayGain -> Apply gain to content…
* Target level: max (110 dB)
* Make files louder or quieter
* Lower adjustment to prevent clipping according to peak information



FLAC: LUFS -8.89, TP -0.10 -> MP3: LUFS -8.89, TP +1.51 -> MP3-FIXED:  LUFS -11.90, TP -1.50

However, the idea of True Peak is not as simple as one might think, even confusing when you read:
Quote
In practice, the calculated true peak value will always be higher than the sample peak.
Unlike sample peaks, the true peak can exceed full scale.

So, is there a clipping when True Peak in Foobar2000 is above 0 or not? Aggrrhh.
• Join our efforts to make Helix MP3 encoder great again
• Opus complexity & qAAC dependence on Apple is an aberration from Vorbis & Musepack breakthroughs
• Let's pray that D. Bryant improve WavPack hybrid, C. Helmrich update FSLAC, M. van Beurden teach FLAC to handle non-audio data

Re: Clipping in MP3

Reply #19
Here goes another way to prevent true peak clipping in lossy encoded files.
The author suggests the following DSP chain: Amplify +3dB -> Advanced limiter -> Amplify -3dB.

• Join our efforts to make Helix MP3 encoder great again
• Opus complexity & qAAC dependence on Apple is an aberration from Vorbis & Musepack breakthroughs
• Let's pray that D. Bryant improve WavPack hybrid, C. Helmrich update FSLAC, M. van Beurden teach FLAC to handle non-audio data

Re: Clipping in MP3

Reply #20
Quote
So, is there a clipping when True Peak in Foobar2000 is above 0 or not? Aggrrhh.
There could be.   The "true peak" doesn't exist in the digital domain so it's not up to foobar.    Maybe it should be called "analog peak" or "virtual peak", or "inter-sample peak".   But there is no inter-sample digital data and no samples on the analog-side.   If your DAC can't go over 0dB on the analog-side you can get clipping.    Integer data is hard-limited to 0dB but there is nothing that says the analog can't go over 0dB.


 

Re: Clipping in MP3

Reply #21
@DVDdoug, I'm sorry, you used a lot of words that are difficult for me to put together.

Previously, there was just Peak, i.e. how close is the track to the ceiling of 0 dB. The ceiling means the limit of the possible propagation of sound, try to rise higher and you will be consumed by the wrath of gods. Now there is True Peak that can exceed 0 dB. Isn't it jaw-dropping? It's like we're used to the fact there is no speed greater than the speed of light (the ceiling, the very limit), but it turned out there is.

True Peak is promoted as a more accurate metric and offered not only by Foobar2000, but also by expensive VST plug-ins used by the giants. Based on True Peak, other metrics such as PLR and PSR are calculated, which are used instead of DR to understand the dynamics of the track. So, whatever it's called, I try to learn how to take it into account when creating a lossy conversion chain and for listening on any hardware.

My goal is to find as automatic as possible way to produce lossy encoded files that are free from clipping with minimal volume loss and minimal waveform distortion. But how can this be achieved if TP seems as vague as quantum studies?

• Join our efforts to make Helix MP3 encoder great again
• Opus complexity & qAAC dependence on Apple is an aberration from Vorbis & Musepack breakthroughs
• Let's pray that D. Bryant improve WavPack hybrid, C. Helmrich update FSLAC, M. van Beurden teach FLAC to handle non-audio data

Re: Clipping in MP3

Reply #22
I'm sorry, you used a lot of words that are difficult for me to put together...
Let's see whether I can explain...

In the digital domain, the waveform is just samples.  Reconstructing the waveform into continuous analogue involves estimating what the signal was which resulted in those samples.  The estimate will be perfect if there were no frequency components in the original waveform greater than half the sampling frequency.

If an input with 0dB peaks is sampled, the only digital samples at 0dB (ie full scale) will be those where the sample point happens to coincide with the peak of the input waveform.  Mostly, the samples will be either side of the peak, and therefore at digital values slightly lower than maximum.  If the digital waveform has no samples at maximum, and is then scaled so that the peak sample is at maximum, reconstructing the analogue waveform will require the waveform to go above 0dB.

This is not a problem in the digital data, and it is not a problem in the DAC, but it might be a problem if there is no headroom in the output filter to accommodate an analogue peak slightly over 0dB.

Hence all this vagueness about digital peak and analogue peak.  Digital music players are working in the digital domain where the peak sample value is not necessarily coincident with the peak analogue voltage.  But, except for highly contrived waveforms, there is hardly any difference and any slight clipping as a result would be barely audible (if at all).
It's your privilege to disagree, but that doesn't make you right and me wrong.