Enabling Bluetooth Audio Output

Need help with MPD?
Post Reply
cober
Posts: 6
Joined: November 4th, 2018, 7:33 am

Enabling Bluetooth Audio Output

Post by cober » November 24th, 2018, 4:07 pm

Hi,

I would need some help/advice for having Linux streaming mpd's audio output to a connected Bluetooth device.

I am running mpd 0.20.18 on a Laptop with Ubuntu 18.04.1.
Basically I can succesfully connect from Ubuntu to various Bluetooth devices (e.g. speakers, AV receiver). For example anything I play with VLC can be heard via the connected Bluetooth device.

Unfortunately, this is not true for mpd. Its audio output is always played locally on the Laptop.
:arrow: Is there something special to be considered in mpd.conf?

My current output setting is alsa with only the mandatory config properties enabled:

Code: Select all

audio_output {
        type            "alsa"
        name            "My ALSA Device"
#       device          "hw:0,0"        # optional
#       mixer_type      "hardware"      # optional
#       mixer_device    "default"       # optional
#       mixer_control   "PCM"           # optional
#       mixer_index     "0"             # optional
}
This is what mpd --version gives me:

Code: Select all

Music Player Daemon 0.20.18

Copyright (C) 2003-2007 Warren Dukes <warren.dukes@gmail.com>
Copyright 2008-2017 Max Kellermann <max.kellermann@gmail.com>
This is free software; see the source for copying conditions.  There is NO
warranty; not even MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Database plugins:
 simple proxy upnp

Storage plugins:
 local smbclient nfs curl

Neighbor plugins:
 smbclient upnp

Decoders plugins:
 [mad] mp3 mp2
 [mpg123] mp3
 [vorbis] ogg oga
 [oggflac] ogg oga
 [flac] flac
 [opus] opus ogg oga
 [sndfile] wav aiff aif au snd paf iff svx sf voc w64 pvf xi htk caf sd2
 [audiofile] wav au aiff aif
 [dsdiff] dff
 [dsf] dsf
 [faad] aac
 [mpcdec] mpc
 [wavpack] wv
 [modplug] 669 amf ams dbm dfm dsm far it med mdl mod mtm mt2 okt s3m stm ult umx xm
 [mikmod] amf dsm far gdm imf it med mod mtm s3m stm stx ult uni xm
 [sidplay] sid mus str prg P00
 [wildmidi] mid
 [fluidsynth] mid
 [adplug] amd d00 hsc laa rad raw sa2
 [ffmpeg] 16sv 3g2 3gp 4xm 8svx aa3 aac ac3 adx afc aif aifc aiff al alaw amr anim apc ape asf atrac au aud avi avm2 avs bap bfi c93 cak cin cmv cpk daud dct divx dts dv dvd dxa eac3 film flac flc fli fll flx flv g726 gsm gxf iss m1v m2v m2t m2ts m4a m4b m4v mad mj2 mjpeg mjpg mka mkv mlp mm mmf mov mp+ mp1 mp2 mp3 mp4 mpc mpeg mpg mpga mpp mpu mve mvi mxf nc nsv nut nuv oga ogm ogv ogx oma ogg omg opus psp pva qcp qt r3d ra ram rl2 rm rmvb roq rpl rvc shn smk snd sol son spx str swf tak tgi tgq tgv thp ts tsp tta xa xvid uv uv2 vb vid vob voc vp6 vmd wav webm wma wmv wsaud wsvga wv wve
 [gme] ay gbs gym hes kss nsf nsfe sap spc vgm vgz
 [pcm]

Filters:
 libsamplerate soxr

Tag plugins:
 id3tag

Output plugins:
 shout null fifo pipe alsa roar ao oss openal pulse jack httpd recorder

Encoder plugins:
 null vorbis opus lame wave flac

Archive plugins:
 [bz2] bz2
 [zzip] zip
 [iso] iso

Input plugins:
 file alsa archive curl ffmpeg smbclient nfs mms cdio_paranoia

Playlist plugins:
 extm3u m3u pls xspf asx rss soundcloud flac cue embcue

Protocols:
 file:// http:// https:// mms:// mmsh:// mmst:// mmsu:// gopher:// rtp:// rtsp:// rtmp:// rtmpt:// rtmps:// smb:// nfs:// cdda:// alsa://

