The DIY Music Streamer Part 5.


We now seems to have a working Mopidy and shairport-sync installation. But lets take a closer look under the hood and also spend some time to understand how to best integrate this music streamer with the rest of our audio gear. This off course depends on your preferences and audio gear but I will use my current setup as an example, your mileage may vary.

The HiFiBerry DAC+ is said to have a maximum output voltage of 2.1 Vrms. My power amp (TC2000 controllers and sta508 power stage chips) got an input sensitivity of 1.5 V. I will connect my music streamer to my preamp and I don't want my preamp to output more than 1.5 Vrms from the streamer. The gain of my preamp on the AUX port is set to x 2.2 (6.92 dB) and is set to give a normal listening volume from my turntable with the volume control on my preamp at around 12 o'clock. The volume control on my preamp is a stepped attenuator with a logarithmic curve from 0 dB down to -62 dB. The attenuation at 12 o'clock is -22 dB. My RIAA preamp has a gain of 38 dB at 1 kHz and is then fed into the preamp. My current turntable cartridge is a Shure M75M-G, quite hot with a rated output of 6.2 mV. That is a lot of information but needed for the following calculations.

RIAA stage: 6.2 mV amplified 38 dB = 492.5 mV
Preamp stage: 492.5 mV amplified 6.92 dB = 1.01 V
12 o'clock: 1.01 V attenuated 22 dB = 86.7 mV

1.01 V output is well under the power amps input sensitivity. What if we fed the preamp the maximum 2.1 Vrms from the HiFiBerry DAC+?

Preamp stage: 2.1 V amplified 6.92 dB = 4.65 V
12 o'clock: 4.65 V attenuated 22 dB = 370 mV

That is a big voltage difference between the turntable and the streamer as a source. The 4.65 V output level is unacceptable and a factor four and some between sources with the volume control at 12 o'clock, it is way to much for my liking. Lets see what we can do about it.

We first need to understand where the volume level can be controlled and how. The volume control in the preamp is usually some form of attenuator with a logarithmic profile and a range around 60 dB. A DAC like the HiFiBerry DAC+ also got builtin controls to alter the output level. These controls can be implemented in the analog or digital domain and in hardware or in software (or any combination thereof). Lets take a closer look at the HiFiBerry DAC+, open up a terminal and logon to your Raspberry Pi.

ssh pi@192.168.1.10

Start by trying to playback a file through the DAC with the following command:

sudo aplay /usr/share/sounds/alsa/Noise.wav

You might get an error message if you followed this guide and created the /etc/asound.conf file with the recommended settings (just like in many other guides online). The error message looks like this:

aplay: set_params:1345: Channels count non available

Modern version of ALSA doesn't need asound.conf and what to take away from this is not to trust any source on the Internet but to take a look under the hood in order to fully understand your hardware, software and configuration. If you created the asound.conf remove it with:

sudo rm /etc/asound.conf

Try to playback the file again and it should just work. Next stop is to figure out what the DAC looks like from an ALSA perspective. The following command:

aplay -l

Will output:

card 0: sndrpihifiberry [snd_rpi_hifiberry_dacplus], device 0: HiFiBerry DAC+ HiFi pcm512x-hifi-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0


It is telling us that we only got one sound card in this configuration and that sound card only got one device aboard. It makes things much easier than if we would have had several cards with several devices. We still need to understand how to control this card, especially the volume control. The following command:

amixer controls

Will output:

