e42.uk Circle Device

 

Quick Reference

alsa Configuration

alsa Configuration

ALSA is quite confusing, there are two ways to interact with it. mpv is a common way of playing video and can list available output devices:

mpv --audio-device=help
List of detected audio devices:
  'auto' (Autoselect device)
  'alsa' (Default (alsa))
  'alsa/hdmi:CARD=HDMI,DEV=0' (HDA Intel HDMI, HDMI 0/HDMI Audio Output)
  'alsa/hdmi:CARD=HDMI,DEV=1' (HDA Intel HDMI, HDMI 1/HDMI Audio Output)
  ...

The devices in the above list are device specifications using device names. Unfortunately, these device names serve to confuse the issue when configuring alsa through /etc/asound.conf.

Device Naming is defined through a set of alsa configuration files, in Gentoo these files are located /usr/var/share/alsa/.

System-wide Output Configuration

Configuring system to fix output rate at 48000Hz and allow multiple applications to playback sound at the same time.

To discover the correct output use mpv with the --audio-device switch, in this example the output that works is:

mpv --audio-device=alsa/hdmi:CARD=HDMI,DEV=1 audio_file.mp4

IMPORTANT check the output of mpv for errors opening the ALSA device. I noticed that only 48000Hz files would playback sound correctly on my TV.

Discover the hardware devices using aplay:

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: HDMI [HDA Intel HDMI], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: HDMI [HDA Intel HDMI], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
...

Notice that the card number is 0 and the device number is 7 (the card name is HDMI and the device name is 1 -- this is the confusing bit). Create a hardware device in asound.conf for the HDMI hardware device and fix the rate to 48000:

pcm.hdmi_hw {
    type hw
    card 0
    device 7
    rate 48000
}

Create a dmix output to combine the sounds from the applications:

pcm.output_dmix {
    type dmix
    ipc_key 1234
    slave {
        pcm "hdmi_hw"
    }
}

dmix does not do sample rate conversion but alsa will fix that for a plug device. Create the default output PCM device:

pcm.!default {
    type plug
    slave {
        pcm "output_dmix"
    }
}

Now playback of any file will be re-sampled to 48000Hz, mixed with output from other applications and written to the HDMI output.

References

Quick Links: Techie Stuff | General | Personal | Quick Reference