So, in the name productivity and as a reward for cleaning my office room, I decided to reward myself with high-quality headphones. My office room is next to a busy cycling street, and during rush hour it can be challenging to focus. Furthermore, my girlfriend is tutororing math at home causing the doorbell to ring many times during the day.

My previous headphones where all in the €50 price range and did not have noise cancelation, a feature that should weaken external sounds. After some research and looking at various price categories I decided to buy one of the most expensive ones. The €327 Sony WH-1000XM2 which, reviews said, had the best noise cancellation, excellent sound quality and wireless audio with Bluetooth.

With the Sony Headphones app, the headphones worked out of the box on my android phone. To connect them to the desktop I bought a popular Bluetooth adapter. The adapter worked fine on Windows, but it gave all sort of issues on my Ubuntu 16.04 installation (I run a dual boot). This article should help in understanding the concept and tools necessary to get your Bluetooth headphones to work on Linux.

Drivers and firmware

The first step is to check if there are issues with the Bluetooth adapter drivers. We can do this by using dmesg which gives output from the low level hardware drivers. When you suspect the hardware is broken, you can check the output of lsusb to see if the USB Bluetooth adapter is detected.

1
2
3
dmesg | grep -i bluetooth # Shows all Bluetooth driver info
dmesg | grep -i bluetooth | grep -i firmware # Shows Bluetooth firmware issues
lsusb # Displays hardware connected to the USB ports

In my case, dmesg gave a firmware error trying to load a file that did not exist. To fix this, I had to manually copy the related firmware file to /lib/firmware/brcm which I got from the winterheart/broadcom-bt-firmware GIT repository.

Now, you should be able to discover Bluetooth devices, pair and connect to them. The best way to see if everything works, is to use the bluetoothctl tool.

1
2
3
4
5
6
7
8
9
10
11
12
13
bluetoothctl # Start the tool it should show something like the output below:
[NEW] Controller DC:A9:71:10:24:89 niels-300V3A-300V4A-300V5A [default]
Agent registered

show # Information about the adapter
help # Info about all Bluetooth commands
scan on # Scans for Bluetooth devices
devices # Shows the Bluetooth devices
Device EC:88:92:6F:30:96 Headphones

pair EC:88:92:6F:30:96 # Start the pairing procedure
Pairing successful
[CHG] Device EC:88:92:6F:30:96 Trusted: yes

Sound and Audio profiles

So, with the hardware driver ready there is a high probability that you encounter issues with your sound system. When you pair and connect the Bluetooth headset, and you can not select it in the sound settings as an input or output device, then the first step is to install Blueman.

1
2
sudo apt-get update
sudo apt-get install blueman

This tool allows you to modify the audio profiles of the Bluetooth devices with an interface. You can play around with re-pairing your devices and with changing the audio profiles to see if you can get it working in the sound settings.

In my case, the system did not recognize the headphones as an audio device, and I could not change the audio profile with Blueman. To fix this, we have to enable the bluetooth-discover module in Pulseaudio, the sound system for most Linux distributions. First, we can check if the module is loaded in Pulseaudio with the pactl.

1
pactl list | grep -i bluetooth # Shows if Bluetooth modules are loaded

If the output is empty, the module is not active. Let’s make sure the package is available with:

1
2
3
sudo apt-get install pulseaudio-module-bluetooth  # Installs the package
sudo pactl load-module module-bluetooth-discover # Loads the module manually
pactl list | grep -i bluetooth # Shows if Bluetooth modules are loaded

Now, the modules are active. However, the chances are that you have to load the module manually everytime you want to use your Bluetooth devices. You can test this by rebooting your machine. I believe the issue is that Pulseaudio gets started before Bluetooth. Sometimes, restarting Pulseaudio by hand can fix the issue.

1
2
pulseaudio --k
pulseaudio --start

What worked for me without having to restart Pulseaudio was changing some configuration in /etc/pulse/default.pa:

1
sudo nano /etc/pulse/default.pa # Open the configuration in your favorite editor

Find the following section:

1
2
3
4
5
6
7
8
### Automatically load driver modules for Bluetooth hardware
.ifexists module-bluetooth-policy.so
load-module module-bluetooth-policy
.endif

.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
.endif

And comment out the ifexist statements:

1
2
3
4
5
6
7
8
### Automatically load driver modules for Bluetooth hardware
#.ifexists module-bluetooth-policy.so
load-module module-bluetooth-policy
#.endif

#.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
#.endif

Wrap things up

Now, with all the hardware and software ready it is best to remove all previously paired devices and pair them with Blueman. Now, the system should detect that it is a headset and you can set the correct audio profiles which should be visible in the sound system.

All in all, the Bluetooth adapter manufacturers have some work to do to make there drivers better accessible on Linux. However, the user experience from the Linux side can get an upgrade as well. Even as a highly technical person I had many issues to understand the output given to me.


Leave a Reply

Your email address will not be published.