Deth

Fitness and everything else

Bluetooth Headphones

For a while now, I have wanted to get my Bluetooth headphones working with FreeBSD but have run into dead ends before. Recently, I damaged the cord, so only one side works. I almost bought new headphones but thought to make sure that it wasn’t the cord. If both sides worked with Bluetooth, then it’s just the cord. That got me thinking about how to get them working with FreeBSD and Bluetooth.

I found a good starting point on the FreeBSD forums, which got it working, but not correctly. Here’s a link in that thread.

I did make some slight modifications to the script. Mainly to fit my system’s setup. Here that is.

#!/bin/sh

if [ "$(cat /dev/sndstat | grep 'Virtual OSS')" = "dsp: <Virtual OSS> (play/rec)" ]; then
 killall pacat ; mixer pcm 100 ; sudo /usr/bin/killall virtual_oss ; sudo /sbin/sysctl hw.snd.basename_clone=1 ; notify-send --app-name=Bluetooth --icon=bluetooth -t 5000 'Bluetooth sound device disconnected'
else
 notify-send --app-name=Bluetooth --icon=bluetooth -t 5000 'Connecting Bluetooth sound device...'
 sudo virtual_oss -T /dev/sndstat -C 2 -c 2 -r 44100 -b 16 -s 1ms -R /dev/null -P /dev/bluetooth/Headphones -d dsp -t vdsp.ctl & sleep 5 && mixer pcm 100 ; pacat --record -d oss_output.dsp1.monitor > /dev/dsp &
fi

The main problem that I was having was that the sound was in slow motion and would lag behind. lowering the -s helped some but it was still behind.

what eventually seemed to help was modifying my sysctl.conf file and adding these lines. Now it’s working great.

dev.pcm.0.play.vchanrate=44100
dev.pcm.1.play.vchanrate=44100
dev.pcm.2.play.vchanrate=44100
dev.pcm.3.play.vchanrate=44100

It was defaulting to dev.pcm.1.play.vchanrate: 48000 and that seemed to be where the problem was coming from.