No Pulseaudio in Kodi, alsa sink in mono only after Buster upgrade

Problem occurred after latest update to Debian Buster.
I use OSMC on Raspberry Pi 3b.
There is no Pulseaudio output available in Kodi sound menu, even the server is working and is accessible (osmc owner). I can use Pulseaudio from command line by aplay:

aplay -L
default
    Playback/recording through the PulseAudio sound server
null
    Discard all samples (playback) or generate zero samples (capture)
jack
    JACK Audio Connection Kit
pulse
    PulseAudio Sound Server
sysdefault:CARD=ALSA
    bcm2835 ALSA, bcm2835 ALSA
    Default Audio Device
dmix:CARD=ALSA,DEV=0
    bcm2835 ALSA, bcm2835 ALSA
    Direct sample mixing device
dmix:CARD=ALSA,DEV=1
    bcm2835 ALSA, bcm2835 IEC958/HDMI
    Direct sample mixing device
dmix:CARD=ALSA,DEV=2
    bcm2835 ALSA, bcm2835 IEC958/HDMI1
    Direct sample mixing device
dsnoop:CARD=ALSA,DEV=0
    bcm2835 ALSA, bcm2835 ALSA
    Direct sample snooping device
dsnoop:CARD=ALSA,DEV=1
    bcm2835 ALSA, bcm2835 IEC958/HDMI
    Direct sample snooping device
dsnoop:CARD=ALSA,DEV=2
    bcm2835 ALSA, bcm2835 IEC958/HDMI1
    Direct sample snooping device
hw:CARD=ALSA,DEV=0
    bcm2835 ALSA, bcm2835 ALSA
    Direct hardware device without any conversions
hw:CARD=ALSA,DEV=1
    bcm2835 ALSA, bcm2835 IEC958/HDMI
    Direct hardware device without any conversions
hw:CARD=ALSA,DEV=2
    bcm2835 ALSA, bcm2835 IEC958/HDMI1
    Direct hardware device without any conversions
plughw:CARD=ALSA,DEV=0
    bcm2835 ALSA, bcm2835 ALSA
    Hardware device with all software conversions
plughw:CARD=ALSA,DEV=1
    bcm2835 ALSA, bcm2835 IEC958/HDMI
    Hardware device with all software conversions
plughw:CARD=ALSA,DEV=2
    bcm2835 ALSA, bcm2835 IEC958/HDMI1
    Hardware device with all software conversions
usbstream:CARD=ALSA
    bcm2835 ALSA
    USB Stream Output
sysdefault:CARD=Audio
    iFi (by AMR) HD USB Audio, USB Audio
    Default Audio Device
front:CARD=Audio,DEV=0
    iFi (by AMR) HD USB Audio, USB Audio
    Front speakers
surround21:CARD=Audio,DEV=0
    iFi (by AMR) HD USB Audio, USB Audio
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=Audio,DEV=0
    iFi (by AMR) HD USB Audio, USB Audio
    4.0 Surround output to Front and Rear speakers
surround41:CARD=Audio,DEV=0
    iFi (by AMR) HD USB Audio, USB Audio
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Audio,DEV=0
    iFi (by AMR) HD USB Audio, USB Audio
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Audio,DEV=0
    iFi (by AMR) HD USB Audio, USB Audio
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Audio,DEV=0
    iFi (by AMR) HD USB Audio, USB Audio
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=Audio,DEV=0
    iFi (by AMR) HD USB Audio, USB Audio
    IEC958 (S/PDIF) Digital Audio Output
dmix:CARD=Audio,DEV=0
    iFi (by AMR) HD USB Audio, USB Audio
    Direct sample mixing device
dsnoop:CARD=Audio,DEV=0
    iFi (by AMR) HD USB Audio, USB Audio
    Direct sample snooping device
hw:CARD=Audio,DEV=0
    iFi (by AMR) HD USB Audio, USB Audio
    Direct hardware device without any conversions
plughw:CARD=Audio,DEV=0
    iFi (by AMR) HD USB Audio, USB Audio
    Hardware device with all software conversions
usbstream:CARD=Audio
    iFi (by AMR) HD USB Audio
    USB Stream Output

Also the Pulseaudio creates alsa sink only in mono:

0       alsa_output.usb-iFi__by_AMR__iFi__by_AMR__HD_USB_Audio-00.analog-stereo module-alsa-card.c      s32le 2 k 44100 Hz      SUSPENDED
1       alsa_output.platform-soc_audio.analog-mono      module-alsa-card.c      s16le 1 k 44100 Hz      SUSPENDED

There is no other profiles available.

Before upgrade I had installed a2dp-app-osmc package, with is unavailable in current compilation. I removed it, but maybe it has done some mess.
I reinstalled Pulseaudio without success.
I would like to reinstall Alsa, but there is no alsa-base package, so I do not know how to do that.
Maybe fresh install?

