Skip to content

Instantly share code, notes, and snippets.

@shakthizen
Forked from the-spyke/pipewire.md
Last active July 9, 2024 14:53
Show Gist options
  • Save shakthizen/c943a07d3ef99f8f5b4004d77b358d2d to your computer and use it in GitHub Desktop.
Save shakthizen/c943a07d3ef99f8f5b4004d77b358d2d to your computer and use it in GitHub Desktop.
Enable PipeWire on Ubuntu 22.04

Enable PipeWire on Ubuntu 22.04

This guide is only for original Ubuntu out-of-the-box packages. If you have added a custom PPA like pipewire-debian, you might get into conflicts.

Ubuntu 22.04 has PipeWire partially installed and enabled as it's used by browsers (WebRTC) for recoding the screeen under Wayland. We can enable remaining parts and use PipeWire for audio and Bluetooth instead of PulseAudio.

Starting from WirePlumber version 0.4.8 automatic Bluetooth profile switching (e.g. switching from A2DP to HSP/HFP when an application needs microphone access) is supported. Jammy (22.04) repos provide exactly version 0.4.8. So, we're good.

Based on Debian Wiki, but simplified for Ubuntu 22.04.

Install

Install Bluetooth codecs AAC/LDAC/AptX:

$ sudo apt install \
  libfdk-aac2 \
  libldacbt-{abr,enc}2 \
  libopenaptx0

Install remaining PipeWire packages and WirePlumber as the session manager:

$ sudo apt install \
  libspa-0.2-bluetooth \
  pipewire-audio-client-libraries \
  pipewire-media-session- \
  wireplumber

Notice '-' at the end of 'pipewire-media-session'. This is to remove it in the same command, because 'wireplumber' will be used instead.

Start WirePlumber for your user:

$ systemctl --user --now enable wireplumber.service

Configure

ALSA

Single step. Copy the config file from the PipeWire examples into your ALSA configuration directory:

$ sudo cp /usr/share/doc/pipewire/examples/alsa.conf.d/99-pipewire-default.conf /etc/alsa/conf.d/

PulseAudio

Everything was done automatically by pipewire-pulse package, which should have been installed by wireplumber package as recommended. If not, install it yourself.

Bluetooth

Just remove this package and Bluetooth will be handled by PipeWire:

$ sudo apt remove pulseaudio-module-bluetooth

Done

Reboot and check if it works by running:

$ LANG=C pactl info | grep '^Server Name'

Reduce Latency

Find necessary info about the bluetooth device (while it is connected!)

    pactl list | grep -Pzo '.*bluez_card(.*\n)*'

The output should be something like

    Name: bluez_card.28_11_A5_84_B6_F9
    Driver: module-bluez5-device.c
    ...
    Ports:
    speaker-output: Speaker (priority: 0, latency offset: 0 usec, available)
        Part of profile(s): a2dp_sink, headset_head_unit
    speaker-input: Bluetooth Input (priority: 0, latency offset: 0 usec, not available)
        Part of profile(s): headset_head_unit

We see that the buffers have currently 0 latency. In the next step, you will need the NAME and PORT of your output. In this example, these are bluez_card.28_11_A5_84_B6_F9 and speaker-output, respectively.

Set the buffer size (latency) of your card to a suitable value with this command pattern:

    pactl set-port-latency-offset <NAME> <PORT> <BUFFER_SIZE_MICROSECONDS>

The latency unit of the following command is microseconds, so I'm using a 50 millisecond buffer for my command here:

    pactl set-port-latency-offset bluez_card.28_11_A5_84_B6_F9 speaker-output 50000

Restart your bluetooth service to apply your change

sudo service bluetooth restart As there is usually no documentation about this, you may have to experiment with higher or lower buffer values. Many people people posted their working latencies in the comments to this answer. Check them out for guidance on the latency value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment