RPI3 A2DP audio sink support

  • Just got my raspberry pi 3 and it has bluetooth support. First thing I tried was streaming a2dp music to it from my cell phone. Some disappointment ensued.
    From what I read about OpenElec it's not clear to me if it should work.

    Has anyone succesfully streamed music to a rpi3 over bluetooth?

    • Official Post

    Yes it is possible, but it is not supported by default.

    On the RPi we do not use pulseaudio or alsa via Kodi. Kodi has it's own special Pi sink that it outputs directly to.

    So in order to get it to work, you need to load the snd-bcm2835 module (might be different on the RPi3)

    Code
    echo "snd-bcm2835" > /storage/.config/modules-load.d/snd-bcm2835.conf


    then reboot.
    Then you need to load the udev module

    Code
    pactl load-module module-udev-detect


    This will give you the new pulseaudio sink
    Then you need to see what sink and source you want to use.

    Code
    pactl list short
    pactl set-default-sink <sink-name>
    pactl set-default-source <source-name>

    So this is why we don't do this by default. There is no universal way to set it up across all platforms.


    PS. this will probably corrupt your audio output from kodi, so after you will want to do this

    Code
    rm /storage/.config/modules-load.d/snd-bcm2835.conf


    and reboot.


    Also, we never said this functionality would work. We simply support outputing audio from kodi to a bluetooth speaker, that's all.

  • Ah so basically the issue is that the rpi receives the BT audio perfectly but it can't output it because of the special kodi sink so instead it just ignores it. Is that what you meant lrusak?

  • Kodi has PVR support so it must contain some code to get audio from a source and put it in it's sink. Probably requires some changes but can't we tell pulse to send it to kodi and let kodi deal with it?

  • This works on my NUC after pairing my iPhone:

    Code
    pactl load-module module-udev-detect                                       
    pactl set-card-profile alsa_card.pci-0000_00_03.0 output:hdmi-stereo-extra1
    pactl set-default-sink alsa_output.pci-0000_00_03.0.hdmi-stereo-extra1

    Unfortunately it occupies the output so Kodi can't use it. Is it possible to have Pulseaudio release it when there's no audio?

    Edited once, last by escalade (May 3, 2016 at 6:29 PM).

    • Official Post


    This works on my NUC after pairing my iPhone:

    Code
    pactl load-module module-udev-detect                                       
    pactl set-card-profile alsa_card.pci-0000_00_03.0 output:hdmi-stereo-extra1
    pactl set-default-sink alsa_output.pci-0000_00_03.0.hdmi-stereo-extra1

    Unfortunately it occupies the output so Kodi can't use it. Is it possible to have Pulseaudio release it when there's no audio?

    Not really, you could restart kodi and select the new pulseaudio output that will show up in the audio output. Otherwise you will have to unload the pulseaudio module.

  • Very interesting, I hope it's alright that I revive this thread, I found it Googling.

    I assume this, A2DP music streaming to LibreELEC, is also possible with other devices, such as an RPi2 with Bluetooth dongle or an Amlogic s905 device with built in Bluetooth running LibreELEC? If so how do I find the proper module to enable (I assume snd-bcm2835 is just for RPi3) or do I have to find and download one myself or something?

    If that first part is possible, then the next step is configuring the audio sink where the Bluetooth music is routed to. Would it be possible to use an external USB sound card for that? There are cheap PCM2704 DAC's available that have a S/PDIF output which are perfect (in theory) to route the audio without loss of quality to my sound receiver. Do I need a driver or anything to get the PCM2704 USB DAC / sound card working or should it work out of the box?

    And then lastly it would be great if this A2DP streaming can be done without interfering with Kodi at all. So is it possible to enable PulseAudio just for the external USB sound card in a way that it won't interfere with Kodi? Kodi should keep outputting it's sound normally over HDMI.

    TL;DR
    The final (ideal & perfect) result I'm looking for would be that I'm able to stream music from my phone over Bluetooth to my LibreELEC device that routes this audio to an external USB sound card with a S/PDIF output that's connected to my sound receiver. Kodi should at the same time still be able to output sound over the default ALSA output (HDMI) and the Bluetooth music shouldn't interfere with Kodi at all.

    • Is it possible to use any Bluetooth dongle / device with OpenELEC and how do I find the required module to enable?
    • Is it possible to use an external USB sound card? Does LibreELEC support this out of the box or do I need drivers or something?
    • Can PulseAudio be enabled for just the external USB sound card so it won't interfere with Kodi at all?

  • Very interesting, I hope it's alright that I revive this thread, I found it Googling.

    I assume this, A2DP music streaming to LibreELEC, is also possible with other devices, such as an RPi2 with Bluetooth dongle or an Amlogic s905 device with built in Bluetooth running LibreELEC? If so how do I find the proper module to enable (I assume snd-bcm2835 is just for RPi3) or do I have to find and download one myself or something?


    Only RPi devices will have to load the module because they use a special kodi sink that doesn't require the RPi to use ALSA audio. Other devices will work without loading any audio kernel module.


    If that first part is possible, then the next step is configuring the audio sink where the Bluetooth music is routed to. Would it be possible to use an external USB sound card for that? There are cheap PCM2704 DAC's available that have a S/PDIF output which are perfect (in theory) to route the audio without loss of quality to my sound receiver. Do I need a driver or anything to get the PCM2704 USB DAC / sound card working or should it work out of the box?


    Yes it's possible, however, remember that bluetooth audio is likely to be lossful audio.
    I'm not sure if that specific USB DAC will work OOTB


    And then lastly it would be great if this A2DP streaming can be done without interfering with Kodi at all. So is it possible to enable PulseAudio just for the external USB sound card in a way that it won't interfere with Kodi? Kodi should keep outputting it's sound normally over HDMI.


    Yes it is possible.

  • Thanks for the quick reply. I've been playing around the last couple of hours and I was able to bring up my Bluetooth device with hciconfig hci0 up and give it a name with hciconfig hci0 name RPi2 and then made it discoverable using hciconfig hci0 piscan. However when I try to pair with my phone a PIN is asked and 0000 or 1234 don't work.

    I also noticed the Bluetooth device shows the Bluetooth icon on my Android phone, not a headphone icon like when pairing with speakers. Is my phone even aware it should stream music to it then? In this screenshot the top one is a paired speaker, the bottom one is my RPi2 with Bluetooth dongle.


    I was hoping to try it with bluetoothctl but that one completely freezes, it will show [bluetooth]# with a cursor but I can't enter any text. All I can do is press ctrl-c to return to the shell. So I'm not sure how to pair it from the cli then. I can't trust it

  • Boy do I feel like an idiot, I used OSMC for a while and before that I ran OpenELEC which didn't have Bluetooth support so it didn't even occur to me to look there.

    Anyways pairing via de GUI in LibreELEC settings works perfectly, safe and secure too, great :). I got my phone, tablet and Bluetooth speaker paired in seconds (while on OSMC I couldn't get anything paired anymore).

    Then to get music playing over the USB sound card all I really had to do was run pactl load-module module-udev-detect. My sound card is detected and is set as the default sink instantly (I guess because it is the only sink available on my RPi2) and my Bluetooth streamed music starts playing over my speakers, yay! At the same time I can play anything using Kodi and Kodi's sound is passed through over HDMI while simultaneously streaming Bluetooth music, exactly what I wanted to achieve.

    To automatically detect my sound card at boot I added pactl load-module module-udev-detect to autostart.sh. Funny how that was really all I had to do to get my ideal setup working.

    Lastly I would like to note that I tested all this with an old USB sound card I had lying around (a "C-Media USB headset solution") but assuming that any USB sound card will be detected as an ALSA sink (including the PCM2704 USB DAC's) this should work over S/PDIF with those kind of USB DAC's too I guess.

    Last question (I promise): all this got me wondering about one last thing regarding Amlogic S905 devices with an S/PDIF output. Is the S/PDIF device a separate ALSA sink that I can configure as the default sink with pactl while at the same time giving Kodi full access to the HDMI output so I can achieve what I described above with an Amlogic S905 with built in Bluetooth and S/PDIF out without any additional peripherals, that would be really cool. Or would I still need an external USB sound card on those devices to use as an ALSA sink for my Bluetooth A2DP music streams?

  • Last question (I promise): all this got me wondering about one last thing regarding Amlogic S905 devices with an S/PDIF output. Is the S/PDIF device a separate ALSA sink that I can configure as the default sink with pactl while at the same time giving Kodi full access to the HDMI output so I can achieve what I described above with an Amlogic S905 with built in Bluetooth and S/PDIF out without any additional peripherals, that would be really cool. Or would I still need an external USB sound card on those devices to use as an ALSA sink for my Bluetooth A2DP music streams?

    As long as the devices are separate it should be possible. Some amlogic devices show the s/pdif and hdmi devices as one device.
    [hr]
    For other people interested in this I have included a wiki post here

    Pulseaudio - LibreELEC

  • Thanks, then I guess I just have to buy one and hope to be lucky.

    In your example in the wiki you use the analog output of you Amlogic box as sink right (aml_m8)? If I may ask: what device do you have and what is the output of pactl list short sinks?


  • Thanks, then I guess I just have to buy one and hope to be lucky.

    In your example in the wiki you use the analog output of you Amlogic box as sink right (aml_m8)? If I may ask: what device do you have and what is the output of pactl list short sinks?

    The device used for the wiki page was the Wetek Hub.

    Code
    LibreELEC:~ # pactl list short sinks
    1    alsa_output.platform-aml_m8_snd.45.analog-stereo    module-alsa-card.c    s32le 2ch 44100Hz    IDLE