I was previously using a Sony HWS-BTA2W bluetooth adapter from 2007 to get sound wirelessly from my computer or phone to a set of non-bluetooth speakers. It had a problem that only happened with my linux computer. I was annoyed with this device because as the workload would increase/decrease on my computer, the audio would speed up and slow down. You could hear the pitch rise and fall if you were listening to music. This is probably by design – as part of the base level Bluetooth SBC codec that everything supports. It makes sense that if you’re talking on the phone you’d want to hear everything someone said, even if it had to be sped up or slowed down for continuity.

The pitch bend happened on all of my linux laptops: 2008 Dell Studio 17 and my 2014 ThinkPad T440s, and my 2019 Developer Edition XPS 13. I wasn’t sure about the problem being in the linux bluetooth stack or the Sony device itself. I knew there was a better solution available – and it happened to be a combination of hardware and software.

After reading all about Bluetooth codecs and wanting another way to tap into my audio interface, I decided to try another, more modern, bluetooth interface. I went with a 1Mii B06S Bluetooth 5.2 Receiver. It supports several aptX profiles, which provide higher fidelity than the base BT codecs.

Interestingly, aptX originated as a PhD thesis, then later became incarnate in a DSP chip. Then the tech changed hands though several companies (including Solid State Logic which makes my audio interface). Before finally becoming part of Qualcomm. AptX was first used in the Bluetooth stack with some Sennheiser headphones from 2009. My 2007 Sony hardware was definitely not using this tech.

AptX on Ubuntu 22.04

To make sure my computer supported these extra codecs, I had to install some extras. Partly because aptX has some patent issues (although it’s been reverse engineered), and partly because I upgraded my system to use pipewire. The best source I found was this gist:

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 WirePlumber as the session manager:

$ sudo apt install 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

Install the ALSA plug-in:

$ sudo apt install pipewire-audio-client-libraries

And copy the config file from PipeWire docs (provided by the plug-in) into the ALSA configuration directory:

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

Check if you have other (like Pulse) configs in the /etc/alsa/conf.d/ installed by something else. You might want to remove them.

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

Install the codecs and remove Bluetooth from PulseAudio, so it would be handled directly by PipeWire:

$ sudo apt install libldacbt-{abr,enc}2 libspa-0.2-bluetooth pulseaudio-module-bluetooth-

The supported codecs are SBC and LDAC.

Unfortunately, aptX and AAC are not supported because of patents and other technical reasons. aptX is available starting from 22.10 via libfreeaptx0 installed by default there (22.10 uses PipeWire by default as well). If you really need these codecs in 22.04 you may use this PPA from @aglasgall which is based on universe, but rebuilds pipewire with additional packages for aptX and AAC from multiverse. Read the discussion here.

Done

Reboot and check if it works by running:

$ LANG=C pactl info | grep '^Server Name'
view raw pipewire.md hosted with ❤ by GitHub

The important part in there is actually the link to the pipewire-extra-bt-codecs PPA for Ubuntu 22.04. I installed/removed the packages as expected and when I connected to the 1Mii B06S I can choose from all of the supported codecs in my sound settings:

I’m going to keep it on aptX HD for now and see how it sounds, but so far I’ve experienced zero pitch changes while listening to music.

Coming soon..

Next I’ll go through how I have everything hooked up in my home audio studio.

One thought on “Ubuntu 22.04 & aptX Bluetooth codec

  1. Pingback: Music Studio 1.0 - Justin Foell

Leave a Reply