U-Law dithering

Windows version: Windows 10

The exact three-section version of Audacity from “Help menu > About Audacity”:

Section 1 — Audacity: https://pastebin.com/PjJZMWyE
Section 2 — Build Information: https://pastebin.com/88MBEjW7
Section 3 — GPL License: https://pastebin.com/i3WUAU1v

U-Law dithering is only by a very little amount. The distortion will still happen. Please fix this.

What that means, is the “version number”, which has 3 parts to it, separated by dots.
For example, this image shows the top of the “About Audacity” screen in the current release version:
3-part-version-number.png
The three part version number shown above is “2.2.2”.
We specify “3 parts”, because too many people write things like “I’m using version 2” or “I’m using version 2.x”, or “I’m using the latest version”, or “I’m using 2.2”, but none of these provide enough information. Each release has new features / enhancements / bug fixes / other changes, so what applies to one version may not apply to another.

Your version of Audacity is “Audacity 2.1.3”, which is now old and missing many features, bug fixes and enhancements that have been developed over the last year.


Please give steps to illustrate this problem.

But the forum text states “three-section”, and I gave the three sections. You stated “three part”.

Generate a 1Hz sine wave at 205887Hz Project Rate, which should contain all 16-bit PCM values, because it’s 65536×PI rounded down, but maybe the sine curvature will compensate for rounding down. Set “shaped” dithering from Preferences and Quality. Export to an other uncompressed file that is WAV and U–Law. Now open this file… and to your surprise the dithering didn’t work as expected — there is still a clear staircase, which is like a sawtooth wave distortion. Only when you zoom in at the beginning, middle or the end (where there are quiet samples and U–Law has greater precision) it’s possible to see the dithering clearly. Shouldn’t audio dithering adapt to the precision of the output? That seems difficult if the implementation is to add a small dither value to each sample. However it’s possible to calculate what the U–Law precision of the sample value is, and then adjust the value of the small dither. Of course the samples of the dither to be added are not fully independent with shaped dither, but still it’s possible to multiply the individual samples of the dither when necessary.

By the way, the forum has a glitch with Unicode: MEGA

If it is a 16-bit track, then generating any sound will give exact 16-bit values.
If the track is 32-bit float, then the sample values will not all be exact 16-bit values. For example, sample number 51471 has a value of sin((360 * 51471) / 205887) = 1.000000000, and the closest 16-bit value is 32767/32768 = 0.999969482.

Yes, that’s what should happen.

Yes, that would be possible, but it would be much slower, and no perceptual benefit. The level of dither noise would be considerably higher for larger amplitude sample values and would be clearly audible, similar to this:

Yes,thank you. That’s a known limitation of the forum software that we are using.

Of course. But I mean that it will contain all 16-bit PCM values, not just some of them.

Are you sure? There is still distortion. The entire purpose of dithering is to make the difference between original and output - noise.

Are you sure? There is still distortion. The entire purpose of dithering is to make the difference between original and output - noise. The fact that the noise would be clearly audible is a result of U-law having low precision at high sample values.

By the way your “big dither” didn’t mask the distortion properly either.

The purpose of dither is to break up cyclical repetition of quantization errors by distributing the errors into frequency bands that are least audible.

It wasn’t intended to. It was just a quick illustration of the high level of noise that would be created if μ-Law export was dithered in the manner that you suggested.

And noise has distributed frequencies, doesn’t it?

But anyway, the point is that dithering for U–Law doesn’t do its job.

Here is an example sound: MEGA

Using Audacity to shaped-dither it to U–Law, the output is MEGA . It clearly has cyclical repetition of quantization errors, so your statement “Yes, that’s what should happen.” is incorrect.

Then let me rephrase: That is the correct behaviour according to its design.

It does for audio close to zero, which is arguably the best compromise for μ-Law. At least, that appears to be the opinion of the developer that designed this feature.

That’s not complete dithering, if it only does for audio close to zero. That means the dithering only works properly in very quiet sounds, and barely does anything otherwise.

Correct. It’s a compromise.

It’s still an unexpected result though. Most people wouldn’t expect a Shaped dither that works powerfully in 16-bit PCM to barely do anything in U-law. Haven’t tested 8-bit PCM, A-law, Rectangular dither or Triangular dither.

Most people don’t care about dither in μ-Law exports.
In my opinion, the level of dither noise would be totally unacceptable if implemented in the way you suggest, so I will not promote this proposed feature.

Most people don’t care about μ–law or dithering at all.

However, there’s always “default and extension” — where you keep the default, but add an optional way to change the behavior.

And, in your “big dithering” sample, the noise seems to be whitely distributed. Isn’t shaped dithering supposed to “shape” the dithering noise to less audible frequencies? Will it still be “totally unacceptable” to you?

Yes, less audible when the peak level of the noise is below about -70 dB.

So the “big dithering” noise will be the same perceived volume with noiseshaping and without?

You agree that the linear amplitude difference between adjacent sample values for high level samples in u-Law format is around 0.03125 ?

Shaped dither randomises sample values by up to +/- 4 bits (for 16-bit linear PCM, that gives a peak level of around -72 dB).
So, for shaped dither where the linear distance between sample values is 0.03125, the required peak level for shaped dither is 8 x 0.03125 = 0.25.
Here is a sample of shaped noise with a peak amplitude of 0.25 (linear)

Note also that in order to achieve shaped dither without clipping, the u-law file would need to be limited to allow 4 bits of dither, which means that the peak level before dither must not exceed +/- 0.855347 linear.

Yes, it is 0.03125. In https://en.wikipedia.org/wiki/Μ-law_algorithm#Discrete, the largest interval is 256. It’s in a 14-bit scale, so it’s divided by 8192 and will produce 0.03125. u-law indeed has 6–bit LPCM’s precision at sample volumes from 50% to 100%.

And indeed, the noises of Rectangular and Shaped seemed similar in volume when I linearly amplified a sine wave by a divisive factor of 1024, then by a multiplicative factor of 1024 (simulating 6-bit LPCM), while Shaped seemed quieter when both factors were 256, simulating 8-bit LPCM. Of course, adaptive Shaped dithering may still be better quality than adaptive Rectangular dithering for U-law, because U-law is not always 6-bit LPCM quality.

However, it would still be nice to have a Preferences… setting that allows to enable adaptive dithering for U-law, A-law, 32-bit float and 64-bit float.

I don’t know what causes the weird effect that two noises may suddenly seem similar volume when increased in volume by the same factor.

If you can show me an implementation of your proposed u-Law dither that works, then I’ll suggest it to the developers.

The “equal loudness curve” becomes flatter as the volume level increases (Equal-loudness contour - Wikipedia)