What is your specific need for pulseaudio? We are trying to move away from it.
If it was for Bluetooth audio (as you write a2dp) I suggest you remove pulseaudio and try our new approach of alsa (can give you the instructions if you want).

Yes, I tested it with Bluetooth headphones, and it working as charm - but only with one pair ;-(
I have 3 children and my goal was to connect 3 BT headsets at once.
I managed to do that by using udev rules and creating combined sink in Pulseaudio.
I don’t know how to approach this without Pulse, because after another headset connects, the other ones mutes (quite logic)

Yeah than you might need to stick to Pulseaudio. But then unfortunately can not help more.

Before I removed a2dp package I had “Bluetooth audio device” and “Pulseaudio” in my audio outputs in KODI. One headphones was working perfect, but it was not available as sink at Pulseaudio. I thought the Bluetooth device is “catched” by KODI/ALSA, before pulseaudio-bluetooth-module can access it. So I removed a2dp package. Now the pulseaudio in creating bluez sink again, but the audio outputs “Bluetooth audio device” and “Pulseaudio” disappeared.
Does Your new approach of alsa is based on bluez-alsa (there is no such package). Can I turn it off to prevent catching bluetooth devices?
BTW: when the new installation image will be available?

Yes the new approach is Bluez and Alsa based.
The bluez package is called armv7-bluez-osmc

Most likely next 24 hours

Won’t I lost Bluetooth support at all if I remove armv7-bluez-osmc?
Is there a way to reinstall alsa (without alsa-base package)? I worry a2dp-app-osmc package made some mess in alsa.

Yes, but you asked about it :wink:

There is no alsa package as it is part of the kernel AFAIK

After removing the a2dp package there is some cruft left which needs to be removed manually, including a pseudo-package bluez. I think apt-get autoremove will fix it. Then search out any files with pulse in the name in the places where alsa keeps its conf files and remove them. After a re-boot you should then be back to stock alsa with no pulse entries in Kodi.

Our current BT audio implementation is based on bluez-alsa. You can get a .deb from here https://collab.osmc.tv/s/hxG3JX4m3rY2XiM. You will be prompted to install a couple of other packages (with apt-get) and get a message about setting up a .asoundrc file. This implementation is experimental and the need to make a .asoundrc file manually will be removed in time.

As for playing to several BT devices at once, it might be possible with some alsa conf magic. I’ve managed to get output to BT and HDMI at the same time but never tried two or more BT devices. There are some posts about using pulseaudio with bluez-alsa on the bluez-alsa github but it’s not something that’s recommended.

Thank - that is the clue - I try it!

I thought that alsa-bluez was implemented in last upgrade… If not, how is to be possible for me to see “ALSA: Bluetooth audio device” (or something similar) in KODI audio output devices??? Was it caused by a2dp package (the entry disappeared with removal of a2dp)?

If I understand clearly: I have to write .asoundrc by myself (based of example), and look for a way to get simultaneous output in alsa configuration files.

This is provided by the A2DP package. PulseAudio exposes an ALSA sink.

Removing pulse .conf files should fix that.

@grahamh I’ve had no luck getting my bluetooth headphones working using the new armv7-bluez-alsa-osmc package. I can get the headphones paired and connected using bluetoothctl and I can get alsa to list my device I’ve created in the .asoundrc file. When I attempt to play a file with aplay I can get it actually connecting to the device somehow (I can hear a faint ‘click’ in the headphones) but no audio plays:

$ aplay --verbose -D mybtdevice (filename.wav)

Logs show an error at the same moment:

Oct 21 14:31:45 myhostname bluealsa[6558]: /usr/bin/bluealsa: E: Couldn’t set audio object type: Invalid config

My .asoundrc is exactly as the example, except I’ve entered the MAC address of my headphones.

My headphones DO support LE, and if I use the MyOSMC Network Bluetooth GUI to connect to them, it displays them as connecting using LE, which presumably isn’t supported (and didn’t work when I was using pulseaudio), but when I re-pair them and connect with bluetoothctl it appears to connect without LE.

I do see my device displayed in the audio system configuration in Kodi, but selecting it doesn’t output anything.
Furthermore, to my surprise, alsamixer does not display my device in the list of sound devices, but if I manually enter bluealsa it shows me the connected bluetooth device with the correct name.

I previously had this working using pulseaudio but I had seen this was no longer necessary and have removed pulseaudio and the previous bluez packages. I feel like I’m on the verge of having this work, but some little thing is missing. When I was using pulseaudio, I had to manually set the profile to a2dp_sink with:

$ pacmd set-card-profile card_number a2dp_sink

I don’t know what the equivalent to this is without pulseaudio. I had considered that the bluetoothctl command register-profile with the UUID of the Audio Sink profile might do this, but it returns only: Failed to register profile: org.freedesktop.DBus.Error.UnknownMethod

Update: I’ve tried this with a different bluetooth device, a speaker, with exactly the same results.

Can you post your .asoundrc. That error message implies a syntax error I think.

My .asoundrc is:

pcm.mybtdevice {
        type bluealsa
        device "XX:XX:XX:XX:XX:XX"
        profile "a2dp"
        hint { show on description "BT Headphones"}
}

A syntax error causes bluealsa to crash on startup (I had a missing brace at some point). Also:

  • Kodi does (sometimes) display ALSA: BT Headphones in the audio device menu
  • aplay -L displays mybtdevice as a PCM
  • ALSA is making some sort of connection to the BT device, since I can hear the ‘click’ of the DAC turning on in the headphones when I us aplay.
  • Finally, my .asoundrc is literally just copied from the included example, with a changed MAC address and description.

What would be the next thing to check?

Maybe it helps, but I also need help.
As I wrote before my object is to use 3 bluetooth headset at the same time.
That is what I done:

removed pulseaudio (I had installed it before) and installed bluez-alsa.
Than I duplicated (tripled to be honest) the services bluealsa.service and bluealsa-aplay.service
They looks like that:

; Unit file from bluealsa wiki by borine

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

[Service]
Type=dbus
BusName=org.bluealsa.bluealsa1
EnvironmentFile=-/etc/default/bluealsa
ExecStart=/usr/bin/bluealsa $OPTIONS1
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:

[Unit]
Description=A2DP Playback1
After=bluealsa_1.service syslog.service
Requires=bluealsa_1.service
StopWhenUnneeded=true

[Service]
ExecStartPre=/bin/sleep 3
ExecStart=/usr/bin/bluealsa-aplay --profile-a2dp 00:00:00:00:00:00 -B bluealsa1
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=A2DP-Playback1
Restart=on-failure

[Install]
WantedBy=bluetooth.target

I also modified d-bus config files.
Each headphone is connecting to different BT dongle, so the hci number can change. I resolved the problem by using the rc.local.service to create proper /etc/default/bluealsa config file:

blue1=$(hcitool dev | grep 00:1A:7D:DA:71:0A | sed 's/^.*hci/hci/' | cut -c-4)
blue2=$(hcitool dev | grep 5C:F3:70:13:D4:F9 | sed 's/^.*hci/hci/' | cut -c-4)
blue3=$(hcitool dev | grep 00:1A:7D:DA:71:11 | sed 's/^.*hci/hci/' | cut -c-4)

O_1=$(echo 'OPTIONS1="-i '$blue1' -B bluealsa1 -S"') 
O_2=$(echo 'OPTIONS2="-i '$blue2' -B bluealsa2 -S"') 
O_3=$(echo 'OPTIONS3="-i '$blue3' -B bluealsa3 -S"') 

printf "$O_1 \n $O_2 \n $O_3" > /etc/default/bluealsa

It’s attaching correct bluetooth headset (and dongle) to proper d-bus name. So the config file starts to look like that:

OPTIONS1="-i hci1 -B bluealsa1 -S" 
 OPTIONS2="-i hci2 -B bluealsa2 -S" 
 OPTIONS3="-i hci0 -B bluealsa3 -S"

and is updated during startup.

And now the .asoundrc file:

pcm.headphones_1 {
        type plug
        slave.pcm {
                service "org.bluealsa.bluealsa1"
                type bluealsa
                device "5C:FB:7C:16:79:FC"
                profile "a2dp"
        }
        hint {
                show on
                description "description - Headphones 1"
        }

}

pcm.headphones_2 {
        type plug
        slave.pcm {
                type bluealsa
                service "org.bluealsa.bluealsa2"
                device "5C:FB:7C:16:20:1E"
                profile "a2dp"
        }
        hint {
                show on
                description "description - Headphones 2"
        }
}

pcm.headphones_3 {
        type plug
        slave.pcm {
                type bluealsa
                service "org.bluealsa.bluealsa3"
                device "E8:D0:3C:FC:3C:E2"
                profile "a2dp"
        }
        hint {
                show on
                description "description - Headphones 3"
        }
}

ctl.headphones_1 {
        type bluealsa
        interface "hci0"
}

ctl.headphones_2 {
        type bluealsa
        interface "hci1"
}


ctl.headphones_3 {
        type bluealsa
        interface "hci3"
}

pcm.headphones {
        type multi
        slaves.a.pcm "headphones_1"
        slaves.b.pcm "headphones_2"
        slaves.c.pcm "headphones_3"
        slaves.a.channels 2
        slaves.b.channels 2
        slaves.c.channels 2
        bindings.0.slave a;
        bindings.0.channel 0;
        bindings.1.slave a;
        bindings.1.channel 1;
        bindings.2.slave b;
        bindings.2.channel 0;
        bindings.3.slave b;
        bindings.3.channel 1;
        bindings.4.slave c;
        bindings.4.channel 0;
        bindings.5.slave c;
        bindings.5.channel 1;
}

ctl.headphones {
    type hw;
    card 0;
}

pcm.stereo2quad {
    type route
    slave.pcm "headphones"
    ttable.0.0 1
    ttable.1.1 1
    ttable.0.2 1
    ttable.1.3 1
    ttable.0.4 1
    ttable.1.5 1
}

The “ctl” are messed - it does not matter at this time.

It’s almost working. All of BT headset are is connecting, and I can play audio to each of them by aplay (aplay -D headphones_[1-3]).
There are two problems:

  1. When I try to play through stereo2quad output (a kind of combined device of alsa, with should play
    through all headphones) I get error:

    Playing WAVE ‘test.wav’ : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
    aplay: set_params:1345: Channels count non available

  2. No matter what there is no headphones output in kodi available

Great work! A channels count not available can usually be fixed with a plug, but I couldn’t tell you where to insert it.

On the other hand, you do have plugs in each headphone_* device. IIRC that can be counter-productive. If it helps, here is my .asoundrc for playing audio to both BT and HDMI at once. I had to use an upmix to get the audio in sync between them - you won’t need that I guess.

pcm.jblflip {
        type bluealsa
        device "FC:A8:9A:B3:42:4F"
        profile "a2dp"
        hint { show on description "JBL Flip 3"}
}

pcm.both {
        type upmix
        slave "pairup"
        channels 4
        delay 50
        hint {
                show {
                        @func refer
                        name defaults.namehint.extended
                }
                description "BT & default"
        }
}

pcm_slave.pairup.pcm {
        type plug
        slave.pcm {
                type multi
                        slaves {
                                a { pcm "jblflip" channels 2 }
                                b { pcm "default" channels 2 }
                        }
                bindings [
                { slave a channel 0 }
                { slave a channel 1 }
                { slave b channel 0 }
                { slave b channel 1 }
                ]
        }
}

As for Kodi recognising the devices, all I can say is with my .asoundrc both ‘JBL Flip 3’ and ‘BT & default’ show up. A BT device has to be connected in order to show up in the Kodi audio settings and Kodi has to be able to open the device - so if stereo2quad isn’t opening with aplay it won’t show up in Kodi. A Kodi debug log should tell you whether it can open each device.

Can you post debug logs for you trying to select the device?

That’s expected. bluealsa isn’t a hardware device but a plugin. alsamixer -Dbluealsa shows you the controls.

configuring alsa is to confusing for me ;-/

pcm.headphones_1 {
                service "org.bluealsa.bluealsa1"
                type bluealsa
                device "5C:FB:7C:16:79:FC"
                profile "a2dp"
                hint { show on description "description - Headphones 1" }
}

pcm.headphones_2 {
                type bluealsa
                service "org.bluealsa.bluealsa2"
                device "5C:FB:7C:16:20:1E"
                profile "a2dp"
                hint { show on description "description - Headphones 2" }
}

pcm.headphones_3 {
                type bluealsa
                service "org.bluealsa.bluealsa3"
                device "E8:D0:3C:FC:3C:E2"
                profile "a2dp"
                hint { show on description "description - Headphones 3" }
}


ctl.headphones_1 {
        type bluealsa
}

ctl.headphones_2 {
        type bluealsa
}

ctl.headphones_3 {
        type bluealsa
}


pcm_slave.pairup.pcm {
        type plug
        slave.pcm {
                type multi
                        slaves {
                                a { pcm "headphones_1" channels 2 }
                                b { pcm "headphones_2" channels 2 }
                                c { pcm "headphones_3" channels 2 }                        
                        }
                bindings [
                { slave a channel 0 }
                { slave a channel 1 }
                { slave b channel 0 }
                { slave b channel 1 }
                { slave c channel 0 }
                { slave c channel 1 }
                ]
        }
}

pcm.both {
        type upmix
        slave "pairup"
        channels 6
        delay 50
        hint {
                show {
                        @func refer
                        name defaults.namehint.extended
                }
                description "BT & default"
        }
}

No matter what, now the error is:

aplay -D both test.wav                      
Playing WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
ALSA lib pcm_params.c:2226:(snd1_pcm_hw_refine_slave) Slave PCM not usable
aplay: set_params:1310: Broken configuration for this PCM: no configurations available

You and me both. It’s always a long story of trial and error.

Forget about the upmix. That’s a special plugin that I think only supports 2+2 channels and you don’t need it for a delay so use route instead as you did before. Just try removing the plugs from each headphone.pcm as you have with this latest.