1

I need a general way to select audio output of ALSA from bash or sh script. Script should work on different platforms, no knowledge about installed audio devices.

So best should be to have 2 scripts: 1) output list of audio outputs and 2) script to select and activate desired output

Question seem trivial but I googled a lot and cannot find solution yet. For example, on Raspberry Pi3 aplay shows me

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

and obvious solution like play on HDMI with "aplay -D hw:0,1 music.wav" does not work.

The only found solution to switch between HDMI and Jack on Raspberry I found is amixer cset numid=3 2 for jack and amixer cset numid=3 1 for HDMI.

$ amixer controls
numid=3,iface=MIXER,name='PCM Playback Route'
numid=2,iface=MIXER,name='PCM Playback Switch'
numid=1,iface=MIXER,name='PCM Playback Volume'
numid=5,iface=PCM,name='IEC958 Playback Con Mask'
numid=4,iface=PCM,name='IEC958 Playback Default'

But here I need knowledge about these particular numids for specific platform. On test x86 notebook list of amixer controls numids is significantly different. On notebook I do not see "PCM Playback Route" option.

So, is it possible to write general scripting solution which could work on different platforms? How to do this?

nckm
  • 103
  • 1
  • 10
  • Different hardware is different. What exactly do you mean with "general solution"? What device do you want? Why don't you use the default device? – CL. Jul 16 '19 at 16:09
  • I do develop custom embedded system for x86 using buildroot. Target platform is not exactly known, it can be notebook or PC or whatever. Notebook may have HDMI and Audio Jack and user may want to use HDMI speaker or Audio Jack. I need to make GUI which allows select Audio output. Unfortunately ALSA device seem does not correspond physical Audio output. I am searching way to list physical outputs and enable them, I do not need "ALSA device" because seem no way to find match between device and physical output. – nckm Jul 17 '19 at 17:43
  • If a HDMI/SPDIF output exists and if the configuration file for that hardware exists, the `hdmi`/`spdif` device will work. Otherwise, the devices listed by `aplay -l` are how the hardware looks from the kernel's point of view, and any additional routing done with mixer controls is nonportable and cannot be done in a generic way. – CL. Jul 17 '19 at 19:03

0 Answers0