A Preliminary Study on the Configuration File of PulseAudio Sound Card

Deepin
5 min readJun 7, 2022

--

PulseAudio is an audio management framework for the deepin system, which is a proxy for the application’s audio capabilities. As audio data is passed between the application and the hardware, it performs advanced processing operations on the data. Only when the sound card information is correctly mapped to PulseAudio through the PulseAudio sound card configuration file, the system can use the sound card correctly. The PA abbreviation will be used later to represent PulseAudio.
This article will describe the following two directories and one file, because these are closely related to the configuration of the sound card in the PA.

Two directories:

$ ls /usr/share/pulseaudio/alsa-mixer/profile-sets/

$ ls /usr/share/pulseaudio/alsa-mixer/paths/

a file:

/lib/udev/rules.d/90-pulseaudio.rules

  1. Directory: /usr/share/pulseaudio/alsa-mixer/profile-sets/

In this directory, the configuration file specifies how to open the audio device and the mixer path to be used. Default.conf is the core file, which is the default configuration file definition for the ALSA backend of PA. This file is used for all non- Fallback for specially mapped sound cards (suitable for most sound cards).

If you need to assign a different configuration to the device than this default.conf configuration file, you need to set the udev property PULSE_PROFILE_SET specifically for the device, or use the “profile_set” parameter to specify the newly added profile configuration when loading the PA’s module-alsa-card module document.

So what’s in this newly added profile set? In short, what is done in this file is to map how ALSA devices are exposed in the PA.

Specifically, which ALSA device string to use to open the device, which channel mapping to use, and which mixer path to use, this is called “mapping”, and many mappings can be bound together in the profile , which is then displayed directly in the user interface as sound card information.

If a profile is selected by the sound card, and a mapping is assigned to a profile, a sink or source will be created.

As shown in the figure below, the mapping name is analog-stereo, the ALSA device string device-strings is front:%f, the channel mapping is left, right, and the mixer path is paths-output and paths-input. These two paths will be Causes the PA to create a sink or source (ie, an audio output port or input port).

2. Directory /usr/share/pulseaudio/alsa-mixer/paths/

The files stored in this directory are the mixer paths mentioned in the previous section. These paths correspond to the contents pointed to by the paths-output and paths-input of the mapping in the profile sets.

For example, for analog-output-lineout in the paths-output item of a mapping, the corresponding mixer path file is analog-output-lineout.conf, and the keyword description-key of its description is analog-output-lineout. As shown below:

The PA works by traversing the mixer path in this directory from top to bottom and checking if the content described by the mixer elements in it exists, and if so, it will be added to the PA-controlled mixer elements, maintaining their read order. All valid paths as an audio device will be represented as sinks or sources, often referred to as ports.

3. Example of sound card configuration file

The default.conf mentioned in the profile set, for most sound cards, this profile can meet the adaptation, but there are some sound cards that require special configuration, need to use the newly added profile file, assuming the new configuration file is named as special-snd-card.conf, of course, it is possible to add a new mixer path, so how to ensure that the sound card can be associated with the newly added profile and mixer path? The following steps can help to do the job:

1) Configure the /lib/udev/rules.d/90-pulseaudio.rules file

2) Add profile

Copy the special-snd-card.conf file to the profile-sets directory.

$ cp special-snd-card.conf /usr/share/pulseaudio/alsa-mixer/profile-sets

3) Add mixer path

Add the path configuration file corresponding to the special-snd-card.conf file in the paths directory.

$ vim /usr/share/pulseaudio/alsa-mixer/paths/special-snd-card.conf

4. Sound card configuration file calling logic

The above briefly introduces two directories and one file about the sound card configuration. Next, we need to connect these files with a schematic diagram to connect their relationship. There are three red texts in the figure below, corresponding to the two directories and one file here.

trigger 90-pulseaudio.rule: will assign a value to PULSE_PROFILE_SET, which is assumed to be the special-snd-card.conf described earlier.
load profile: Load special-snd-card.conf.
load mixer path: Load the relevant path in the special-snd-card.conf file.

Through the above schematic diagram, we can have a preliminary understanding of the PA sound card configuration file, which is helpful to analyze and deal with audio problems in our usual work. In the future, we will update the internal details of the profile and mixer path configuration files. In-depth analysis, especially the mapping relationship between the device-strings keyword of mapping in the profile and the sound card, as well as the meaning of each element of each mixer path, etc., so stay tuned!

welcome to use deepin!

--

--