ALSA: open a PCM device in shared mode ALSA: open a PCM device in shared mode linux linux

ALSA: open a PCM device in shared mode


I couldn't find a way to share a device between multiple processes. I tried to use the dmix plugin to combine multiple playback streams using the .asoundrc configuration file but that didn't work for some reason. I tried to use the default device of my sound card but that didn't work too. According to a recommendation in ALSA mailing list I tried to open the default device using default:CARD=x as the device name parameter to the snd_pcm_open function which results in a device not found error in my system. Apparently there is no way to do this (if someone can find a way, please update this answer).

Rather than using ALSA, I used PulseAudio next which solved my problem.


The trouble with ALSA back then was the absence of a mixer plugin inserted in default output. In recent versions of ALSA, this does not happen anymore as dmix plugin is now included in the output path by default.

(You can recreate the shared soundcard trouble for yourself if you mess with ~/.asoundrc, or if you bypass the mixer by telling application to use directly the hardware plug. Note that some applications, such as JACK will try to use the hardware directly if not told to do otherwise.)

With PulseAudio, you still use ALSA as backend, you just added a layer with a mixer (and a ton of other things you probably do not even want to know about).JACK would do exactly the same job for you.

Nowadays, ALSA's dmix plugin will do it for you, so you can get rid of middleware such as PulseAudios and JACKs until you really need the non-basic sound system features they provide.

For reference, look up some .asoundrc documentation.


Check the file /dev/sndstat (if you have the OSS compatibility layer enabled). It should list audio devices which correspond to the ALSA devices on your system. And also you can check /proc/asound/devices to get features of each device.

Try access to different playback devices (in your example it's "plughw:0,0" opened) by choosing different names for snd_pcm_open():This is from here:

plughw:card,device. Both have as parameters the card (ID string or numerical index), device and optionally subdevice of the hardware to be accessed.