#849203 libasound2: ALSA_PCM_DEVICE environment variable is ignored

Package:
libasound2
Source:
alsa-lib
Description:
shared library for ALSA applications
Submitter:
Leszek Godlewski
Date:
2017-11-04 14:30:03 UTC
Severity:
normal
#849203#5
Date:
2016-12-23 14:54:46 UTC
From:
To:
Dear Maintainer,

I have a PC with two on-board Intel HD Audio chips using the same driver. One of them outputs SPDIF to the HDMI connector, the other - to a separate SPDIF/analog jack. These chips are visible as separate cards:

inequation@BrixPro:~$ 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
card 0: HDMI [HDA Intel HDMI], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 0: ALC269VC Analog [ALC269VC Analog]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 1: ALC269VC Digital [ALC269VC Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

For most applications, the HDMI output is preferred and is set to be the default:

inequation@BrixPro:~$ aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
hdmi:CARD=HDMI,DEV=0
    HDA Intel HDMI, HDMI 0
    HDMI Audio Output
hdmi:CARD=HDMI,DEV=1
    HDA Intel HDMI, HDMI 1
    HDMI Audio Output
hdmi:CARD=HDMI,DEV=2
    HDA Intel HDMI, HDMI 2
    HDMI Audio Output
dmix:CARD=HDMI,DEV=3
    HDA Intel HDMI, HDMI 0
    Direct sample mixing device
dmix:CARD=HDMI,DEV=7
    HDA Intel HDMI, HDMI 1
    Direct sample mixing device
dmix:CARD=HDMI,DEV=8
    HDA Intel HDMI, HDMI 2
    Direct sample mixing device
dsnoop:CARD=HDMI,DEV=3
    HDA Intel HDMI, HDMI 0
    Direct sample snooping device
dsnoop:CARD=HDMI,DEV=7
    HDA Intel HDMI, HDMI 1
    Direct sample snooping device
dsnoop:CARD=HDMI,DEV=8
    HDA Intel HDMI, HDMI 2
    Direct sample snooping device
hw:CARD=HDMI,DEV=3
    HDA Intel HDMI, HDMI 0
    Direct hardware device without any conversions
hw:CARD=HDMI,DEV=7
    HDA Intel HDMI, HDMI 1
    Direct hardware device without any conversions
hw:CARD=HDMI,DEV=8
    HDA Intel HDMI, HDMI 2
    Direct hardware device without any conversions
plughw:CARD=HDMI,DEV=3
    HDA Intel HDMI, HDMI 0
    Hardware device with all software conversions
plughw:CARD=HDMI,DEV=7
    HDA Intel HDMI, HDMI 1
    Hardware device with all software conversions
plughw:CARD=HDMI,DEV=8
    HDA Intel HDMI, HDMI 2
    Hardware device with all software conversions
default:CARD=PCH
    HDA Intel PCH, ALC269VC Analog
    Default Audio Device
sysdefault:CARD=PCH
    HDA Intel PCH, ALC269VC Analog
    Default Audio Device
front:CARD=PCH,DEV=0
    HDA Intel PCH, ALC269VC Analog
    Front speakers
surround21:CARD=PCH,DEV=0
    HDA Intel PCH, ALC269VC Analog
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=PCH,DEV=0
    HDA Intel PCH, ALC269VC Analog
    4.0 Surround output to Front and Rear speakers
surround41:CARD=PCH,DEV=0
    HDA Intel PCH, ALC269VC Analog
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=PCH,DEV=0
    HDA Intel PCH, ALC269VC Analog
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=PCH,DEV=0
    HDA Intel PCH, ALC269VC Analog
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=PCH,DEV=0
    HDA Intel PCH, ALC269VC Analog
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=PCH,DEV=0
    HDA Intel PCH, ALC269VC Digital
    IEC958 (S/PDIF) Digital Audio Output
dmix:CARD=PCH,DEV=0
    HDA Intel PCH, ALC269VC Analog
    Direct sample mixing device
dmix:CARD=PCH,DEV=1
    HDA Intel PCH, ALC269VC Digital
    Direct sample mixing device
dsnoop:CARD=PCH,DEV=0
    HDA Intel PCH, ALC269VC Analog
    Direct sample snooping device
dsnoop:CARD=PCH,DEV=1
    HDA Intel PCH, ALC269VC Digital
    Direct sample snooping device
hw:CARD=PCH,DEV=0
    HDA Intel PCH, ALC269VC Analog
    Direct hardware device without any conversions
hw:CARD=PCH,DEV=1
    HDA Intel PCH, ALC269VC Digital
    Direct hardware device without any conversions
plughw:CARD=PCH,DEV=0
    HDA Intel PCH, ALC269VC Analog
    Hardware device with all software conversions
plughw:CARD=PCH,DEV=1
    HDA Intel PCH, ALC269VC Digital
    Hardware device with all software conversions
inequation@BrixPro:~$ cat /etc/asound.conf
defaults.pcm.card 0
defaults.pcm.device 3

However, for some applications, I'd rather have their playback directed to the jack (i.e. card #1). The ALSA environment variables ALSA_PCM_CARD and ALSA_PCM_DEVICE should be doing the trick; and while ALSA_PCM_CARD does work, ALSA_PCM_DEVICE does not. See /usr/share/alsa/alsa.conf.

What makes me suspect that is the case is this piece of an mplayer failed playback log:

inequation@BrixPro:~$ ALSA_PCM_CARD=1 ALSA_PCM_DEVICE=0 mplayer test.mp3
(...)
[AO_ALSA] alsa-lib: pcm_hw.c:1601:(snd_pcm_hw_open) open '/dev/snd/pcmC1D3p' failed (-2): No such file or directory
(...)

Please note the device path that refers to device #3, which is set as default in my asound.conf. Calling the same command line with ALSA_PCM_CARD=0 succeeds, although the audio plays on the HDMI output, which confirms my suspicion that card switching works, but device switching doesn't. I've actually written a script that tries ALSA_PCM_DEVICE from 0 to 100, and the result is always the same, which makes me quite convinced that the variable is being ignored.

A hacky, dirty workaround for the issue is to make a symlink from /dev/snd/pcmC1D0p to /dev/snd/pcmC1D3p. Playback works as expected then, but the symlink is ugly.

I simply expect to be able to pick the ALSA device via environment variables.

I'm on current ALSA package from testing.

Regards,

Leszek

#849203#10
Date:
2016-12-23 18:42:31 UTC
From:
To:
* Leszek Godlewski <lg@inequation.org> [2016-12-23 15:54 +0100]:

[...]

As far as i understsnd the sources you must prepare your device to
interpret ALSA_PCM_DEVICE. Try /etc/asound.conf as follows:

defaults.pcm.card 0
defaults.pcm.device 3
defaults.pcm.device {
    @func igetenv
        vars [ ALSA_PCM_DEVICE ]
        default 0
}

Now it should be possible to run
$ ALSA_PCM_CARD=1 ALSA_PCM_DEVICE=0 mplayer test.mp3


Elimar

#849203#15
Date:
2016-12-23 18:46:37 UTC
From:
To:
Hi Elimar,

If that is the case, why does ALSA_PCM_CARD work without such preparation?
/usr/share/alsa/alsa.conf contains a similar block for the card, yet it
isn't needed in /etc/asound.conf.

I will try it anyway and let you know if it worked, thanks!

Leszek

pt., 23 gru 2016 o 19:42 użytkownik Elimar Riesebieter <riesebie@lxtec.de>
napisał:

#849203#20
Date:
2017-01-11 18:31:18 UTC
From:
To:
* Leszek Godlewski <lg@inequation.org> [2016-12-23 18:46 +0000]:

Any news?

[...]

Elimar

#849203#25
Date:
2017-11-04 12:59:38 UTC
From:
To:
Hi Elimar,

Apologies for taking so many months to reply, this is unfortunately how
long it took for the use case to arise again.

Unfortunately, your fix to asound.conf didn't help. I'm on up-to-date
Debian testing, and with the contents of asound.conf you suggested (I
simply copy/pasted the contents of your last email), ALSA apps now report
this in the console:

ALSA lib conf.c:1385:(parse_def) device is not a compound
ALSA lib conf.c:1852:(snd_config_load1) _toplevel_:4:21:Zły argument
ALSA lib conf.c:3615:(config_file_open) /etc/asound.conf may be old or
corrupted: consider to remove or fix it
ALSA lib conf.c:3537:(snd_config_hooks_call) function snd_config_hook_load
returned error: Zły argument
ALSA lib conf.c:3986:(snd_config_update_r) hooks failed, removing
configuration

Which means I'm back to my old hack of symlinking /dev/snd/PCMC1D0p to
/dev/snd/pcmC1D3p again.

Regards,

Leszek

śr., 11 sty 2017 o 19:31 użytkownik Elimar Riesebieter <riesebie@lxtec.de>
napisał:

#849203#30
Date:
2017-11-04 14:01:00 UTC
From:
To:
Hi Leszek,

* Leszek Godlewski <lg@inequation.org> [2017-11-04 12:59 +0000]:

your use case is too specific for me. I can't reproduce :-( If you
want further support please try alsa-devel or alsa-user mailinglist:

[0] http://www.alsa-project.org/main/index.php/Mailing-lists

Elimar

#849203#35
Date:
2017-11-04 14:21:44 UTC
From:
To:
Thank you for your help. I'll escalate to alsa-user, then.

Regards,

Leszek

sob., 4 lis 2017 o 15:01 użytkownik Elimar Riesebieter <riesebie@lxtec.de>
napisał: