PreviousINDEXNext
Rebuilding mirrored disks on FreeBSDar deterministic mode breaks make

Raspberry Pi sound

Note: scroll to the bottom of the page for solutions.

I recently ran apt-get upgrade on my Raspberry Pi Model B Rev 2. The upgrade installed a new raspberian kernel:

  Linux red 4.19.118+ #1311 Mon Apr 27 14:16:15 BST 2020 armv6l GNU/Linux

The installation of the new kernel stopped sound working for both the applications I use, mpd and mpv. The 3.5mm headphone jack is used to play through a set of Ruark speakers.

mpv claimed to be playing, but no sound was emitted through the headphone jack. mpd produced the following error message:

  mpd error: exception: Failed to read mixer for 'ALSA Device': no such control: PCM

and was silent.

mpv is installed from a package, while mpd is built from source (so I had the latest version, not the old one in raspberian packages).

I had had an encounter with this issue a little while ago, as I had foolishly ran rpi-update. It got me an in-progress version of the stable version now installed. In that case, I downgraded back to the previous stable to solve the sound issue:

  sudo apt-get update; sudo apt-get install --reinstall raspberrypi-bootloader raspberrypi-kernel

The benefit of this brush with the future was that it gave me experience of the diagnostic tools required to identify and maybe fix the missing sound.

The kernel was booted with this set of flags:

  Kernel command line: coherent_pool=1M snd_bcm2835.enable_compat_alsa=0
  snd_bcm2835.enable_hdmi=1 snd_bcm2835.enable_headphones=1
  bcm2708_fb.fbwidth=592 bcm2708_fb.fbheight=448 bcm2708_fb.fbswap=1
  vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000  dwc_otg.lpm_enable=0
  console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/sda2
  rootfstype=ext4 elevator=deadline rootwait

Audio outputs had been created:

  bcm2835_audio soc:audio: card created with 4 channels
  bcm2835_audio soc:audio: card created with 4 channels

The clue is snd_bcm2835.enable_compat_alsa=0 that indicates old style compatabilty with ALSA has been turned off. This default setting can be subverted by adding a flag to /boot/cmdline.txt to override the kernel. The flag to add is: snd_bcm2835.enable_compat_alsa=1. You may need to make Headphone output the default by invoking sudo raspi-config. These modifications made the sound apps work again. However, I wanted to see if I could have sound with the stock kernel settings, i.e. without ALSA compatability.

In addition, I didn't want to change any of the default settings, but make things explicit in the configuration of the music apps. For example. raspi-config changes the default output device by writing an .asoundrc in my home directory. This tripped me up before when sound went weird, as I had forgotten all about the .asoundrc file.

So, back with the new standard kernel boot flags, aplay -l showed this:

  **** List of PLAYBACK Hardware Devices ****
