The alsa interface

alsa allows access to raw ALSA audio playback and recording devices. This is equivalent to direct driver access to your audio hardware and may block other applications from recording or playing sound.

To provide better audio sharing and input and output configuration, it’s recommended that most snaps access audio functionality through the system audio layer, such as PulseAudio, via the audio-playback and audio-record interfaces.

However, raw access to ALSA devices using this interface can provide a slight performance advantage with input and output latency and avoid resampling which can reduce audio quality.

Example

The musical notation and composition application, MuseScore, is a good example of a snap that uses the ALSA interface.

To connect a snap to the ALSA interface, run the following command:

$ sudo snap connect <snap name>:alsa

Interface documentation:
See Interface management and Supported interfaces for further details on how interfaces are used.


Developer details

Auto-connect: no

The alsa interface is not auto-connected, in part, because not all hardware will multiplex clients and therefore may block audio.

The libasound2 library needs to be included in a snap’s stage-packages, of the part which uses ALSA, either directly or through some other package which brings it in (or manually compiled).

Code examples

The snapcraft.yaml for MuseScore includes an ALSA interface definition:
https://github.com/pachulo/musescore-snap/blob/master/snap/snapcraft.yaml

The source code for this interface is in the snapd repository:
https://github.com/snapcore/snapd/blob/master/interfaces/builtin/alsa.go

Why it is not auto-connected? Games won’t work without it, right?

Games are expected to use the system’s sound server instead of alsa directly since the sound server provides multiplexing and the opportunity to finely mediate recording.

Do you mean pulseaudio? Or newer pipewire?

Today, pulseaudio but eventually pipewire too. Today use the pulseaudio interface but the plan is to phase that out in favor of the audio-playback/audio-record interfaces which we’ll use to abstract out the sound server implementations.

2 Likes

There’s some discussion on https://bugs.launchpad.net/snapd/+bug/1835290 that indicates it would be useful to document common ways of using this interface correctly. Specifically it talks about a particular layout and set of packages to stage.

Why not just note within this documentation for alsa interface itself that

a) the libasound2 needs to be available in the snap’s runtime by being included in the stage-packages, of the part which uses alsa, either directly or through some other package which brings it in. OR ELSE needs to be compiled as a part, if someone wants that.

b) the $SNAP/usr/share/alsa needs to be exposed at /usr/share/alsa of the snap’s runtime by using the layout bind mechanism of snapcraft.yaml. i.e

layout:
    /usr/share/alsa:
        bind: $SNAP/usr/share/alsa

c) the need for user to explicitly connect the snap’s alsa plug to the snap system’s alsa interface using the below command

sudo snap connect SnapPackage:alsa

2 Likes