Menu

Creating ALSA Aliases for specific devices that are then visible to userspace

2018-07-09
2018-07-22
  • Dejan Jovasevic

    Dejan Jovasevic - 2018-07-09

    Hi there,

    I was wondering if it is possible to edit /etc/asound.conf in such a way as to create alias names for specific devices, and then when a user space application enumerates audio devices have these aliases show up? My goal is to be able to create an alias for 2 hdmi playback devices (outputdev1, outputdev2 for instance), and then use this alias when searching for alsa devices in the application.
    ie. outputdev1 => plughw:CARD=X,DEV=Y
    outputdev2 => plughw:CARD=X,DEV=Z
    I have been able to create device aliases by editing the config as follows:
    pcm.outputdev1 { type plug slave { pcm "hw:1,4" } }
    pcm.outputdev2 { type plug slave { pcm "hw:1,6" } }
    And then using these aliases I am able to perform capture and playback using the alsa command line utilities aplay|arecord. However these aliases do not show up in my application.
    Using the definition of pcm.plughw in /usr/share/alsa/alsa.conf I have been able to construct my own pcm.outputdev type. This does show up when my appliction enumerartes alsa devices, however I am unable to specify just one device, so all plughw devices show up under outputdev aswell.
    DeviceName:plughw:CARD=PCH,DEV=0 DeviceName:plughw:CARD=PCH,DEV=1 DeviceName:plughw:CARD=PCH,DEV=4 DeviceName:plughw:CARD=PCH,DEV=6 DeviceName:plughw:CARD=PCH,DEV=7 DeviceName:plughw:CARD=PCH,DEV=9 DeviceName:outputdev:CARD=PCH,DEV=0 DeviceName:outputdev:CARD=PCH,DEV=1 DeviceName:outputdev:CARD=PCH,DEV=4 DeviceName:outputdev:CARD=PCH,DEV=6 DeviceName:outputdev:CARD=PCH,DEV=7 DeviceName:outputdev:CARD=PCH,DEV=9

    Thank you so much in advance,

    Dejan Jovasevic

     

    Last edit: Dejan Jovasevic 2018-07-09
  • Dejan Jovasevic

    Dejan Jovasevic - 2018-07-22

    The issue was not in the way I edited the ALSA config itself, but the way user space application was getting device hints from ALSA. I was looping through sound cards and then for each card I would call

    snd_device_name_hint (int card, const char *iface, void ***hints).
    

    and get back array of hints for all devices on that card. However, when I changed the logic and instead of looping through cards I called the fucntion with -1 snd_device_name_hint(-1,....) , I got back array with hints for all cards and devices I was able to see the aliases I created.

     

Log in to post a comment.