card 0: b1 [bcm2835 HDMI 1], device 0: bcm2835 HDMI 1 [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 Headphones [bcm2835 Headphones]
  Subdevices: 4/4
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3

aplay -L showed this:

  null
      Discard all samples (playback) or generate zero samples (capture)
  jack
      JACK Audio Connection Kit
  pulse
      PulseAudio Sound Server
  default:CARD=b1
      bcm2835 HDMI 1, bcm2835 HDMI 1
      Default Audio Device
  sysdefault:CARD=b1
      bcm2835 HDMI 1, bcm2835 HDMI 1
      Default Audio Device
  dmix:CARD=b1,DEV=0
      bcm2835 HDMI 1, bcm2835 HDMI 1
      Direct sample mixing device
  dsnoop:CARD=b1,DEV=0
      bcm2835 HDMI 1, bcm2835 HDMI 1
      Direct sample snooping device
  hw:CARD=b1,DEV=0
      bcm2835 HDMI 1, bcm2835 HDMI 1
      Direct hardware device without any conversions
  plughw:CARD=b1,DEV=0
      bcm2835 HDMI 1, bcm2835 HDMI 1
      Hardware device with all software conversions
  usbstream:CARD=b1
      bcm2835 HDMI 1
      USB Stream Output
  default:CARD=Headphones
      bcm2835 Headphones, bcm2835 Headphones
      Default Audio Device
  sysdefault:CARD=Headphones
      bcm2835 Headphones, bcm2835 Headphones
      Default Audio Device
  dmix:CARD=Headphones,DEV=0
      bcm2835 Headphones, bcm2835 Headphones
      Direct sample mixing device
  dsnoop:CARD=Headphones,DEV=0
      bcm2835 Headphones, bcm2835 Headphones
      Direct sample snooping device
  hw:CARD=Headphones,DEV=0
      bcm2835 Headphones, bcm2835 Headphones
      Direct hardware device without any conversions
  plughw:CARD=Headphones,DEV=0
      bcm2835 Headphones, bcm2835 Headphones
      Hardware device with all software conversions
  usbstream:CARD=Headphones
      bcm2835 Headphones
      USB Stream Output

amixer also provides some useful information:

  [mark@red:~]$ amixer -c 0
  Simple mixer control 'HDMI',0
    Capabilities: pvolume pvolume-joined pswitch pswitch-joined
    Playback channels: Mono
    Limits: Playback -10239 - 400
    Mono: Playback 0 [96%] [0.00dB] [on]
  [mark@red:~]$ amixer -c 1
  Simple mixer control 'Headphone',0
    Capabilities: pvolume pvolume-joined pswitch pswitch-joined
    Playback channels: Mono
    Limits: Playback -10239 - 400
    Mono: Playback -13 [96%] [-0.13dB] [on]

mpd

In configuring mpd, the documentation gave me an idea of how to change the /usr/local/etc/mpd.conf file:

  # red mpd configuration file
  # mpd default configuration means this file must be at
  # /usr/local/etc/mpd.conf (very BSD)
  music_directory "/rep/music"
  playlist_directory "/rep/music/playlists"
  bind_to_address "192.168.0.17"
  bind_to_address "127.0.0.1"
  audio_output {
          type "alsa"
          name "ALSA Device"
          device "hw:1"
          mixer_control "Headphone"
  }

These settings re-enabled sound for mpd.

mpv

mpv has a very helpful feature; if you give it the command flag --audio-device=help, it will list all the audio devices it can find.

  List of detected audio devices:
  'auto' (Autoselect device)
  'alsa' (Default (alsa))
  'alsa/jack' (JACK Audio Connection Kit)
  'alsa/output' (output)
  'alsa/sysdefault:CARD=b1' (bcm2835 HDMI 1, bcm2835 HDMI 1/Default Audio Device)
  'alsa/dmix:CARD=b1,DEV=0' (bcm2835 HDMI 1, bcm2835 HDMI 1/Direct sample mixing device)
  'alsa/plughw:CARD=b1,DEV=0' (bcm2835 HDMI 1, bcm2835 HDMI 1/Hardware device with all software conversions)
  'alsa/usbstream:CARD=b1' (bcm2835 HDMI 1/USB Stream Output)
  'alsa/sysdefault:CARD=Headphones' (bcm2835 Headphones, bcm2835 Headphones/Default Audio Device)
  'alsa/dmix:CARD=Headphones,DEV=0' (bcm2835 Headphones, bcm2835 Headphones/Direct sample mixing device)
  'alsa/plughw:CARD=Headphones,DEV=0' (bcm2835 Headphones, bcm2835 Headphones/Hardware device with all software conversions)
  'alsa/usbstream:CARD=Headphones' (bcm2835 Headphones/USB Stream Output)
  'jack' (Default (jack))
  'sdl' (Default (sdl))
  'sndio' (Default (sndio))

The following command flag makes mpv sound work:

  --audio-device=alsa/sysdefault:CARD=Headphones
PreviousINDEXNext
Rebuilding mirrored disks on FreeBSDar deterministic mode breaks make