# How does companding compress dynamic range?

Regarding when you 'compress' the signal, I typically see diagrams like this:

And the companding curve:

I can only see how the companding curve achieves a higher average SQNR by rounding down higher amplitudes more than lower amplitudes when making the quantization, according to a normal PDF, making the quantisation more efficient. I don't see how it reduces the dynamic range of the signal to the 'compressed dynamic range'. The only dynamic range compression I can see is that when the higher amplitudes are expanded again, they'll be expanded to the figure they were rounded down to during quantisation, reducing the upper dynamic range, but not the lower.

The dynamic range compression appears to be referring to the dynamic range of the signal after the compressor and before the expander, but this doesn't make sense. How can PCM samples have a dynamic range that isn't anything you want it to be.. and as the samples are uniform, surely a high rounded down amplitude now has a higher relative amplitude (sample 255/256 for instance whereas it was originally rounded down much more), and of course a lower amplitude is now a much higher amplitude.

What confused me is that there is a correspondence between 1.0 input amplitude and 1.0 output amplitude, which doesn't compress the dynamic range at all.

I hope that the key word in the output is 'relative' i.e. relative to the output range and it's actually mapping it onto a smaller dynamic range, though it looks like it's the same range. It would make sense to me if the dynamic range compression comes from the dynamic range that the samples are being mapped to is smaller than the input, and the companding curve is just a way to do this more efficiently than linear.

Why is the companding curve even called 'compression', surely the compression part is mapping it to a smaller dynamic range, or when using digital compression, the compression part is the reduction of bits in the PCM sample, and you can compress with linear companding, which wouldn't be considered compression at all if you were defining compression to be non uniform quantisation.

Companding is used when you want a signal to noise ratio (SNR) that's largely independent of the signal level.

Quantization noise is constant, so if the signal level varies, so does the SNR.

Let's consider an audio signal that's quantized at 8 bit. The quantization noise sits at -53dBFS. If you have a loud signal, i.e. -10dBFS you have a healthy 43 dB SNR. However, for a soft signal at -40dBFS, the SNR is very poor at 13 dB.

If you compand you can get an SNR of maybe 30dB for both cases, which is much better. The audibility of the quantization noise is NOT a function of the absolute noise level but the noise level relative to the signal. You can tolerate more noise, if the signal itself is louder since the louder signal masks more of the noise.

Companding implies that there is a decompression operation, whereas compression implies that it is lossy compression and the final product, which is just used to compress in a way that cannot be restored, which can be used for effect in a DAW, or to reduce file size. Though linear companding is lossy, it's still called companding because there's a basic decompression operation back to the original PCM bit depth.

A codec can employ digital companding, and the goal is to reduce the file size / increase the samples that can be sent per second on a transmission line, allowing for better sampling rates for the same amount of data, while preserving the dynamic range of the signal as best as possible.

When you sample a signal, it introduces quantisation noise into the samples, because the quantisation isn't exact because you've only got a 12 bit depth lets say. The dynamic range is therefore the max signal to average noise plus quantisation noise across the samples.

Now you could have a codec that just compresses it linearly to 8 bit samples by truncating the last 3 bits of the 12 bit samples, i.e. rounding down to a multiple of 8. This increases the quantisation noise in the samples because when you expand the samples to 12 bits again by adding 3 0s to the end, the samples now are more inaccurate and have higher granularity. Linear companding is therefore lossy, and you get identical to what you would have got if you just sampled with 8 bit samples in the first place, and therefore you get the dynamic range of an 8 bit depth sampling. So you don't preserve the dynamic range of the original signal.

That's why you get codecs like G.711 that use non linear companding such as A law companding, because they map the 12 bit samples of lower amplitudes to the 8 bit amplitude levels at 1:1 rather than 8:1 across the board, and then the higher amplitude samples obviously at 64:1, to make up for it, such that you get the same average 8:1 compression across the board. But of course, because most of the signal is in this dynamic range, you end up getting lower average quantisation noise, because most of the signal is quantised as if it were 12 bit PCM, so when you reverse this to get the 12 bit PCM samples again, the quantisation noise is similar to if it were truly 12 bit PCM, meaning the inherent dynamic range in these samples is now close to 12 bit PCM instead of the 8 bit PCM they were compressed to.

If you want to preserve the dynamic range of a signal in the analogue domain, you map it to the same dynamic range using an A law curve. Mapping it linearly will do absolutely nothing because it's the same dynamic range, but altering it with a companding curve will cause an 8 bit quantisation to quantise in the same way the 12 to 8 bit sample digital conversion does, except entirely analoguely. So you just get those 8 bit samples mentioned earlier straight out of the ADC. So you can actually do the companding curve in physical circuitry on the physical signal. In this case you don't compress the physical dynamic range, you just compress and expand the signal at a net 1:1 change because you're doing the digital domain companding but in the analogue domain

In compression of an analogue domain or digital domain analogue audio signal, where it is the final product, it is usually shown on an unnormalised plot where the input and output dynamic range (on the axes) are the same, in this case a 1:1 compression is $$y = x$$ and maps the amplitudes 1:1, whereas the dynamic range is compressed 4:1 above the threshold for instance, and you can see the new dynamic range on the output axis (y).

In the analogue domain, you are physically changing the dynamic range of the signal by mapping it to a new dynamic range, but in the digital domain, there is no concept of dynamic range, because the samples can be scaled linearly to any amplitude and output DAC, instead the quantisation noise defines the dynamic range, because it will be scaled with the signal, meaning the dynamic range is a fixed inherent property of the samples that doesn't change when scaling linearly.