[How-to] set up Bluetooth audio

Logfile is here:
https://paste.osmc.tv/owakipiqib

got it paired with bluetoothctl, but sound came random after some time.
https://paste.osmc.tv/ayelapoxef

https://paste.osmc.tv/amawatanal

edit - short info: late sound output is depended by ā€œkeep audio device aliveā€
but have no idea to solve this.

A post was split to a new topic: Canā€™t connect iPad bluetooth

LDAC and aptx_hd is supported?
I try this [GitHub - arkq/bluez-alsa: Bluetooth Audio ALSA Backend] and [GitHub - EHfive/pulseaudio-modules-bt: [Deprecated, see https://github.com/EHfive/pulseaudio-modules-bt/issues/154] Adds Sony LDAC, aptX, aptX HD, AAC codecs (A2DP Audio) support to PulseAudio on Linux] ,but only use SBC or AAC by my android device.
Please tell me how to use LDAC and aptx_hd on OSMC.
Thank you.

We do not currently build bluez-alsa with LDAC or aptx_hd because of licensing issues. You could build it yourself following the instructions here. You should not need pulseaudio - best if you remove it to avoid conflicts.

Updated: Iā€™ve added instructions for building the OSMC version of bluez-alsa above.

@nasu1105 Can you try building with these instructions? It built OK here but I canā€™t test if it actually works. Let us know.

@grahamh Thank you for teaching me how to build!
Finally, I can pair my android phone via aptx, but Iā€™m trying to enable LDAC.
Do you know how to do it?

ā†‘I could install libldacdec, but when make armv7 appeared following code.

checking for ldacBT-abr >= 1.0.0ā€¦ yes
checking for ldacBT-dec >= 2.0.0ā€¦ no
checking for ldacBT-enc >= 2.0.0ā€¦ yes

Reaching the limits of my compiler knowledge. The bluez-alsa guys mention thereā€™s no decoder in the debian repo but donā€™t tell you exactly what to do about it. They link to this, rather than anonymix007ā€™s fork.

That library would need to be built and installed inside the chroot we use for building OSMC packages. I suspect youā€™ve installed it on the main system. Run this script to go into the chroot and repeat the installation in there from the /mnt directory. exit when done and try building bluez-alsa again.

#!/bin/bash
pushd /opt/osmc-tc/armv7-toolchain-osmc/
sudo mount --bind <WHERE_YOU_CLONED_LDACBT_TO> mnt
sudo mount --bind /dev dev
sudo mount --bind /proc proc
sudo chroot .
sudo umount mnt
sudo umount dev
sudo umount proc
popd

Good luck and thanks for the feedback.

In case it helps someone else, in order to stream from my phone to my USB DAC (via RPi4) I had to set the bluealsa-aplay to one of the following:

-D plughw:CARD=Audio
-D hw:CARD=Audio
-D default:CARD=Audio
-D sysdefault:CARD=Audio

Using -D front:CARD=Audio didnā€™t work for me.

One thing Iā€™ve noticed is that the playback is at 44.1kHz (consistent with phone/spotify) and therefore seems to be bypassing OSMCā€™s audio engine which Iā€™ve set to a fixed output of 96kHz.

Yes. Kodi is not involved at all. Output goes direct through ALSA to your DAC.

Fair enough. Any idea if it can be routed through OSMCā€™s AudioEngine or otherwise upsampled?

Am hoping I can get bluetooth input to play nice with CamillaDSP which Iā€™ve got working with OSMC on a different Pi (prototyping before changing my main system). In that case, an ALSA loopback device is used to capture the output of OSMC and send it to CamillaDSP at a fixed sample rate.

You would have to use ALSA to upscale it.

Any idea how to go about this as a quick setup, as I assume this is what I so need to do for my use case?

I have just been given a soundbar and with 2x wireless speakers and a wireless sub. They have up firing speakers in them, so technically a throwdown 5.1.4 atmos system, that is only 4 boxes.

Anyhow, it seems it only does anything other than 2.0 stereo if the codec in the HDMI to it is a Dolby format, any DTS or PCM is always stereo. Plus it have some internal upmix to 5.1.4 settings for content, that also is only functional when the codec is Dolby.

I am hoping that with my Vero4k, I can somehow do a Bluetooth audio receive, from my phone playing music, then use some sort of DSP to upmix to 5.1 for stereo everywhere + low frequencies to the LFE sub channel, then get it out of the HDMI to the system as AC3.

Does that sound possible?

Everything is possible but you may have to be a developer to achieve it :stuck_out_tongue:

BT is always stereo. You can upmix that to more channels for output to HDMI with some ALSA configuration. Iā€™m surprised your soundbar canā€™t accept multi-channel PCM audio through HDMI. What is the make/model? For a digital (coaxial or ToSLink) connection it would have to be AC3 but HDMI??

When streaming from BT, we canā€™t make use of Kodiā€™s upmixing to create the LFE so that would have to be done by an ALSA filter plug-in. But then youā€™ve still got the problem of converting that to AC3.

For AC3 output, all I can think of is piping the BT input through ffmpeg then to HDMI. You would have to disable the built-in bluealsa-aplay service. Ffmpeg could probably do all of the upmix, LFE filtering and conversion to AC3 but Iā€™m not sure whether the resulting signal would be recognised by HDMI or whether something would be needed to tell HDMI ā€˜this is AC3 not PCMā€™.

I canā€™t think of an easy ā€˜off the shelfā€™ way but happy to help with bits you canā€™t do yourself.

Iā€™ve got this weird problem. My phone connects to my OSMC RPi3 and streams fine. However, audio output is HDMI, no matter how I edit my config. When I play something throuh Kodi, it plays normally through my hifiberry output.

[Unit]
Description=Bluealsa daemon
Documentation=https://github.com/Arkq/bluez-alsa/
After=dbus-org.bluez.service
Requires=dbus-org.bluez.service
StopWhenUnneeded=true

[Service]
Type=dbus
BusName=org.bluealsa
EnvironmentFile=-/etc/default/bluealsa
ExecStart=/usr/bin/bluealsa  -D default:CARD=sndrpihifiberry -p a2dp-sink  --a2dp-volume
Restart=on-failure
ProtectSystem=strict
ProtectHome=true
PrivateTmp=true
PrivateDevices=true
RemoveIPC=true
RestrictAddressFamilies=AF_UNIX AF_BLUETOOTH
; Also non-privileged can user be used
;User=bluealsa
;Group=audio
;NoNewPrivileges=true

[Install]
WantedBy=bluetooth.target

And my aplay -L:

$ aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
default
    Default Audio Device
sysdefault
    Default Audio Device
bluealsa
    Bluetooth Audio Hub
btaudio
    Bluetooth Audio
hw:CARD=vc4hdmi,DEV=0
    vc4-hdmi, MAI PCM i2s-hifi-0
    Direct hardware device without any conversions
plughw:CARD=vc4hdmi,DEV=0
    vc4-hdmi, MAI PCM i2s-hifi-0
    Hardware device with all software conversions
default:CARD=vc4hdmi
    vc4-hdmi, MAI PCM i2s-hifi-0
    Default Audio Device
sysdefault:CARD=vc4hdmi
    vc4-hdmi, MAI PCM i2s-hifi-0
    Default Audio Device
hdmi:CARD=vc4hdmi,DEV=0
    vc4-hdmi, MAI PCM i2s-hifi-0
    HDMI Audio Output
dmix:CARD=vc4hdmi,DEV=0
    vc4-hdmi, MAI PCM i2s-hifi-0
    Direct sample mixing device
hw:CARD=sndrpihifiberry,DEV=0
    snd_rpi_hifiberry_dacplus, HiFiBerry DAC+ Pro HiFi pcm512x-hifi-0
    Direct hardware device without any conversions
plughw:CARD=sndrpihifiberry,DEV=0
    snd_rpi_hifiberry_dacplus, HiFiBerry DAC+ Pro HiFi pcm512x-hifi-0
    Hardware device with all software conversions
default:CARD=sndrpihifiberry
    snd_rpi_hifiberry_dacplus, HiFiBerry DAC+ Pro HiFi pcm512x-hifi-0
    Default Audio Device
sysdefault:CARD=sndrpihifiberry
    snd_rpi_hifiberry_dacplus, HiFiBerry DAC+ Pro HiFi pcm512x-hifi-0
    Default Audio Device
dmix:CARD=sndrpihifiberry,DEV=0
    snd_rpi_hifiberry_dacplus, HiFiBerry DAC+ Pro HiFi pcm512x-hifi-0
    Direct sample mixing device

I want BT to stream to hifiberry output, but I donā€™t know how to troubleshoot. Please helpā€¦

You need to edit bluealsa-aplay.service, not bluealsa.service. For the device, Iā€™d start with dmix:CARD=sndrpihifiberry. That way you should get sound from both BT and Kodi.

YMMV.

Thanks for your quick help Graham. That did the trick! It works just fine with default:CARD=sndrpihifiberry.

/Chris

1 Like

Hi,

I am creating a application to test bluetooth speakers.The problem is MAC id of the devices changes each time , is there a way to avoid ssh and connect to speakers automatically and play the file.
But this not the only help i am seeking , I am facing some problems.

  1. I followed the steps

[NEW] Device 00:58:76:C7:18:07 CarKit_blink
[bluetooth]# trust 00:58:76:C7:18:07

After above step the device starts showing in the Paired Devices (with Red Bluetooth Icon)
[CHG] Device 00:58:76:C7:18:07 Trusted: yes
Changing 00:58:76:C7:18:07 trust succeeded
[CHG] Device 00:58:76:C7:18:07 Connected: yes

At this step,the device shows pair success

[CHG] Device 00:58:76:C7:18:07 UUIDs: 00001108-0000-1000-8000-00805f9b34fb
[CHG] Device 00:58:76:C7:18:07 UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Device 00:58:76:C7:18:07 UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device 00:58:76:C7:18:07 UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[CHG] Device 00:58:76:C7:18:07 UUIDs: 4de17a00-52cb-11e6-bdf4-0800200c9a66
[CHG] Device 00:58:76:C7:18:07 UUIDs: ec884348-cd41-40a2-9727-575d50bf1fd3
[CHG] Device 00:58:76:C7:18:07 ServicesResolved: yes
Request PIN code
[agent] Enter PIN code: 0000
[CHG] Device 00:58:76:C7:18:07 Paired: yes

  1. List item In the above step the device is asked for password, In this step my question is can this agent request come on the UI ?

  2. List item ** I am able to see two Audio Output devices , Bluetooth AudioHUB() and Bluetooth Audio() , but I am unable to hear audio.

Also, I wanted to know, if any support team , can assist in professionally taking up this project i.e to make a Bluetooth speaker tester for all kinds of speakers whether they are pairing with authentication key or without.

Thanks and Regards

Yes. In normal use you would connect using MyOSMC. Are you saying thatā€™s not working for you?

Using the command line you would normally pair first then trust the speaker. If you are having problems, try deleting the device and starting again.

They should be the same. Itā€™s a config file that needs tidying up.

Thatā€™s beyond what OSMC is designed to do. You could have a poke around in our python code and maybe get some ideas from that.

Hi,
Thanks for reply, yes I am not getting authentication request on the UI.

I am guessing the problem here is not the pairing part but the command i.e Trust.
Is there any way to add the code , so that whenever we click on a bluetooth device for pairing first it comes to trusted list then pairing starts.

I am guessing Audio Output Devices in my case are two or should be more than two because my bluetooth device ( Android Headset for a car called a Headup Display on many forums) is having two bouetooth profiles.

  1. Calling- When we receive incoming calls
  2. Music - When we play music.

Thatā€™s not expected behaviour - Iā€™ll need to check. What device are you running OSMC on? And are you using its internal BT or a dongle?