Using Bluetooth audio devices (speaker, headphones, earbuds) with FreeBSD

olli@

Daemon
Developer

Reaction score: 1,263
Messages: 1,140

Here’s just a small recommendation if you want to connect Bluetooth audio devices to a FreeBSD machine, such as wireless speakers or headphones.

Unfortunately, FreeBSD’s support for Bluetooth audio devices is rather weak. Some devices work via the virtual_oss port, but many don’t work. It also requires a lot of manual work.

Therefore I’ve been looking for an alternative, and I found this little USB Bluetooth dongle (the link points to Amazon Germany – if you use Amazon somewhere else, please use the search function to locate this or something similar; also see my reply #3 below for alternative products that work the same).

The special thing about this dongle is that it is not an actual USB Bluetooth adapter. Instead, the operating system recognizes it as a standard USB sound card. When you plug it in, FreeBSD automatically attaches it with the snd_uaudio(4) driver and creates a pcm(4) device that appears in /dev/sndstat. Bluetooth drivers are not required.

Here’s the dmesg output from the attachment:
Code:
ugen0.9: <vendor 0x0a12 B10> at usbus0
uaudio0 on uhub1
uaudio0: <vendor 0x0a12 B10, class 0/0, rev 2.00/25.19, addr 12> on usbus0
uaudio0: Play[0]: 48000 Hz, 2 ch, 16-bit S-LE PCM format, 2x8ms buffer.
uaudio0: Record[0]: 48000 Hz, 1 ch, 16-bit S-LE PCM format, 2x8ms buffer.
uaudio0: No MIDI sequencer.
pcm5: <USB audio> on uaudio0
uaudio0: HID volume keys found.
Output from cat /dev/sndstat
Code:
pcm0: <NVIDIA (0x0081) (HDMI/DP 8ch)> (play)
pcm1: <NVIDIA (0x0081) (HDMI/DP 8ch)> (play)
pcm2: <Realtek ALC1220 (Analog 5.1+HP/2.0)> (play/rec) default
pcm3: <Realtek ALC1220 (Rear Digital)> (play)
pcm4: <Realtek ALC1220 (Front Analog Mic)> (rec)
pcm5: <USB audio> (play/rec)
As you can see, the new device got the number 5 (“pcm5”), so the command sysctl hw.snd.default_unit=5 can be used to use it by default. Now the audio output from my favorite media player goes to my “Melomania 1” true-wireless headphones. Even the little volume buttons on the earbuds work – when I press them, the playback volume is adjusted, and I can see the value change in the output of the mixer(8) command.

According to the above output, the device also supports a “record” channel for the built-in microphone of head-sets and some speakers, so you should be able to use this for phone calls, video conferences and similar. I haven’t tried this, though, because I only need the playback function.
 
Last edited:
OP
olli@

olli@

Daemon
Developer

Reaction score: 1,263
Messages: 1,140

The following steps will set the default sound device automatically when you plug in the USB audio dongle.
You can make this work with other USB audio devices, just replace the vendor ID and product ID in the devd file below. To find out the IDs for your device, type usbconfig -d ugen0.5 dump_device_desc (you can see the USB device in dmesg; in this case it’s ugen0.5), and look for the lines labeled “idVendor” and “idProduct”.

Note: You have to perform the following steps with root privileges.

Step 1:
Create a file /usr/local/etc/devd/bluetooth-audio-b10.conf (or whatever name you see fit, but it must end with .conf):
Code:
#   When we attach the "B10" Bluetooth audio dongle,
#   automatically set it to be the default audio device.

attach 100 {
        match "vendor"  "0x0a12";
        match "product" "0x1004";
        action "sleep 1 ; /usr/local/sbin/update-snd-unit";
};
To make it work with other USB audio devices, replace the “vendor” and “product” codes as explained above.

Step 2:
Create a script /usr/local/sbin/update-snd-unit:
Code:
#!/bin/sh -
#   When a new pcm* device has been attached.
#   set it to be the default sound device.

set -Cefu
ME="${0##*/}"
FAC="daemon"    # Syslog facility, see syslog(3).
export PATH=/sbin:/bin:/usr/sbin:/usr/bin

PCM=$(
        dmesg \
        | awk '
                /^pcm[0-9]+: .* on / {
                        sub (/^pcm/, "")
                        sub (/:.*/, "")
                        pcm = $0
                }
                END {
                        print pcm
                }
        '
)

if [ -z "$PCM" ]; then
        logger -p $FAC.error -t "$ME" "Cannot determine new pcm device."
        exit 1
fi

sysctl hw.snd.default_unit=$PCM 2>&1 \
| logger -p $FAC.notice -t "$ME"
Step 3:
Make the script executable: chmod 755 /usr/local/sbin/update-snd-unit

Step 4:
Restart devd(8): service devd restart

Done!
 
OP
olli@

olli@

Daemon
Developer

Reaction score: 1,263
Messages: 1,140

PS: In case you have trouble finding that USB dongle mentioned above – Most USB Bluetooth dongles intended to be used for the Playstation (PS4, PS5) or for the Nintendo Switch work exactly the same, i.e. they are recognized as USB sound cards by the operating system, so no Bluetooth drivers are needed. For example, see this product on Amazon USA.

(Note that these are standard links to Amazon, not afiliate links. I do not get any revenues for them.)
 

free-and-bsd

Daemon

Reaction score: 170
Messages: 1,016

VERY interesting, thank you. Found this post because my Bluetooth 5.0 USB dongle evidently doesn't work with FreeBSD.

The one you're talking about seems to be a high quality device... and costs accordingly. OK! Found it at aliexpress.com as well.
Just hoave some questions here.
From the product descriptions it is not quite clear to me how to pair my Bluetooth headset with this device...
What I mean is, if it "just pairs" (as in 'just works'), then anyone around can also JUST pair and listen to what I am listening, right? As it mentions there, among the advantages, "double" pairing -- that TWO person can connect to it and listen. And no mentioning of how this can be controlled. Rather, the device seems to be self-sufficient (no output volume controls except what your paired phones/speakers offer).
Suich independence is, for one thing, good, because no drivers are needed. But it is also bad in case pairing cannot be controlled.

So, olli@, I'd be very thankful if you could comment on this.
.
 

grahamperrin

Son of Beastie

Reaction score: 1,045
Messages: 3,512

𡀦… this dongle … the operating system recognizes it as a standard USB sound card. …

Smart. Thanks.

Using Bluetooth audio devices (speaker, headphones, earbuds) with FreeBSD

Also:

 

covacat

Daemon

Reaction score: 533
Messages: 1,081

VERY interesting, thank you. Found this post because my Bluetooth 5.0 USB dongle evidently doesn't work with FreeBSD.

The one you're talking about seems to be a high quality device... and costs accordingly. OK! Found it at aliexpress.com as well.
Just hoave some questions here.
From the product descriptions it is not quite clear to me how to pair my Bluetooth headset with this device...
What I mean is, if it "just pairs" (as in 'just works'), then anyone around can also JUST pair and listen to what I am listening, right? As it mentions there, among the advantages, "double" pairing -- that TWO person can connect to it and listen. And no mentioning of how this can be controlled. Rather, the device seems to be self-sufficient (no output volume controls except what your paired phones/speakers offer).
Suich independence is, for one thing, good, because no drivers are needed. But it is also bad in case pairing cannot be controlled.

So, olli@, I'd be very thankful if you could comment on this.
.
usually multiple pairing != multiple connection
i can have both may mac and phone paired with my receiver but only one can connect and play
once the device is paired to your headphones / bt speaker it wont attempt to pair to anything else unless you probably push the button
i don't think is much of a privacy problem
 

free-and-bsd

Daemon

Reaction score: 170
Messages: 1,016

usually multiple pairing != multiple connection
Usually not. But I invite you to read what the description of this device says: "1Mii B10 Bluetooth audio transmitter can connect 2 bluetooth headphones at the same time...".
Not a very standard feature, I should say. Impressive! As you see, it's not about connecting 2 computer devices (that would never be possible). But it does indeed boast the ability to have 2 sound receiver devices (headphones, speakers) connected simultaneously to this one little dongle (which is, of course, connected to only ONE computer at a time).

So I wonder, how is this pairing CONTROLLED? From the looks of this device there is nothing there, it's just a little dongle, that's all. Neither can computer control the pairing. Because, as the OP brings out, the system SEES IT AS AN AUDIO DEVICE. Which suggests, the thing itself handles all the pairing, right?
Now suppose I DON"T want to connect 2 headphones, I'm using just 1 pair of them. And I'm doing it in a public place. So does that mean anyone around (say, in a bus) will be able to connect HIS headphones to this little wonder-device when I'm only using 1 pair of headphones?

This I hoped to hear from the OP who has it.

 

covacat

Daemon

Reaction score: 533
Messages: 1,081

And I'm doing it in a public place. So does that mean anyone around (say, in a bus) will be able to connect HIS headphones to this little wonder-device when I'm only using 1 pair of headphones?
only if you pair it while on the bus an the other person does it in the same time ?
i assume you have to set the dongle to pair mode before it searches for devices to connect to
 

free-and-bsd

Daemon

Reaction score: 170
Messages: 1,016

only if you pair it while on the bus an the other person does it in the same time ?
i assume you have to set the dongle to pair mode before it searches for devices to connect to
Yes, I could assume it MUST be handled somehow... but I'm not satisfied with assumptions here. If I decide to buy it I want to know for sure.
 

free-and-bsd

Daemon

Reaction score: 170
Messages: 1,016

...assume you have to set the dongle to pair mode before it searches for devices to connect to
OR maybe it has a small switch on it to switch this "double-pairing" mode ON and OFF just like that. I think there IS some kind of small switch on the picture of that dongle... But good to know in advance -- not so much because it costs A LOT (36$ -- not VERY much, but there are other things on the list as well :) ) but because I don't want to add another device I DON'T ACTUALLY USE to my already big collection ;) ;) ;)
 
Top