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 audible when lossy encoding? (Read 6788 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Clipping audible when lossy encoding?

I ran upon this question when testing opus last night. But it's not a specific opus question.

I encoded my standard test set of various pop tracks in order to find out average bitrate for a certain opus bitrate setting.
But I also looked at the peak track values. They were often something like 1.35.
Thanks to the loudness war most of my original flac tracks have a peak of 1.0 or not much below.
With this basis it is clear that such things happen going from the time domain to the frequency domain and back.
But what does this mean for the final quality? With peak values ~1.35 can I be sure clipping is inaudible or avoided somehow?
With mp3 I always look at the track peak value given by foobar, and - if necessary - edit a track gain value of -1.5 db (or more if necessary) and apply track Replaygain to the file content. After that I expect listening with foobar can't have clipping issues any more. With other decoders things can be different, but I expect to have significnatly lowered the chance for audible clipping also in these cases.

I do the same with AAC files. But what about codecs like opus? What can I do to prevent clipping? Or are these worries irrelevant? I'm pretty much beyond certainties at the moment.
lame3995o -Q1.7 --lowpass 17

Re: Clipping audible when lossy encoding?

Reply #1
1.35 = +2.6dB so -1.5dB is not enough anyway.
Audibility may vary from track to track, need to ABX.
Safetest way to avoid clipping for all formats is to use a playback app with proper RG support.

Re: Clipping audible when lossy encoding?

Reply #2
...I've never used Opus.

If it's going over 0dB the file itself isn't clipped at 0dB.  However you'll clip your DAC if you play it at "full digital volume".

I've never heard of a case where the clipping caused by lossy encoding was audible.   That is, I've never heard of a case where lowering the volume (before encoding) made audible compression artifacts go-away, or of a case where lowering the volume improved the sound.  (Nor, have I ever heard of anyone doing these experiments.)

Quote
What can I do to prevent clipping?
You can use a 2-pass process...  Encode once to find the peak...  Lower the level by the required amount and encode again.   Or, take bennetng's suggestion and use ReplayGain (and make sure it's set-up to avoid clipping).

Re: Clipping audible when lossy encoding?

Reply #3
Applying the gain losslessly: one could hack together a search query that first selects those for which the peak is positive but not (in dB terms) larger than the RG (album peak and album gain, I would presume for the purpose) - and apply to those first, and then have a more careful look at the others. I don't think fb2k has logarithm or exponentiation in its query syntax though, so here is a chance to hone your Taylor expansion skills ...

But the topic leads me to a couple of questions ... it would be interesting to know whether there is anything that happens up there. A lossy representation need not stay below 0 dB in all samples even if the original does.
 - As long as there are only "a few samples every now and then" peaking over 0 dB, and that is nothing but part of the "loss" in "lossy": is there anything that says that clipping those makes it any worse?
 - Then: is there any reason to believe that +2.6 dB peaks are but an artifact of the lossiness, or would that be so large that you would think there must have been a volume bump in the process?

Re: Clipping audible when lossy encoding?

Reply #4
If the original clips at full scale then even applying a low-pass filter will cause samples to exceed full scale. This has nothing to do with lossy compression.

Re: Clipping audible when lossy encoding?

Reply #5
The issue is then whether the clipping is due to the original signal also clipping at full scale, then?
Exceeding 0 dB could be introduced when the signal is processed (in this case, by creating a lossy file).

Re: Clipping audible when lossy encoding?

Reply #6
Maybe I haven't made it very clear:

I don't blame lossy encoding for the clipping.
I'm well aware that any kind of processing within a digital transmission chain will lead to clipping if the input signal's peaks are close to 0 db (which unfortunately is true for most of the recently recorded pop music).

The only special thing with lossy encoding/decoding is that with different decoding software the transmission chain changes and so do the clipping details. Which also means that calculating the peaks with a specific piece of software and reducing the signal according to the calculated peak (or telling decoders to take the calculated peak value into account) doesn't necessarily prevent another decoding software from clipping (though I'd expect the clipping amount to be significantly reduced).

My question is:

a) do I have to worry about the clipping? I guess I have to, but I'd be very pleased if somebody could convince me of the contrary. Maybe there are studies out there about it, but I've never heard of it.

b) in case I must be afraid that the clipping can be audible in a way that is not negligible: what is the best way to deal with it as a general procedure? With mp3 and AAC the signal of the encoded track can be reduced losslessly in 1.5 db steps, and a simple procedure would generally reduce the signal by -3dB after encoding. That should provide a safety margin which I guess is sufficient ususally. For other codecs like opus: what is the most practical way to treat the problem?
lame3995o -Q1.7 --lowpass 17

Re: Clipping audible when lossy encoding?

Reply #7
a) do I have to worry about the clipping? I guess I have to, but I'd be very pleased if somebody could convince me of the contrary.
For that I suggest cognitive behavioral therapy.

