Pulseaudio

Tasks

set the default sink/source

pactl list short sinks
pactl set-default-sink <sink_name>
pactl list short sources
pactl set-default-source <source_name>

Restart the pulseaudio daemon

pulseaudio -k

Configuration files

default.pa - PulseAudio Sound Server Startup Script
~/.config/pulse/default.pa
/etc/pulse/default.pa

pulse-daemon.conf - PulseAudio daemon configuration file
~/.config/pulse/daemon.conf
/etc/pulse/daemon.conf

pulse-client.conf - PulseAudio client configuration file
~/.config/pulse/client.conf
/etc/pulse/client.conf

If Pulseaudio works system-wide and not per-user...
/etc/pulse/system.pa

man pulse-cli-syntax
pulse-cli-syntax - PulseAudio Command Line Interface Syntax

Concepts

Cards

Physical devices related to sound.

In the following example, I have three cards.

  • 0 is sound getting through HDMI, generally to an audio equipped display (output)
  • 1 is a webcam that can record sound (input)
  • 2 the sound card on the motherboard (can input and output)
$ pactl list cards short
0	alsa_card.pci-0000_0b_00.1	module-alsa-card.c
1	alsa_card.usb-046d_HD_Pro_Webcam_C920_F2CFBFEF-02	module-alsa-card.c
2	alsa_card.pci-0000_0d_00.4	module-alsa-card.c

Each card has one or more profiles.

definition/creation ?? ()

http://www.freedesktop.org/wiki/Software/PulseAudio/Backends/ALSA/Profiles/

pacmd set-card-profile index|name profile-name
Change the profile of a card.

pacmd set-card-profile alsa_card.pci-0000_00_1b.0 output:analog-surround-51

Clients

$ pactl list clients short
0	module-systemd-login.c	(null)
2	protocol-native.c	wrapper-2.0
5	module-x11-xsmp.c	(null)
6	protocol-native.c	firefox
13	protocol-native.c	wine-preloader
36	protocol-native.c	sd_espeak-ng
37	protocol-native.c	sd_dummy
45	protocol-native.c	python3.8
51	protocol-native.c	pavucontrol
60	protocol-native.c	pactl

Sinks

Where an audio stream can be routed, “what you write/input into”.

Every sink has a monitor that can be used as a source (for loopback and routing).

In the following example, there is only a single sink: all audio goes to the main sound card.

$ pactl list sinks short
12	alsa_output.pci-0000_0d_00.4.analog-surround-51	module-alsa-card.c	s16le 6ch 44100Hz	RUNNING

Sink-Input

Audio stream connected to a sink.

In the following example, there’s only one sink-input. It’s an application (Quod Libet) inputting audio into the only one sink (“alsa_output.pci-0000_0d_00.4.analog-surround-51”).

$ pactl list sink-inputs short
155	12	66	protocol-native.c	s16le 2ch 44100Hz

Sources

Audio streams entering Pulseaudio, “what you read/record from”.

In the following example, there are two sources that an application could record from:

  • the webcam microphone
  • the monitor of the main sound card (acting as a loopback)
$ pactl list sources short
1	alsa_input.usb-046d_HD_Pro_Webcam_C920_F2CFBFEF-02.analog-stereo module-alsa-card.c	s16le 2ch 32000Hz	RUNNING
13	alsa_output.pci-0000_0d_00.4.analog-surround-51.monitor module-alsa-card.c	s16le 6ch 44100Hz	RUNNING

Why isn’t an application producing sound a source ?

Because the audio is not coming from a card. It is possible, though, to record the output of an audio application by creating a sink for this application to input into (we connect them through a sink-input). Then using the monitor of this sink, we have a source which can be recorded from.

Source-output

Stream going out of a Pulseaudio source to an application reading it.

ex: application recording/reading something, Pavucontrol connected to the source to read/set the recording volume (so, information is coming from this source towards Pavucontrol).

Pavucontrol has one general source-ouput for every source + 1 source-output per sink-input…

$ pactl list source-outputs short
16	1	51	protocol-native.c	float32le 1ch 25Hz
17	2	51	protocol-native.c	float32le 1ch 25Hz
18	2	51	protocol-native.c	float32le 1ch 25Hz
19	2	51	protocol-native.c	float32le 1ch 25Hz
20	2	51	protocol-native.c	float32le 1ch 25Hz

Modules

https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/Modules/

module-native-protocol-{unix,tcp}

auth-ip-acl (only for -tcp)

A semicolon separated list of IP address range to which anonymous access is allowed. Example: auth-ip-acl=10.11.12.13;192.168.50.0/24;127.0.0.0/8

To allow all local users to use the sound server.

pactl load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1

Commands

pacmd – Reconfigure a PulseAudio sound server during runtime

pacmd --help

pacmd suspend 1 && pacmd suspend 0

to get the “Default sample spec”
pacmd stat

