Hardware vs. Software Volume Control

Some users asked why the HiFiBerry DAC does not support volume control. It is true that the card itself does not come with the volume control widget that can be used by “amixer”. However, most music playback software has its own volume control. How does this work? Basically, the incoming audio samples will be scaled by dividing them by a given value. Dividing by 2 gives an output voltage reduction of 6 dB.

The following picture shows what happens. At the left side is the original, unscaled signal and on the right side a signal that has been reduced by factor 3 (which is roughly a 9db voltage reduction).

sin-fullpfeil200sin-half

With volume control in the playback software, the software will do this scaling and feed the data on the right side to the DAC.

But many people tell me, that is bad! Why is it bad? Because you will lose some resolution. Reducing the volume by 50% means that you will lose 1 bit. The resulting resolution will be only 23 bits now. If you decrease the volume further, you will lose more bits of resolution.

Is it really that bad? Remember, that most music that is available today is still recorded with 44.1kHz and 16bit. That means you can “lose” 8 bit with volume control on the DAC without really loosing anything from your music.

There is another downside of digital volume control: signal-to-noise ratio will decrease. That might be an issue in some areas. But many modern DACs have the noise floor at -110dB or even lower. If this increases to e.g. -90dB it is still a good value.

But some DACs have a “hardware” volume control. Having a mixer control in Linux means, that your software does not have to scale down the samples. The DAC will reduce the output volume. But how does it do this? Just have a look at the datasheets of the chips used on these sound cards. You will notice, that almost all chips with integrated volume control also use digital volume control, that means reduce the volume by dividing the digital data by some number.  This is not better than doing it purely in software.

Summary: Software volume control might have an impact on the audible performance, but with modern 24bit DACs, it often works quite well. Not every “hardware” volume control is really hardware. In many cases, it means that the software scaling is done inside a chip, but works exactly like a software volume control.