Re: Clipping audible when lossy encoding?

Reply #8
Quote
a) do I have to worry about the clipping? I guess I have to, but I'd be very pleased if somebody could convince me of the contrary. Maybe there are studies out there about it, but I've never heard of it.
I'm not worried...  When I make an MP3 I know I'm making a lossy file...  But, I expect it to sound good (if the original sounds good ;) ) ...and it always does.

Some people reduce the volume before making a lossy copy, but I don't bother.

If I want perfection, I'll go lossless.

Re: Clipping audible when lossy encoding?

Reply #9
Is this in reference to my opus clipping remark?  If so, I was considering clipping because the artifact was described as sounding like it and the material was chiptunes, which can cause normally inaudible integer overflow or clipping bugs to suddenly become very noticeable.  A full scale square wave will often make it very clear if your processing steps need more headroom.

For software that handles things correctly, lossy induced clipping should not be audible.

Re: Clipping audible when lossy encoding?

Reply #10
[...]normally inaudible integer overflow [...]
Huh? The only way for "integer overflow" to be inaudible is to not overflow. Any tiny amount of overflow will be clearly audible. ( ok.. maybe with white noise it could be hidden under the SNR, but otherwise... )


Re: Clipping audible when lossy encoding?

Reply #12
Is this in reference to my opus clipping remark?
I did some internet research before I posted and I ran upon some opus remarks. Maybe that was yours. But I didn't really understand it anyway.
... the material was chiptunes, which can cause normally inaudible integer overflow or clipping bugs to suddenly become very noticeable.  A full scale square wave will often make it very clear if your processing steps need more headroom.
For software that handles things correctly, lossy induced clipping should not be audible.
If software handles things correctly, why not so for full scale square waves?
And how can software handle it correctly? Correct handling would mean for my understanding: scan the entire track in advance, and decode taking the peak value into account. I don't think any software does that. Close to that comes the RG peak value mechanism: the playback software takes into account the peak value calculated by another piece of software (which probably deviates a bit from the peak value the actual playback software generates).

Can software handle things correctly by another mechanism?

I am about to realize that clipping can be really audible. With today's recording practice pop music is not only stored close to full scale but is really clipped sometimes. And that can be very audible as I know from certain tracks. Strange I didn't remember that before. I really dislike the idea of adding more chance of audible distortion due to clipping.


lame3995o -Q1.7 --lowpass 17


Re: Clipping audible when lossy encoding?

Reply #14
I don't think that software should reduce the volume upon decoding to an unpredictable level (based on a few short high frequency peaks) unless specifically requested to perform normalization. When playing PCM floating-point format files, Winamp scans the whole fle for peak level, normalizes, and the normalization cannot be defeated. I believe it is incorrect, and a file should be replayed at the level it is recorded by default. (Or it would have been reduced in level.)

It is possible that clipping is audible in some cases, but I haven't ever heard it in music. Tracks subject to the loudness war usually contain enough distortion to effectively mask additional clipping noise. I've heard clipping in recordings of speech, at low bitrate and sample rate, where the clipping is longer in duration, and also due to speech signal being less busy than most music.

Integer overflows sound really nasty. An older version of the WavPack plug-in for Winamp had these (when playing floating-point files, this is now fixed) and also the latest official build of Speex command-line decoder (the Winamp plugin works correctly).

Re: Clipping audible when lossy encoding?

Reply #15
It is possible that clipping is audible in some cases, but I haven't ever heard it in music. Tracks subject to the loudness war usually contain enough distortion to effectively mask additional clipping noise.
This makes me pretty happy.
lame3995o -Q1.7 --lowpass 17

Re: Clipping audible when lossy encoding?

Reply #16
Uh ... nobody mentioned this?

Preferences -> Playback and under ReplayGain Processing, select "apply gain and prevent clipping according to peak".

Sometimes necessary even for lossless.  Not too often, as most music has a negative RG value.

Re: Clipping audible when lossy encoding?

Reply #17
That's what I called the RG peak value mechanism above.
lame3995o -Q1.7 --lowpass 17

Re: Clipping audible when lossy encoding?

Reply #18
Just did some experiments. My Realtek ALC892 has -5dB analog I/O differences with my X-Fi Titanium HD, so it means my X-Fi has 5dB headroom when recording the output of ALC892, which is good enough to see how ALC892 handle 0dBFS+ signals.

The attachment has two test files at 44 and 48k peaked at -1dBFS (Beware of loud volume!), I encoded them to different formats and examined their peak values. Take into account that these are mono files so their bitrates are actually pretty high. As shown in the attachment, opus has the highest peaks in both 44 and 48k, but exceptionally high in 44k, which I guess is caused by resampling rather than the lossy encoding process.

