Bluetooth audio, bmixd and aloopd

versatile 64-bit multi-user Linux distribution

Moderators: kirk, jamesbond, p310don, JakeSFR, step, Forum moderators

Post Reply
jamesbond
Posts: 717
Joined: Tue Aug 11, 2020 3:02 pm
Location: The Pale Blue Dot
Has thanked: 124 times
Been thanked: 402 times

Bluetooth audio, bmixd and aloopd

Post by jamesbond »

stemsee wrote: Thu Nov 04, 2021 1:21 pm

I also have a question regarding bmixd and default soundcard script.

There are two ways to connect to bluetooth audio in Fatdog up to 812rc. (The next release will add a 3rd way).
All of these are activated using fatdog-default-soundcard.sh

Method 1) Connect to bluetooth directly.
Method 2) Connect to bluetooth using bmixd (bluetooth-dmix-daemon).
Method 3) Connect to bluetooth using aloopd. (Not yet available, to be released in next release of Fatdog, probably in 812)

Method 1: Direct bluetooth connection
This was the oldest method. It still works, but it is less convenient.

Steps:
1. Pair the bluetooth speaker, using bluetoothctl
a) Run bluetoothctl
b) Inside bluetoothctl's prompt, type "scan"
c) when you see the device you want, type "pair AA:BB:CC:DD:EE" where AA:BB:CC:DD:EE is the bluetooth MAC address you see.
2. Run fatdog-default-soundcard.sh
3. Choose "bluetooth devices" (last option).
4. Choose device you have just paried in step 1.
5. Start the audio app.
6. When you're done, don't forget to run "bluetoothctl" again and type "disconnect"

Pro: simple, no daemon needed.
Con: only one application can use the sound at one time. If one audio app is already using sound, starting a second audio app will fail. Switching between bluetooth speakers and/or internal soundcards require you to stop the audio app, run fatdog-default-soundcard, and then re-start it.

Method 2: Bluetooth connection using bmixd
Steps:
1. Pair the bluetooth device as above described in method #1.
2. Run fatdog-default-soundcard.sh, and choose "Bluetooth devices using blue-alsa bmixd"
3. Back on terminal, type "service bmixd start"
4. Run bluetoothctl, and inside, type "paired-devices". This will give you a list of the devices that you have paired before.
5. Type "connect AA:BB:CC:DD:EE" where AA:BB:CC:DD:EE is one of the devices you see in previous step.
6. Start the audio app
7. When you're done, don't forget to run "bluetoothctl" again and type "disconnect"

Pro: Multiple apps can output to bluetooth speaker. You can change the bluetooth devices any time you want, without restarting the audio app. If you want to switch to internal soundcard, however, you still have to re-start the app.
Con: Requires you to run the bmixd daemon.

Method 3: Bluetooth connection using aloopd
Steps:
1. Pair the bluetooth device as above described in method #1.
2. Run fatdog-default-soundcard.sh, and choose "ALSA Loop sound server (aloopd)"
3. Back to terminal, run bluetoothctl, and inside, type "paired-devices". This will give you a list of the devices that you have paired before.
4. Type "connect AA:BB:CC:DD:EE" where AA:BB:CC:DD:EE is one of the devices you see in the preivous step.
5. Edit $HOME/.aloopdrc and specify the bluetooth address AA:BB:CC:DD:EE as the bluetooth target device.
6. Type "service aloopd start".
7. Start the audio app
8. When you're done, don't forget to run "bluetoothctl" again and type "disconnect"

We may create a GUI for step 5, so you don't have to write it manually.

Pro: Multiple apps can output to bluetooth speaker. You can change the bluetooth devices any time you want, switch between internal soundcard(s), and bluetooth anytime, without restarting the app. You can also record what you hear.
Con: Requires you to run the aloopd daemon.

________________________

Notes:
1. The operations that requires the interactive "bluetoothctl" can also be done scripted using others commands: "bt-device" to connect/disconnect/pair/unpair, and "bt-adapter" to view nearby devices. See details here.

2. We used to have a GUI for all this, but when we upgraded to bluez 5, we lost that GUI tool; and we haven't gotten the chance to re-write a new GUI too. I remember, though that @stemsee had written some sort of GUI for that.

User avatar
stemsee
Posts: 780
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: Bluetooth audio, bmixd and aloopd

Post by stemsee »

Thanks @ jamesbond for the comprehensive response which I am sure others will appreciate too.

Indeed aloop will be the most versatile method.

Question would you make fatdog-default-soundcard.sh accept mac $1 input and have a default settings path requiring no interaction, so as it is at present my app, which handles bluetooth nicely, can use rely on it to set the selected bt device ... I know you don't particularly like monolithic apps which seek to do many things, but please have a look at SNAPp viewtopic.php?t=2972&start=30. It is fatdog developed. What would be required to have it accepted in the fatog repo?