numid=6,iface=MIXER,name='DSP Program'
numid=3,iface=MIXER,name='Analogue Playback Boost Volume'
numid=2,iface=MIXER,name='Analogue Playback Volume'
numid=10,iface=MIXER,name='Auto Mute Mono Switch'
numid=11,iface=MIXER,name='Auto Mute Switch'
numid=8,iface=MIXER,name='Auto Mute Time Left'
numid=9,iface=MIXER,name='Auto Mute Time Right'
numid=7,iface=MIXER,name='Clock Missing Period'
numid=5,iface=MIXER,name='Deemphasis Switch'
numid=4,iface=MIXER,name='Digital Playback Switch'
numid=1,iface=MIXER,name='Digital Playback Volume'
numid=20,iface=MIXER,name='Max Overclock DAC'
numid=19,iface=MIXER,name='Max Overclock DSP'
numid=18,iface=MIXER,name='Max Overclock PLL'
numid=16,iface=MIXER,name='Volume Ramp Down Emergency Rate'
numid=17,iface=MIXER,name='Volume Ramp Down Emergency Step'
numid=12,iface=MIXER,name='Volume Ramp Down Rate'
numid=13,iface=MIXER,name='Volume Ramp Down Step'
numid=14,iface=MIXER,name='Volume Ramp Up Rate'
numid=15,iface=MIXER,name='Volume Ramp Up Step'


That is a lot of controls. Most of them are controls exposed by the device driver and not intended as user controls. The ones of interest are:

numid=1,iface=MIXER,name='Digital Playback Volume'
numid=2,iface=MIXER,name='Analogue Playback Volume'
numid=3,iface=MIXER,name='Analogue Playback Boost Volume'

Lets take a closer look at them one by one. Start with the following command:

amixer cget numid=1

It will output:

numid=1,iface=MIXER,name='Digital Playback Volume'
  ; type=INTEGER,access=rw---R--,values=2,min=0,max=207,step=0
  : values=201,201
  | dBscale-min=-103.50dB,step=0.50dB,mute=1


This is actually the primary volume control of the HiFiBerry DAC+ in the current device driver (it has previously been accessed by names like 'PCM' and 'Master' but is now replaced on a low level by 'Digital Playback Volume'. Note that ALSA sometimes truncate strings like name if they contain space characters. 'Digital Playback Volume' can therefor be just Digital so you might have to use quoted full strings or just the truncated string without quotes.

We can get a lot of information about this mixer control from the output above. It is a mixer interface with id=1. It has two values (left and right channel) of integer type. Min value=0 and max value=207. The dB scale is from -103.5 dB in 0.5 dB increments.

207 * 0.5 = 103.5. A value of 0 ought to equal -103.3 dB and a value of 207 ought to equal 0 dB. Seems logical right? But what about the other two interfaces? Next command:

amixer cget numid=2

Will output:

numid=2,iface=MIXER,name='Analogue Playback Volume'
  ; type=INTEGER,access=rw---R--,values=2,min=0,max=1,step=0
  : values=0,0
  | dBscale-min=-6.00dB,step=6.00dB,mute=0


It is another mixer interface and the name hint at analog volume control. It is an integer value and the min value is 0 and the max value is 1. The dB scale is from -6 dB dB in 6 dB increments. This tell us that it is not a regular analog volume control. It is more of a switch to attenuate the analog output signal 6 dB or not.

Next up is the  following command:
 
amixer cget numid=3

It will output:

numid=3,iface=MIXER,name='Analogue Playback Boost Volume'
  ; type=INTEGER,access=rw---R--,values=2,min=0,max=1,step=0
  : values=0,0
  | dBscale-min=0.00dB,step=0.80dB,mute=0


You can probably guess by now that this is another mixing interface. An integer value, min=0, max=1 in 0.8 dB increments. Another switch like interface in order to boost the analog output 0.8 dB or not.

We should now have a better understanding of how ALSA interfaces with the DAC hardware through the device driver. But how is Mopidy and shairport-sync controlling the volume? Mopidy is using software volume control by default and it is controlled in the [audio] section of the configuration file. Shairport-sync is also using software volume control is nothing else is stated in the alsa section of the configuration file.

I guess you are starting to understand the complexity of the whole  audio chain. We got different volume controls in our DAC, ALSA, Mopidy, shairport-sync and our preamp. You can read more about the pros and cons of software vs. hardware volume control in this blog post. But it is not only a question of sound quality, it is also a question of convenience and usability. A volume range of 103.5 dB is not convenient from a usability standpoint. Having different volume levels from different sources and software with the preamp volume control at the same position is also an inconvenience etc. My next post will therefor be about how volume control can be addressed in our streamer.