pacmd list-modules
pacmd list-sinks
pacmd list-sources
pacmd list-clients
pacmd list-cards
pacmd list-samples

pacmd list-sink-inputs
pacmd list-source-outputs

pacmd set-card-profile alsa_card.pci-0000_00_1b.0 output:analog-surround-51

pactl – Control a running PulseAudio sound server

pactl list sources
-> Input devices (in pavucontrol)

leopardb@neptune:~$ pactl list short sources
2	alsa_output.pci-0000_00_1b.0.analog-surround-51.monitor	module-alsa-card.c	s16le 6ch 44100Hz	RUNNING
4	alsa_input.pci-0000_00_1b.0.analog-stereo	module-alsa-card.c	s16le 2ch 44100Hz	RUNNING

pactl list sinks
-> Output devices (in pavucontrol)

leopardb@neptune:~$ pactl list short sinks  
2	alsa_output.pci-0000_00_1b.0.analog-surround-51	module-alsa-card.c	s16le 6ch 44100Hz	IDLE

pactl list sink-inputs
-> applications playing sound

active inputs to sinks a.k.a. playback streams
lister les paires: “ce qui est connecté à/rentre dans un sink” (j’ai un sink, qu’est-ce qui rentre dedans ?)
ex: source “Alsa sc2” connecté au sink “speakers”


The "Buffer Latency" field shows the amount of audio in the stream buffer (not yet written to the sink). The "Sink Latency" field shows the latency of the sink. The sum of these two values is the full server-side latency for the stream. In addition to the server-side latency, there's the transport latency between the client and the server (very low for local streams).

corked= paused


pactl list source-outputs
source = audio-generating *thing* (application, line-in, microphone etc...)
outputs of sources a.k.a. recording streams

lister les paires: “ouput connecté à une source” “What is reading a Source ?”
ex: Pavucontrol connecté aux sources “Input Devices” (micro etc...)

pactl list short clients
leopardb@neptune:~$ pactl list short clients
0	module-systemd-login.c	(null)
33	protocol-native.c	chrome
353	protocol-native.c	rhythmbox
356	protocol-native.c	pactl

pactl list samples

pactl list short cards

leopardb@neptune:~$ pactl list short cards
0	alsa_card.pci-0000_00_1b.0	module-alsa-card.c

paman, paprefs, pavumeter

not yet documented…

Script

#!/bin/bash

# Pulseaudio stuff for my twitch stream

# intermediary sink for music/other stuff
pactl load-module module-null-sink sink_name="temp_sink" sink_properties=device.description="stream_stuff_i_want_to_hear"

# what is sent directly to this sink will only be heard on stream
pactl load-module module-null-sink sink_name="twitch_stream" sink_properties=device.description="Twitch_Stream"


# sends all that goes to the intermediary sink also to my headphones
pactl load-module module-loopback source=temp_sink.monitor sink=alsa_output.pci-0000_0d_00.4.analog-stereo rate=44100

# sends all that goes to the intermediary sink also to the stream sink
pactl load-module module-loopback source=temp_sink.monitor sink=twitch_stream rate=44100

# sends microphone source directly to the twitch sink (i don’t want to hear it)
pactl load-module module-loopback source=alsa_input.pci-0000_00_1b.0.analog-stereo sink=twitch_stream rate=44100

We want people in Skype to hear our music directly (not through our speakers + some larsen/reverb)

In order to do this we start by creating two null-sink to send our audio to:

pactl load-module module-null-sink sink_name="skype_sink" sink_properties=device.description="skype_sink"
pactl load-module module-null-sink sink_name="music" sink_properties=device.description="music"

Skype will “record” the source “skype_sink.monitor” (automatically created), and we will output our music to the “music” sink. All this can be accomplished using pavucontrol.

We do not hear our music anymore ! we need to send the music to our audio card using the module “module-loopback”:

pactl load-module module-loopback source="music.monitor" sink=alsa_output.pci-0000_0d_00.4.analog-stereo

Then we send it to Skype as well:

pactl load-module module-loopback source="music.monitor" sink=skype_sink

Now, for our contacts to hear us, we need to send our microphone source to the “skype_sink” sink:

pactl load-module module-loopback source=alsa_input.usb-046d_HD_Pro_Webcam_C920_F2CFBFEF-02.analog-stereo sink=skype_sink

In one go:


#!/bin/bash

# create two sinks 
pactl load-module module-null-sink sink_name="skype_sink" sink_properties=device.description="skype_sink"
pactl load-module module-null-sink sink_name="music" sink_properties=device.description="music"

# send my microphone to skype
pactl load-module module-loopback source=alsa_input.usb-Razer_Inc._Razer_Seiren_Elite_UC1829L01000232-01.analog-stereo sink=skype_sink

# sends music to my speakers and to skype
pactl load-module module-loopback source="music.monitor" sink=alsa_output.pci-0000_0d_00.4.analog-stereo
pactl load-module module-loopback source="music.monitor" sink=skype_sink