regards
stemsee

jamesbond
Posts: 717
Joined: Tue Aug 11, 2020 3:02 pm
Location: The Pale Blue Dot
Has thanked: 124 times
Been thanked: 402 times

Re: Bluetooth audio, bmixd and aloopd

Post by jamesbond »

stemsee wrote: Fri Nov 05, 2021 10:04 am

Question would you make fatdog-default-soundcard.sh accept mac $1 input and have a default settings path requiring no interaction,

Sorry, stemsee, that wouldn't be possible. FDS (fatdog-default-soundcard.sh) is purposely designed to take interactive input. Making it able to take a command from the parameter and pass it down through the entire structure means a complete re-write, which I'm not motivated enough to do at this time.

If you need this functionality, my suggestion is this: why don't you run FDS with the appropriate parameter that you like, and then take the resulting .asoundrc and turn it into a template. Use "sed" script to edit this template and replace the appropriate parts to place the bluetooth MAC address etc.

As for the bluetooth gui ... after 2 years of procrastination, I have finally come up with something. It will be in 812.

but please have a look at SNAPp viewtopic.php?t=2972&start=30. It is fatdog developed. What would be required to have it accepted in the fatog repo?

Thanks stemsee, I'm not aware. I don't hang around in the forum very often anymore, so thanks for letting me know.
I will take a look. It is an SFS, right? If all is good, I can post it as a Contributor's SFS package, and it will show up in here: http://distro.ibiblio.org/fatdog/contrib/sfs/800/

User avatar
stemsee
Posts: 780
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: Bluetooth audio, bmixd and aloopd

Post by stemsee »

jamesbond wrote: Sat Nov 06, 2021 7:37 am

If you need this functionality, my suggestion is this: why don't you run FDS with the appropriate parameter that you like, and then take the resulting .asoundrc and turn it into a template. Use "sed" script to edit this template and replace the appropriate parts to place the bluetooth MAC address etc.

I already implemented that and it doesn't work!

jamesbond
Posts: 717
Joined: Tue Aug 11, 2020 3:02 pm
Location: The Pale Blue Dot
Has thanked: 124 times
Been thanked: 402 times

Re: Bluetooth audio, bmixd and aloopd

Post by jamesbond »

stemsee wrote: Sat Nov 06, 2021 2:55 pm

I already implemented that and it doesn't work!

What exactly is the problem? Several people have done this (notably, Smokey01, among others), and it works very well.

User avatar
stemsee
Posts: 780
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: Bluetooth audio, bmixd and aloopd

Post by stemsee »

Actually, I just change a few things and used only 'sed -i "s/\*\:\*\:\*\:\*\:\*/$BSSID/g" ~/asound.rc' and it works. In fact I am playing two different pieces of music one on vlc the other with ffplay, to two different bluetooth devices simultaneously .... which means this is very close to a bluetooth sound server!

I made one device default soundcard. Then started a music app, vlc, to which i kept dropping files on. Then by editing ~.asound.rc with sed added a new device, and played music to it. I repeated that step and added a third device, all three available in vlc and playing different tracks @ a2dp aptX-HD 48000hz. I noticed that there is no a2dp.fifo in /tmp. bmixd is running, starting up with X, but was not selected as default soundcard. It's interesting because using a script and suitable delay between starting sound streams, all three or more devices could have the same track playing to them... ie bluetooth sound server.

Thanks!

stemsee

User avatar
stemsee
Posts: 780
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: Bluetooth audio, bmixd and aloopd

Post by stemsee »

muti-bt-out.png
muti-bt-out.png (289 KiB) Viewed 1324 times
alsa-bt.png
alsa-bt.png (53.93 KiB) Viewed 1324 times

This is how it looks in alsa and vlc device menu. bmixd was not running this time. Still playing to 3 different mac addresses over one internal pcie wifi/bt card! Is this unusual?

But the mouse keeps locking up! Then I have to use keys to navigate and type.

User avatar
stemsee
Posts: 780
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: Bluetooth audio, bmixd and aloopd

Post by stemsee »

Also I set a default soundcard, then connected another two bt devices, then selected bmixd as default soundcard. I am able to play multiple streams to each device simultaneously! Nice!

is it possible to use two profiles on one device, a2dp playback and sco voice/headset profile? I think so.

EDIT: this ability I have discovered is stealthy to say the least. In audacity it offers a2dp_capture ??
yes bluetooth 5 allows two connected devices... but for two way audio from one standard chromebook combi wifi/bt internal card....it makes you wonder where is all this bandwidth coming from ... there was no noticeable loss in quality on any device while playing high fidelity stereo files to three different high fidelity bt speaker/soundcards!! The NHS covid trace app is bluetooth and always wants to be on! Time to get spooftooph!! https://gitlab.com/kalilinux/packages/spooftooph

Post Reply

Return to “FatDog64”