|
Audio Asylum Thread Printer Get a view of an entire thread on one page |
For Sale Ads |
68.127.105.125
In Reply to: What's the math behind a digital volume control? posted by JayM on February 8, 2007 at 17:46:32:
Digital volume control with a PCM bitstream is actually very simple, you simply multiply each sample by a binary constant. This apparent simplicity is a trap for improperly implemented digital volume controls that can really mess up a digital signal. The result length in bits of any binary multiplication is equal to the sum of the word lengths of both input terms. For example a 16 bit pcm signal multiplied by a 16 bit volume control constant results in a 32 bit binary number. This conversion is completely loss-less, the original signal can be completely reconstructed from the 32 bit output data. However as there are no 32 bit DACs a 32 bit bitstream must truncated and possibly dithered or noise shaped to a manageable word length before it is converted into analog audio. Truncation is always a lossy process, once a signal is truncated no amount of processing may restore the original, it may be possible to to make any truncation artifacts inaudible with dither or noise shaping but the key to good digital volume control is to avoid any lossy translations. Instead of multiplying the pcm bitstream by a 16 bit constant you may multiply it by constant with an 8 bit or less word length, a 16 bit data stream and 8 bit volume coefficient will result in a 24 bit word, which is attainable by many high quality DAC designs so no truncation is required. However the loss-less resolution of the result comes at the price of volume control steps that do not accurately track the ideal logarithmic attenuation curve, an 8 bit word my only attenuate a signal by a maximum of 48db and the last few steps will be very large making a reasonable attenuation limit of an 8 bit volume coefficient about 30db or so.The best digital volume controls are those that use a table that attempts to limit the amount of truncation needed. Such a volume control may use 4 bit constants for the first few attenuation levels, then gradually increase the word length as needed for greater amounts of attenuation. This table should include as many "magic" attenuation values as possible, -6.02db is only a 1 bit coefficient, -12.04db is only 2 bits ect... This approach maximizes the signal quality but also minimizes the linearity of the attenuation steps so that each volume step will be slightly different, however as volume control is more of a bulk attenuation and human hearing can easy adapt, a linear volume control is not really necessary.
It should also be apparent that the least amount of attenuation possible should be used in a system with digital volume control, in an ideal system you should always be listening as near as possible full volume, this usually requires amplifiers with low gain. This can be a real problem since most amplifiers are designed with as much gain as possible to give the customer the illusion of "Power". Using amplifiers with too much gain requires too much digital attenuation at normal listening levels leading to very low resolution (too much truncation of the digital signal before it is converted in the DAC.) Digital volume control should also never be used with DACs of insufficient word length, a 16 bit DAC will require truncating a CD resolution digital input for any attenuation value at all so digital volume controls should only be used with DACs capable of converting word lengths of 20 bits or more. Of course better, higher resolution DACs result in better sound quality with digital volume control than lesser DACs. An acceptable DAC used without digital volume control may become unlistenable when used with digital volume control due to linearity errors that are normally masked when converting full level data, delta sigma DAC designs are perhaps the worst in this respect while sign-magnitude DAC designs are the best. A sign-magnitude DAC always increases its linearity with decreasing signal level making it ideal for digital volume control use. A delta-sigma DAC on the other hand has a noise level that increases with decreasing signal level making most of DACs of this type very poor choices to use with digital volume control.
Follow Ups:
Why do some dacs say they handle 32 bits when you say there is no such thing? Are the manufacturers lying?
Howdy24 bits (144 dB) covers the dynamic range from individual air molecules bouncing on the ear drum to being at the exhaust of a jet engine. You don't need more.
It's actually hard to build a DAC that's much better than 20 bits (120 dB)
It's easy for a DAC (or most anything else) to accept more bits than it can fully use and also on general purpose computers often 32 bits (4 bytes) is easier to handle than 24 bits (3 bytes.)
Thanks for the excellent explanation. If we want to increase the volume in the digital domain are the pitfalls the same? I remember reading that if you increase volume digitally by 6.02dB that no dither need be applied if the word length is reduced.Nearly all the reading I have done is about reducing word length from 24 bit to 16 bit in order to make a CD. But if you are, for example, recording off the air to hard drive using a 24 bit A/D and playing back using a 24 bit D/A there is no need to truncate to 16 bit. However, and this where I get confused, most (all?) digital components process internally at far greater than 24 bit (typically 72dB???).
So even when our final output stage is 24dB, doesn't this always represent a truncation from a (much?) larger word with all the potential problems you have outlined above?
I have not been able to find anything about truncating from say 48dB to 24dB? Do you have any links?
Increasing the volume of a digital signal is less lossy than decreasing it, the multiplication rule still applies, however since your output is larger than your input you gain one bit of resolution as you pass the bit transition at +6.02db, 2 bits at +12.04db ect... There is one significant problem tho, if any output sample exceeds the bounds of the digital output format it is clipped to the maximum (or minimum). This appears as a hard clip similar to overdriving a transistor amplifier. As most recordings are purposefully recorded close to full scale to extract the maximum performance from the A/D converters they were recorded with there is usually very little space available for increasing the level of a digital signal before it clips. You can attempt to decrease the audibility of a clipped digital waveform by soft limiting the clipped portions which creates a rounded clipped waveform similar to an overdriven tube amplifier, however there is still significant distortion added. Therefore it is best not to attempt any digital volume increase unless you know the exact form of the input signal and are confident it will not clip.If you require amplification it is best to apply it in the analog domain after the DAC (or in the DAC itself with some designs.) Then you can use digital attenuation which has no chance of clipping.
Too bad we can't sticky it. Whenever this topic comes up I start a post but bail out when it's apparent that it needs somethign as long as you've written to do it well.However, once you have the full picture, a couple rules of thumb can be used
a) if you only have a 16-bit capable DAC, forget it
b) if you have a 20-24bit capable DAC, you can get between 10 and 20dB of attenuation before any degradation sets in (depends on the low-level linearity of the DAC)
c) gain structure of your downstream system has to be set up properlyI think the idea of a hybrid system where you have an analog stepped attenuator with 10dB steps for coarse adjustment and a digital control for ~10dB of 'fine' adjustment is pretty attractive.
Your distillation of my post is right on the mark, digital volume control should never be used to correct the gain structure of a system, it should only be used for adjusting the gain differences between recordings. Your hybrid analog/digital volume control idea is a great solution.
This post is made possible by the generous support of people like you and our sponsors: