PulseaudioProfiles

Differences between revisions 1 and 2
Revision 1 as of 2013-04-15 14:47:35
Size: 2385
Editor: hd9483857
Comment: Not yet finished
Revision 2 as of 2013-04-15 15:03:10
Size: 4177
Editor: hd9483857
Comment:
Deletions are marked like this. Additions are marked like this.
Line 20: Line 20:
<path name="speaker">
</path>
<path name="headphone">
</path>
<path name="main-mic-top">
</path>
<path name="main-mic-left">
</path>
<path name="headset-mic">
</path>
<path name="speaker"></path>
<path name="headphone"></path>
<path name="main-mic-top"></path>
<path name="main-mic-left"></path>
<path name="headset-mic"></path>
Line 41: Line 36:
Typically a number of switches need to be set up correctly for audio to be output. If your mixer file looks like this:
Line 42: Line 38:
{{{
  <ctl name="Speaker Playback Switch" value="0" />
  <ctl name="Int Spk Switch" value="0" />
  <path name="speaker">
    <ctl name="Speaker Playback Switch" value="1" />
    <ctl name="Int Spk Switch" value="1" />
  </path>
  <path name="headphone">
  </path>
}}}

Then you can figure out that both of "Speaker Playback Switch" and "Int Spk Switch" need to be turned on for audio to be output on the Speaker.

Here's how the corresponding section would look like in PulseAudio's speaker path file:
{{{
[Element Int Spk]
switch = mute

[Element Speaker]
switch = mute
}}}

And here's how it would look in PulseAudio's headphone path file:

{{{
[Element Int Spk]
switch = off

[Element Speaker]
switch = off
}}}

In short; "Speaker Playback Switch" is transformed into "Element Speaker", "switch = off" or "switch = mute". If switch is set to "off", it will always be off when that path is active. If it is set to "mute", it will toggle depending on whether audio is currently muted or not.

For volumes, my mixer xml file did not give me any hint. But "Master", "Speaker" are usually safe bets. Try and see if you get the desired results. A "Speaker" playback volume would typically be coded as:

Speaker path:
{{{
[Element Speaker]
volume = merge
override-map.1 = all
override-map.2 = all-left,all-right
}}}

(Just copy-paste the override-map rows as the above.)

Headphone path:
{{{
[Element Speaker]
volume = off
}}}

If you have more than one ALSA volume control set to "merge", PulseAudio will merge them in order to create a main volume control with a range that corresponds to all of the ALSA volume controls combined.

Introduction to PulseAudio profiles and ports

For controlling audio volume and mute, PulseAudio provides an abstraction layer over ALSA. ALSA often exposes a bewildering list of mixer controls, and the end user probably just wants to control the main volume, not several volumes.

However, which volume to control, depend on the currently active output (or input). Some ALSA volume control might be necessary for controlling Headphones volume, and another for Speaker volume. There might be additional controls needed to be set for audio to be output at all.

To describe what mixer controls PulseAudio needs to set for a particular output, PulseAudio uses path files. There is also a profile-set file that describes which path files to look for, and an udev rule to determine which profile-set file will be used for a particular hardware.

The upstream documentation for how to write profile and path files is here. There is also documentation inside these files.

Android also has mixer files

Android devices, at least some of them, have mixer files in an xml format. These can provide very good hints of how to write your paths. Here is how the mixer xml file looks for Nexus7, which will be used as an example in this guide.

Path files

In my example, I have the following paths defined in the Android mixer file:

<path name="speaker"></path>
<path name="headphone"></path>
<path name="main-mic-top"></path>
<path name="main-mic-left"></path>
<path name="headset-mic"></path>

This would typically correspond to similar path files in PulseAudio. I chose to create paths for

  • Speaker
  • Headphone
  • Mic (built-in)

PulseAudio does not support switching port depending on current rotation, and the headset-mic path present is probably bogus, because Nexus7 does not support headset mics (at least so I've been told).

Volumes and mutes

Typically a number of switches need to be set up correctly for audio to be output. If your mixer file looks like this:

  <ctl name="Speaker Playback Switch" value="0" />
  <ctl name="Int Spk Switch" value="0" />
  <path name="speaker">
    <ctl name="Speaker Playback Switch" value="1" />
    <ctl name="Int Spk Switch" value="1" />
  </path>
  <path name="headphone">
  </path>

Then you can figure out that both of "Speaker Playback Switch" and "Int Spk Switch" need to be turned on for audio to be output on the Speaker.

Here's how the corresponding section would look like in PulseAudio's speaker path file:

[Element Int Spk]
switch = mute

[Element Speaker]
switch = mute

And here's how it would look in PulseAudio's headphone path file:

[Element Int Spk]
switch = off

[Element Speaker]
switch = off

In short; "Speaker Playback Switch" is transformed into "Element Speaker", "switch = off" or "switch = mute". If switch is set to "off", it will always be off when that path is active. If it is set to "mute", it will toggle depending on whether audio is currently muted or not.

For volumes, my mixer xml file did not give me any hint. But "Master", "Speaker" are usually safe bets. Try and see if you get the desired results. A "Speaker" playback volume would typically be coded as:

Speaker path:

[Element Speaker]
volume = merge
override-map.1 = all
override-map.2 = all-left,all-right

(Just copy-paste the override-map rows as the above.)

Headphone path:

[Element Speaker]
volume = off

If you have more than one ALSA volume control set to "merge", PulseAudio will merge them in order to create a main volume control with a range that corresponds to all of the ALSA volume controls combined.

Switching port on device plugin

TBW

What about UCM?

UCM is another abstraction layer for mixer controls. Its implementation in PulseAudio is still immature (as of Ubuntu 13.04), as it does not support, e g, mapping an ALSA mixer control to the main PulseAudio volume.

Touch/Core/PulseaudioProfiles (last edited 2013-04-16 09:26:57 by hd9483857)