However, when I played the lossless version of both test files and captured ALC892's output, both 44 and 48k files needed to reduce 6dB to completely avoid clipping. So it means the lossless files themselves have DAC intersample peaks from +5 to +6dB, which means Track Peak from 1.778 to 2, not too far from the lossy peaks isn't it? Vorbis peaks are low because it encoded the whole spectrum, unlike other codecs with obvious lowpass.

44k:
https://youtu.be/gZ_18ROoUrg

48k:
https://youtu.be/JIW0L3Gcb0o

That's why I said if one is paranoid and wants to absolutely avoid clipping regardless of audibility, it is necessary to measure the analog output of individual files and playback devices.

My ALC892's RMAA results are pretty good.
https://hydrogenaud.io/index.php/topic,111980.msg922878.html#msg922878
My post said ALC887, it was a mistake. It was ALC892 on my ASRock B85M Pro4 motherboard.

Re: Clipping audible when lossy encoding?

Reply #19
That's why I said if one is paranoid and wants to absolutely avoid clipping regardless of audibility, it is necessary to measure the analog output of individual files and playback devices.
That's the point. I don't worry about the clipping per se, but I'm worried about situations where clipping might be audible. And I'd like to learn exactly about this.

Thank you for the test, anyway. It shows that when worrying about clipping one should be worried not just about peaks above fullscale generated by the digital process chain but just as well about intersample peaks which occur even with no processing at all. (Though I guess intersample peaks are related to high frequency noise which may be different for other kind of peaks).

It also shows a way to avoid clipping to a high degree of probability by giving a headroom of 6db before going analogue.

But if I understand you correctly you think I don't have to worry about audibility of clipping. Unfortunately you didn't go into detail. But it's in line with j7n's post which gave me confidence already. j7n gave some aspects about clipping noise and clipping duration in order to be audible which usually doesn't apply.
lame3995o -Q1.7 --lowpass 17

Re: Clipping audible when lossy encoding?

Reply #20
I'd worry about it when I came to it.  No point operating out of fear of things that pose no true threat to you.

Again, I recommend cognitive behavioral therapy.

Re: Clipping audible when lossy encoding?

Reply #21
j7n's reply is a very good one so I did not add my opinion about it. My reply was actually aimed at debunking the myth that lossy files are more likely to clip.

Re: Clipping audible when lossy encoding?

Reply #22
Is this in reference to my opus clipping remark?
I did some internet research before I posted and I ran upon some opus remarks. Maybe that was yours. But I didn't really understand it anyway.
... the material was chiptunes, which can cause normally inaudible integer overflow or clipping bugs to suddenly become very noticeable.  A full scale square wave will often make it very clear if your processing steps need more headroom.
For software that handles things correctly, lossy induced clipping should not be audible.

If software handles things correctly, why not so for full scale square waves?

If it handles things correctly, square waves should work just fine.  But if someone encodes loud square waves, and they hear a lot of distortion, odds are something didn't handle it correctly.

And how can software handle it correctly? Correct handling would mean for my understanding: scan the entire track in advance, and decode taking the peak value into account. I don't think any software does that. Close to that comes the RG peak value mechanism: the playback software takes into account the peak value calculated by another piece of software (which probably deviates a bit from the peak value the actual playback software generates).

In this context, correct just means using floating point for everything, not adding positive gain, and then clipping to integer at the very last step.  Most software will get this correct without even trying because most software runs on PCs that use floating point for audio samples and because its not that hard to avoid applying positive gain.  In this case, clipping will still happen, but it'll just be added at the last step, and it will be too small to matter.

Software that doesn't handle this correctly is software that doesn't use FP for everything, which is mostly older software or software running on embedded devices where FP is not an option.  This is mostly where I've ran into problems.  In this case you can make things a lot worse if you aren't careful, and it can be very hard to track down bugs.  When I ported libwma to fixed point for ARM systems, I then spent years tracking down strange overflow or clipping bugs that only happened in one sample in a thousand (in part this was because I had no documentation, but also because its just hard to do high quality fixed point really well). 

I don't consider using replaygain to automatically mean handling things correctly.  Everyone should use replaygain.  But that is up to the user to decide.  The software should do what the user tells it to, even if that means processing clipped audio.

Re: Clipping audible when lossy encoding?

Reply #23
Thank you, saratoga.
So with a carefully designed playback software I don't have to worry.
lame3995o -Q1.7 --lowpass 17

Re: Clipping audible when lossy encoding?

Reply #24

My ALC892's RMAA results are pretty good.
https://hydrogenaud.io/index.php/topic,111980.msg922878.html#msg922878
My post said ALC887, it was a mistake. It was ALC892 on my ASRock B85M Pro4 motherboard.

Very good to say the least. The quantity 10 piece price of this part on the spot market appears to be about a $buck.  It appears to easily equal or better the CardDeluxe that ran about $400 back in the day, and some of the better eMu and M-Audio devices that were around $150-200 within the decade.