Other features:
 avahi epoll icu inotify ipv6 systemd tcp un
Best regards,
Christoph

max
Forum team
Posts: 886
Joined: January 15th, 2013, 3:43 pm

Re: Enabling Bluetooth Audio Output

Post by max » November 26th, 2018, 9:37 am

Is your Bluetooth device visible as an ALSA device in "aplay -l" or "cat /proc/asound/cards"?

cober
Posts: 6
Joined: November 4th, 2018, 7:33 am

Re: Enabling Bluetooth Audio Output

Post by cober » November 26th, 2018, 6:47 pm

Hi Max,

no, my Bluetooth controller is not listed with any of the commands you were suggesting:

Code: Select all

play -l
**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: CX20590 Analog [CX20590 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

Code: Select all

cat /proc/asound/cards
 0 [PCH            ]: HDA-Intel - HDA Intel PCH
                      HDA Intel PCH at 0xc3610000 irq 30
Your question kind of conveys it should be listed there in order to achieve what I want...

In fact it was not really a straight forward task to get my Bluetooth controller (BCM43142) working with Ubuntu. But considering Google as my friend I finally succeeded:

Code: Select all

dmesg | grep -i 'bluetooth'
[    3.320331] Bluetooth: Core ver 2.22
[    3.320344] Bluetooth: HCI device and connection manager initialized
[    3.320347] Bluetooth: HCI socket layer initialized
[    3.320349] Bluetooth: L2CAP socket layer initialized
[    3.320358] Bluetooth: SCO socket layer initialized
[    3.476218] Bluetooth: hci0: BCM: chip id 70
[    3.479775] Bluetooth: hci0: BCM: features 0x06
[    3.496270] Bluetooth: hci0: COBERMOBILE
[    3.496275] Bluetooth: hci0: BCM (001.001.011) build 0289
[    4.073539] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[    4.073541] Bluetooth: BNEP filters: protocol multicast
[    4.073545] Bluetooth: BNEP socket layer initialized
[    4.265204] Bluetooth: hci0: BCM (001.001.011) build 0341
[    4.281208] Bluetooth: hci0: BCM43142A0 Generic USB Class 2 NonUHE @ 20 MHz
[  271.186173] Bluetooth: hci0: BCM: chip id 70
[  271.187167] Bluetooth: hci0: BCM: features 0x06
[  271.203156] Bluetooth: hci0: BCM43142A
[  271.203163] Bluetooth: hci0: BCM (001.001.011) build 0000
[  272.065218] Bluetooth: hci0: BCM (001.001.011) build 0341
[  272.081184] Bluetooth: hci0: BCM43142A0 Generic USB Class 2 NonUHE @ 20 MHz
I hope Google can help my once more to dig up some relevant hints and infos on how to add this Bluetooth controller as an alsa device.
Or is there anybody in this forum who has experience with Broadcom Bluetooth controllers to be used as alsa device?

Best regards,
Christoph

max
Forum team
Posts: 886
Joined: January 15th, 2013, 3:43 pm

Re: Enabling Bluetooth Audio Output

Post by max » November 26th, 2018, 9:41 pm

I've never used Bluetooth audio stuff, but I thought they'd be accessed via the ALSA API, like any other sound output on Linux. Apparently, Bluetooth is special and require a different API, which is an unfortunate design choice.

Those other programs you listed may have implemented that Bluetooth-specific API. MPD does not, so you're out of luck. This needs a volunteer to figure out how it works and write a new output plugin for MPD.

cober
Posts: 6
Joined: November 4th, 2018, 7:33 am

Re: Enabling Bluetooth Audio Output

Post by cober » November 27th, 2018, 6:06 am

Hi,

just letting you know I finally succeeded to listen to MPD's output on a Bluetooth device.
I more or less followed the instructions found here: https://askubuntu.com/questions/555103/ ... pulseaudio

This means I changed the audio_output in my mpd.conf from ALSA to PulseAudio along with a enabling TCP for PulseAudio.
In addition, I had to All these actions helped me to have my Ubuntu-Laptop streaming MPD's output to my Bluetooth device in fine A2DP quality.

Cheers,
Christoph

max
Forum team
Posts: 886
Joined: January 15th, 2013, 3:43 pm

Re: Enabling Bluetooth Audio Output

Post by max » November 27th, 2018, 9:44 am

Thanks for the feedback, this might help other people get started - but I think this is a pretty complicated and fragile solution. It would be better to have native Bluetooth support in MPD. Let's hope somebody drops some code to me.

skidoo
Posts: 165
Joined: April 28th, 2013, 10:06 pm
Location: Western Germany

Re: Enabling Bluetooth Audio Output

Post by skidoo » November 27th, 2018, 10:39 am

The current status quo is, that in order to stream audio from/to a Bluetooth device, one has to install PulseAudio, or use Bluez < 5. However, Bluez version 4 is considered to be deprecated.
Possible solution is to use BlueALSA https://github.com/Arkq/bluez-alsa

Very basic example config:

Code: Select all

audio_output {
        type            "alsa"
        name            "Bluetooth enabled device"
        device          "bluealsa:HCI=hci0,DEV=00:11:22:33:44:55,PROFILE=a2dp"
}
Give it a try.

cober
Posts: 6
Joined: November 4th, 2018, 7:33 am

Re: Enabling Bluetooth Audio Output

Post by cober » November 27th, 2018, 5:51 pm

BlueALSA was one of the first solutions I stumbled across yesterday evening (when my friend Google joined me to see what the Internet has in store for me ;))
Unfortunately, I did not get BlueALSA working right away... I gave it a try with aplay using the very same syntax as suggested by skidoo for the ALSA device in mpd.conf. But since it did not work for me (alas, I don't remember the exact error messages) I gave up and looked for another solution.

But knowing it actually should work -- especially with MPD -- I will start a second attempt with BlueALSA!

skidoo
Posts: 165
Joined: April 28th, 2013, 10:06 pm
Location: Western Germany

Re: Enabling Bluetooth Audio Output

Post by skidoo » November 27th, 2018, 11:54 pm

@Christoph> Building BlueALSA from source, installing, systemd startup and usage was pretty straight forward on a headless server. But I can not help with Pulseaudio, sorry.

@max> adding Bluetooth audio devices (and Chromecasts or SnapCast clients) during runtime would be would be pretty cool. :D

cober
Posts: 6
Joined: November 4th, 2018, 7:33 am

Re: Enabling Bluetooth Audio Output

Post by cober » November 29th, 2018, 7:51 pm

Hi skidoo,

getting+building+running BlueALSA was not the problem. At least I hope I did everything correctly, because it is still not working properly.
Whenever I try to play something via BlueALSA using aplay I get the following error:

Code: Select all

aplay -v -D bluealsa:HCI=hci0,DEV=B8:69:C2:54:06:7B,PROFILE=a2dp test.mp3 
ALSA lib ../../../src/asound/bluealsa-pcm.c:653:(_snd_pcm_bluealsa_open) BlueALSA connection failed: No such file or directory
aplay: main:788: audio open error: No such file or directory
The device specified with DEV is definitely connected and I can hear sound through it. (Unfortunately it is not the sound coming via BlueALSA).

I guess there is some interference between (Blue)ALSA and PulseAudio (the latter still being present somehow) which needs to be resolved.
I can post some updates next week, I won't find time to investigate this in the next couple of days.

Cheers,
Christoph

skidoo
Posts: 165
Joined: April 28th, 2013, 10:06 pm
Location: Western Germany

Re: Enabling Bluetooth Audio Output

Post by skidoo » November 29th, 2018, 10:11 pm

You have to turn off PulseAudio.
1. Open the ~/.pulse/client.conf file to disable PulseAudio for the current user,

OR

Open the /etc/pulse/client.conf file to disable PulseAudio for all users.
2. Set the following attribute and ensure the line is not commented out:

autospawn = no
3. Call pulseaudio --kill to end the PulseAudio process.
4. Call ps -e | grep pulse to check the process stopped correctly.

max
Forum team
Posts: 886
Joined: January 15th, 2013, 3:43 pm

Re: Enabling Bluetooth Audio Output

Post by max » November 30th, 2018, 7:55 am

So if another process (i.e. PulseAudio) is already using the Bluetooth device, then the second process gets "No such file or directory" instead of "Device busy"? Uh, not so user friendly.

Post Reply