13 thoughts on “Hardware vs. Software Volume Control

  1. gebi

    Thx for this explanation. just a question:
    does the hifiberry always use 24 bit resolution from standard 44.1kHz/16bit stream ?
    E.g you play such a flac and the data stream will be 44.1kHz/16bit at the I2C. To get the full resolution upon SW volume control, the kernel-module need to fill out 8 LSB’s with zeros and send a 44.1kHz/24bit stream to the DAC. Or in other words: is the stream to the hifiberry always 24 bit ?
    thx in advance – Gear great project !

    Reply
    1. Daniel Post author

      That’s a very good question. The answer is: no. Usually all sound cards allow multiple resolutions. The application decides, which to use. That means with 44kHz/16bit, the application will often choose only this resolution.
      But there are applications, the can upsample all music to a higher resolution, e.g. Volumio. In this case, all music will be internally converted to e.g. 192kHz/24bit and then send to the DAC with this resolution.

      Reply
        1. Daniel Post author

          Hi San,

          the link that you posted addresses the some topic.
          Sending a signal that is to high can be a problem, mostly for tweeters. You won’t be able to destroy a woofer easily, but sending high-volume high-frequency noise to a tweeter can damage some tweeters.

          And you’re right – matching input and output is the best.
          The problem ist, that today there is no common standard anymore. 2VRms was a “de-facto” standard with CD players. Phono stage output often was lower (even in the past). New mobile devices often output max 1Vrms (sometimes even less). In case of doubt, a bit more is usually better. Reducing the volume by a voltage divider usually work well and is easy to accomplish.

          Daniel

          Reply
    2. Torsten Jaekel

      Hmmm, assuming a 24bit DAC and 16bit samples – why there should not be an effect by the software loudness control?

      I think with software loudness control, if you will realize a loudness change then you also reduce the resolution, always. It does not matter if 16bit or 24 bit for my understanding (24bit as extended 16bit samples does not gain any dynamic or additional samples).
      If you would do also upsampling, e.g. 44.1KHz -> 192KHz, this could improve a bit the software loudness control.

      Why SNR is affected – I do not understand: the SNR should be a parameter which is independent of the loudness. It is the lowest signal change which can be measured (before a signal change, bit change, disappears into the noise). The SNR specifies your effective resolution, the Effective Number of Bits. It can be much lower then 24bit. Even using a 24bit or 32bit DAC, for every bit you need approx. 6dB SNR. So, it ends up, for real 24bit resolution you need 144dB SNR which is not provided by any 24bit DAC. Assume with 100dB SNR which is quite excellent, you have just 16.6 bit resolution. 16bit effective resolution on most DACs, never mind if DAC would take 24 or even 32bit samples.
      A good SNR is mandatory to use software loudness control (the more bits you have the better in order to kill bits again to make it more quiet).
      SNR is a system parameter and consider the entire system: if your final power amp has just 100dB SNR, good to go with 24bit DAC but you will hear at the end just 16bits.

      My preference: use a hardware loudness control which is an attenuator at the output. In case of headphones for instance this small device with the wheel (as known on smartphones).
      Or on amplifier inputs: have a DAC which generates the correct input voltage, e.g. 2Vrms (with full signal swing). And the amp will have an input (or any other kind of) attenuator. Run the DAC with highest swing, e.g. on computer with max. loudness.

      BTW: if you think about, HW loudness control is the attenuation done in the DAC, e.g. via I2C control commands, it will do often the same: it scales the input samples down before processing it. Not really a difference.

      Why a real HW loudness control (at final output)?
      To degrade the signal early is not a good idea. Let the DAC run in best resolution mode, use the full swing but attenuate the signal later (as late as possible or where needed). The only drawback: you kill the signal power later in the signal chain (e.g. after amplification where amp runs in best performance mode) and the power efficiency of the system goes down.
      It helps also to make use of the SNR: take the signal away from the noise (noise floor), at input, low noise input stage, keep the signal swing large (keep and use the SNR during processing) and trim it at the output down to the needed level.
      (with other words: better to have a big water hose with fully loaded capacity and use a a small outlet instead to let trickle few drops of water through a big pipe ;-) )

      Reply
      1. Daniel Post author

        I fully agree, that a “pure” hardware volume control is the best solution in respect to SNR and dynamics. I do not say, that there is no effect. However with modern DACs, software volume control is not as bad as it was with 16-bit DACs, that usually had a much smaller SNR than modern 24-bit DACs.

        Why does scaling has an impact on SNR? SNR is the difference between full signal and the noise floor. If you scale down the full signal, this difference will be smaller, resulting in a lower SNR.

        Reply
  2. Martin

    You are right – if the 16 bit are simply shifted in the 24 bit I2S stream, the loss of quality is small.

    But Texas Instruments have a proper volume control chip (PGA2311), which has slightly better specs than Cirrus Logics CS3310 – both of them are digitally controlled analog volume controls with approx 120 dB dynamic range and very little distortion – a raspberry pi with such a volume control and a quality DAC would be a ‘real’ hifi solution, the question I have is if it would be possible to implement such a solution as a replacement of the existing digital volume control?

    Reply
    1. Daniel Post author

      It is possible to implement this. However it would most likely not work with the normal Linux mixer controls, therefore software had to be adopted specifically for this application.

      Reply
      1. Martin

        I thought so :-) I noticed that the Pi MusicBox was updated to support i2s output with your help – great!
        My interest is to have a Spotify ‘as high-as-possible-fidelity’ with a nice user interface, and I think that your RasPI DAC + a proper volume control + a custom version for the MusicBox would be an attractive solution.
        I have ordered some samples of the TI volume control and would like to help developing such a solution if you are interested.

        Reply
          1. Martin

            Ooops, I missed that, sorry!
            Regarding the volume control: what I want is to be able to control the analog volume control from a tablet or phone, the most elegant way would of course be to replace the routine that does digital volume control on the signal with a custom control of the analog volume control, through some of the GPIOs, but I don’t know what code to modify or how to rebuild the linux distribution, so I’m hoping that you (or anybody) can either do this or point out the code that does the volume control in the MusicBox/Mopidy software.

          2. Daniel Post author

            Hi Martin,

            as we do not develop the music player software, you should get in touch with the MusicBox/Mopidy developers.

            Best regards
            Daniel

  3. René Knuvers

    As far as I know, in DAC’s with digital volume control this may very well work using a small DA converter that actually controls the uref, a DC reference voltage that has a fixed relation to the analog full scale value. Hence, having digital volume control in such a set up will not affect audio performance like you described, This works like a digital controlled amplifier (opposed to a VCA, voltage controlled amplifier) and thus controls the relation between the digital domain Full Scale and the analogue domain FS value.

    However, weaker output signals will drown in the analogue noise floor of the output stage, so still the performance levels are diminishing. Having the output close to the rail increases the rise times, so adds some distortion to the signal. Overall, THD will most likely be close to optimal on the max output, but in fact it may be slightly better at a little lower signal level.

    Anyway, this is a bit of a theoretical discussion, Practical values shall be measured to have a real comparison. Fascinating stuff, these DAC’s

    Reply

Leave a Reply