PulseAudio
PulseAudio is the sound system used by most desktop Linux distributions. The goal of this guide is to teach you the basic knowledge you’ll need to be able to solve your own audio routing situations (e.g., routing an application’s sound and your microphone into Discord while still being able to hear the application).
If you already know the concepts, you can skip down to Routing Audio.
Important Concepts
-
There are two types of devices:
-
sink: a device that an application can send audio to (e.g., a set of speakers)
-
source: a device that an application can get audio from (e.g., a microphone)
These terms are straightforward if you remember that they are named from an application’s perspective.
-
-
There are two types of application streams:
-
sink-input: a stream going to a sink (e.g., the sound output by an application, going to speakers)
-
source-output: a stream coming from a source (e.g., the sound input to an application, coming from a microphone)
These terms are confusing because they seem to be named from PulseAudio’s perspective (a sink-input is the sound coming into a sink from an application). I find it helpful to mentally flip the order of the two words and think of them as “input (to a) sink” and “output (from a) source”.
-
-
And there’s one more concept that I couldn’t fit into a better category:
- monitor: a hidden source that automatically exists for each sink and allows accessing the audio that is being sent to that sink
pavucontrol
pavucontrol (PulseAudio Volume Control) is the best way to interact with PulseAudio because it doesn’t try to simplify or hide these concepts from you (like the volume widgets of many desktop environments do).
Device Naming
Each device has a name used internally by PulseAudio as well as a description which is meant to be human-readable.
Finding Device Names
Use the list-sinks
or list-sources
commands and search for the lines that contain name:
or device.description =
. Then find the name that matches the description.
$ pacmd list-sinks | grep -E 'name:|device\.description'
name: <alsa_output.pci-0000_00_1f.3.analog-stereo>
device.description = "Sound Core3D [Sound Blaster Recon3D / Z-Series] (SB1570 SB Audigy Fx) Analog Stereo"
name: <bluez_sink.38_18_4C_7D_5C_08.a2dp_sink>
device.description = "Headphones"
The name is the part between the <>
brackets (i.e., the brackets are not part
of the name).
Changing Device Descriptions
Use the update-sink-proplist
or update-source-proplist
commands to change
the device.description
property.
$ pacmd update-sink-proplist $speakers 'device.description="Laptop Speakers"'
Useful Modules
Null Sink
A null sink is a virtual sink that discards audio sent to it. That’s not very useful by itself, but the monitor that comes with it can be very useful.
Use load-module module-null-sink
to create a new null sink.
$ pacmd load-module module-null-sink \
sink_name=null \
sink_properties=\'device.description=\"Null Output\"\'
You can omit the sink_name
and sink_properties
arguments if you don’t care
about the name and description (you’ll get the defaults, “null” and “Null
Output”). But if this is part of a more complex setup, it’s worth it to set
descriptive names from the beginning (see Application to
Application for a practical example).
Use pavucontrol to route application audio to the null sink as desired.
Combined Sink
A combined sink is a virtual sink that forwards audio to multiple other sinks.
First, find the names of the sinks you want to combine,
then use load-module module-combine-sink
to create a new combined sink.
$ pacmd load-module module-combine-sink slaves=$speakers,$headphones
The combined sink will automatically have a readable description.
Loopback
A loopback forwards audio from a source to a sink.
Use load-module module-loopback
to create a new loopback.
$ pacmd load-module module-loopback
Then use pavucontrol to choose which source and sink the loopback should use.
Routing Audio
Application to Application
Use a null sink to receive the audio from the source application, and configure the other application to read from the monitor of the null sink.
Application to Application+Speakers
Follow the previous instructions, then add a combined sink that forwards to the null sink and the speakers.
Application to Application+Speakers and Microphone to Application
Follow the previous instructions, then add a loopback that forwards the microphone to the null sink.