amixer, multiple sound cards, PulseAudio

 

amixer, multiple sound cards, PulseAudio

To change the volume controls or other settings of most HiFiBerry sound cards, you can use the tool “alsamixer”. However, if you want to debug the settings, the command line tool “amixer” is often the better choice.

If everything is just working fine, you can simply run the command “amixer” and it will show you the settings of the sound card:

However, you might see something like this:

Simple mixer control 'Master',0
Capabilities: pvolume pswitch pswitch-joined
Playback channels: Front Left - Front Right
Limits: Playback 0 - 65536
Mono:
Front Left: Playback 65536 [100%] [on]
Front Right: Playback 65536 [100%] [on]
Simple mixer control 'Capture',0
Capabilities: cvolume cswitch cswitch-joined
Capture channels: Front Left - Front Right
Limits: Capture 0 - 65536
Front Left: Capture 65536 [100%] [on]
Front Right: Capture 65536 [100%] [on]

These are not volume controls from a HiFiBerry sound card and changing volume here might not have any effect at all.

Problem 1: Multiple sound cards

Using the command “aplay”, you can list all sound cards on the system:

aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: b1 [bcm2835 HDMI 1], device 0: bcm2835 HDMI 1...
  Subdevices: 4/4
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
card 1: Headphones [bcm2835 Headphones], device 0: bcm2835...
  Subdevices: 4/4
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
card 2: sndrpihifiberry [snd_rpi_hifiberry_dacplus], ...
  Subdevices: 1/1
  Subdevice #0: subdevice #0

We strongly recommend to disable the onboard sound. Different applications use different methods to select the sound card. Without any additional settings, almost all applications use the first sound card – which is the onboard sound in this case. While many applications can be configured to use a different sound card, this can be rather complicated. Feel free to check the documentation of the applications you’re using.

If you disabled the onboard sound, it should look like this:

aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: sndrpihifiberry [snd_rpi_hifiberry_dacplus], device 0: ...
  Subdevices: 0/1
  Subdevice #0: subdevice #0

Problem 2: PulseAudio

In 2021, The Raspberry Foundation decided to introduce PulseAudio as an additional audio layer in Raspberry Pi OS. While this software is used often in desktop environments, we don’t recommend it for any music player system. It not just adds complexity, but also resamples audio internally. The internal resampler is not the best you can find and you won’t get the best audio quality with it. PulseAudio creates a virtual sound interface, that multiple processed an use concurrently. This also creates problems setting mixer controls, as “amixer” will not display the right volume controls:

Simple mixer control 'Master',0
Capabilities: pvolume pswitch pswitch-joined
Playback channels: Front Left - Front Right
Limits: Playback 0 - 65536
Mono:
Front Left: Playback 65536 [100%] [on]
Front Right: Playback 65536 [100%] [on]
Simple mixer control 'Capture',0
Capabilities: cvolume cswitch cswitch-joined
Capture channels: Front Left - Front Right
Limits: Capture 0 - 65536
Front Left: Capture 65536 [100%] [on]
Front Right: Capture 65536 [100%] [on]

One way to work around this is to use a command line option for amixer telling it to explicitly use card 0:

amixer -c 0
Simple mixer control 'DSP Program',0
  Capabilities: enum
  Items: 'FIR interpolation with de-emphasis'...
  Item0: 'FIR interpolation with de-emphasis'
Simple mixer control 'Analogue',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 1
  Mono:
  Front Left: Playback 1 [100%] [0.00dB]
  Front Right: Playback 1 [100%] [0.00dB]
...

In combination with the “sset” command of amixer, you can set controls even with PulseAudio installed:

amixer -c 0 sset "Digital" 90%
Simple mixer control 'Digital',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 207
  Mono:
  Front Left: Playback 187 [90%] [-10.00dB] [on]
  Front Right: Playback 187 [90%] [-10.00dB] [on]
Last updated: November 30, 2021