AirPlay / Spotify by Snapcast

  • Hi,

    I have a bluetooth Receiver on one of my libreelec devices (milhouse 9 build) - How can I make snapclient on this device play to the bluetooth device? Everything else on this device plays to bluetooth without issues

    System Audio is set to "PULSE: (SPEAKERNAME)"

    "snapclient -l" on ssh also only delivers the ALSA devices, no pulseaudio device

  • Hi,

    I have a bluetooth Receiver on one of my libreelec devices (milhouse 9 build) - How can I make snapclient on this device play to the bluetooth device? Everything else on this device plays to bluetooth without issues

    System Audio is set to "PULSE: (SPEAKERNAME)"

    "snapclient -l" on ssh also only delivers the ALSA devices, no pulseaudio device

    Snapclient outputs to ALSA, not to Pulseaudio.

    What you are trying to do is therefore not possible at the moment.

    Moreover, I suspect that Kodi holds the Pulseaudio speaker, and that Snapclient will not be able to share it.

    Maybe someone else here has an idea of how this could be implemented, and wants to give it a shot.

  • on PC it works just fine - here I have a output like this:

    snapclient -l

    0: default

    Playback/recording through the PulseAudio sound server

    1: null

    Discard all samples (playback) or generate zero samples (capture)

    2: pulse

    PulseAudio Sound Server


    If I select 0 here, snapclient just routes the audio to pulseaudio like any other client on the pc.

    I think there's probably the pulseaudio library missing in the snapclient addon for libreelec, so that it doesn't find the pulseaudio of libreelec?

    Also - of course kodi "holds" the pulseaudio speaker, but there is running a pulseaudio server which is used by kodi - snapclient should just output to that pulseaudio server as a source - just like it does on a desktop

    Or maybe - if for some reason that's not possible - is it possible that snapclient just outputs to "kodi" - like librespot does? that way it would just use whatever source is used in kodi, or is that not possible due to the syncing?

    Edited once, last by Catscrash (March 28, 2018 at 2:12 PM).

  • By default there is no asound.conf in LibreELEC. You could try to create /storage/.config/asound.conf to create a pulse output. You will have to reboot LibreELEC for ALSA to pick up that asound.conf.

    According to what I found /storage/.config/asound.conf should be:

    Code
    pcm.pulse {    type pulse
    }
    
    ctl.pulse {    type pulse
    }

    Let me know if it works

  • Hi,

    thank you. Okay, so that seems to do something, but I think that's not quite right, now there's nothing anymore:


    Code
    snapclient -l
    0: null
    Discard all samples (playback) or generate zero samples (capture)

    I added dtparam=audio=on to config.txt, now I have with your asound.conf again

    aplay -L gives the same output btw. I think you're right, that the alsa-pulseaudio plugin is missing or not activated somehow

    Edited once, last by Catscrash (March 28, 2018 at 4:15 PM).

  • I found this when using aplay maybe that's the issue:


    aplay a2002011001-e02.wav

    ALSA lib /home/neil/projects/http://LibreELEC.tv/build.LibreELEC-RPi2.arm-9.0-devel/alsa-lib-1.1.5/src/dlmisc.c:254:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/alsa/libasound_module_pcm_pulse.so

    aplay: main:828: audio open error: No such device or address


    Edit: I got alsa-plugins to compile as a package, now I'm just building a new image to try this, I'll report back

    Edited once, last by Catscrash (March 28, 2018 at 5:13 PM).

  • Yeah I also ran into this problem. Getting alsa-plugins into LibreELEC will solve this :)

    I will see if I can add both to snapserver (and librespot)

    That's awesome!

  • I created a new image with alsa-plugins and it's working! Unfortunately not 100% in sync with the rest yet, but that's a problem for another day

    run 'pactl list sinks' and look at 'Latency'. You'll see a value in usec displayed for your currently active output. Take this value, devide by 1000 and pass it to snapclient as the latency parameter, e.g. for a value of 30000 usec in your pulseaudio playback latency you run 'snapclient --latency=30' and everything will be in sync again.

  • No idea if it is possible to have Alsa search plugins in LD_LIBRARY_PATH.

    I've been looking and I did not find any environment variable that defines the location of alsa plugins either. That's unfortunate.

    I thought there was a possibility to specify plugin locations via asoundrc or asound.conf but I misremembered. While you can set the location of LADSPA plugins in asound.conf and specify their location via a variable called LADSPA_PATH there is no way to do this for alsa plugins.

    Having the alsa plugins in LibreELEC would be really cool though. We'd be able to use alsa's 'file' plugin to write audio to the snapserver fifo instead of using pulseaudio. For playback we could use the alsa 'dmix' plugin to have snapclient play through alsa while at the same time not blocking the output device for Kodi. We'd be using snapcast as it is intended to be used by badaix, running on alsa. As there is no native pulseaudio support snapcast can manage latency for raw alsa devices but not for pulseaudio.

    A benefit of using alsa directly would be that we would not have to set the snapclient's '--latency=xy' parameter to offset the latency that is introduced by pulseaudio (which is a unique value for every output device and cannot be statically defined for all systems and devices).

    The drawback would be that pulseaudio would still be required for playout of snapclient to bluetooth devices. Also setting the latency parameter would be required for synchronous playback. But since bluetooth playback itself introduces considerable latency, the latency parameter would have to be used to account for this anyway.

  • I've been looking and I did not find any environment variable that defines the location of alsa plugins either. That's unfortunate.

    I thought there was a possibility to specify plugin locations via asoundrc or asound.conf but I misremembered. While you can set the location of LADSPA plugins in asound.conf and specify their location via a variable called LADSPA_PATH there is no way to do this for alsa plugins.

    Having the alsa plugins in LibreELEC would be really cool though. We'd be able to use alsa's 'file' plugin to write audio to the snapserver fifo instead of using pulseaudio. For playback we could use the alsa 'dmix' plugin to have snapclient play through alsa while at the same time not blocking the output device for Kodi. We'd be using snapcast as it is intended to be used by badaix, running on alsa. As there is no native pulseaudio support snapcast can manage latency for raw alsa devices but not for pulseaudio.

    A benefit of using alsa directly would be that we would not have to set the snapclient's '--latency=xy' parameter to offset the latency that is introduced by pulseaudio (which is a unique value for every output device and cannot be statically defined for all systems and devices).

    The drawback would be that pulseaudio would still be required for playout of snapclient to bluetooth devices. Also setting the latency parameter would be required for synchronous playback. But since bluetooth playback itself introduces considerable latency, the latency parameter would have to be used to account for this anyway.

    I have reworked the alsa-plugin package to only build pulse in less than 100KB. I will submit a PR when it is ready.

    I will think about how to go forward with Snapcast and Librespot during the next days, and propose it here.

    At a glance, output to pulse and being able to control Snapserver via RPC from Kodi, at least to select a stream and set volume would allow to simplify a lot of things.

  • At a glance, output to pulse and being able to control Snapserver via RPC from Kodi, at least to select a stream and set volume would allow to simplify a lot of things.

    That would be great!! I stopped using more than one stream and stopped using volume control because I could only set those via the android app. Sometimes it worked, usually it didn't.

    Controlling these features from Kodi would be very cool :)

    If you need any testing done please let me know. I'm not a developer but I can build an image from a custom branch if needed.