ashthespy / Vollibrespot

Spotify Connect daemon for Volumio
MIT License
20 stars 8 forks source link

Issues setting up snapcast #2

Closed foreveremain closed 5 years ago

foreveremain commented 5 years ago

After upgrading volumio in May 2019, volspotconnect2 no longer played tracks through a custom alsa sink (even though the spotify app thought it was playing). Executing vollibrespot directly revealed the alsa error messages below. I've seen the same with all versions of vollibrespot including latest v0.1.6. Also seen with Raspotify 0.13.x, with the last good version of raspotify was 0.12, built with librespot daeeeaa (2019-02-22).

Linux volumio-bedroom 4.14.92-v7+ #1187 SMP Wed Jan 9 20:01:54 GMT 2019 armv7l GNU/Linux volumio version: 2.587 (rasbian 8 on Pi 3B) Plugins: snapcast + vollibrespot Alsaconfig: snapcast device resample 48->44.1

volumio@volumio-bedroom:~$ ./vollibrespot -b 320 -c /tmp --disable-audio-cache --name Volumio-bedroom 70 --device snapcast
vollibrespot v0.1.6 cd3b133 2019-04-29 (librespot b5c80bf 2018-11-27) -- Built On 2019-04-29
[Vollibrespot] : Failed to register IPv6 receiver: Os { code: 19, kind: Other, message: "No such device" }
[Vollibrespot] : Connecting to AP "gew1-accesspoint-a-qjwc.ap.spotify.com:4070"
[Vollibrespot] : Authenticated as "foreveremain" !
[Vollibrespot] : Using alsa sink
[Vollibrespot] : Metadata pipe established
[Vollibrespot] : Country: "GB"
[Vollibrespot] : SessionActive!
[Vollibrespot] : Loading track "Altitude Dub" with Spotify URI "spotify:track:4JJ4zbQiFYGm6VzoTKyldy"
[Vollibrespot] : Track "Altitude Dub" loaded
[Vollibrespot] : Alsa error PCM open ALSA function 'snd_pcm_hw_params' failed with error 'EINVAL: Invalid argument'
[Vollibrespot] : Could not start audio: Alsa error: PCM open failed

Apologies to be the bearer of bad tidings ! Let me know if you'd like me to try anything..

ashthespy commented 5 years ago

Looks like the device snapcast isn't a valid ALSA device, and thus it's complaining. I am not to well versed with snapcast, but it believe you probably need to pass the --backend pipe option to VLS.

ashthespy commented 5 years ago

Yep, seems the case https://github.com/Saiyato/volumio-snapcast-plugin/issues/60 https://github.com/Saiyato/volumio-snapcast-plugin/pull/61

foreveremain commented 5 years ago

thanks. snapcast is a PCM patch device to resample 44.1->48k, as a fix the spotify-resample problem:

https://github.com/badaix/snapcast/issues/45

--backend pipe works, but still requires a resample before passing to snapserver. Earlier versions of librespot could write to the PCM device directly, but something seems to have changed after daeeeaa. I'm not enough of an alsa expert to work out what's going on here ! Either way I guess its an upstream issue.

ashthespy commented 5 years ago

What does your asound.conf look like? I will try and recreate something this side to debug. From the error - ALSA can't read the PCM handle that was given to it (EINVAL).

ashthespy commented 5 years ago

Btw - can't you achieve the resampling from directly by setting sampleformat to something like &sampleformat=44100:16:2 ?

foreveremain commented 5 years ago

Thanks for keeping with this one !

#SNAPCAST
pcm.!snapcast {
type plug
slave {
pcm rate48000Hz # Direct default output to the below converter
}
}

pcm.rate48000Hz {
type rate
slave {
pcm writeFile # Direct to the plugin which will write to a file
format S16_LE
rate 48000
}
}

pcm.writeFile {
type file
slave.pcm null
file "/tmp/snapfifo"
format "raw"
}

#ENDOFSNAPCAST

This is the vanilla solution for upsampling the 44.1k spotify stream to 48k which is the only one natively supported by the android snapcast client. I noticed someone over at https://github.com/librespot-org/librespot/issues/340 suggested a fix of changing the snapcast samplerate -- that's fine if your sink handles it but most don't.

ashthespy commented 5 years ago

So I had some time tonight, so tired to understand what is going on with this. It looks like this plug device is quite sensitive to the snd_pcm_hw_params that alsa needs to set up the device before opening it up.

I made a new test build based on some trial and error - but since I don't have snapcast setup, I'd request you to test it out. This build should open up the device without crashing, but don't know if the parameters would actually lead to some sensible output. Either way, it needs to be passed a special flag, like so:

LIBRESPOT_RATE_RESAMPLE=1 /data/plugins/music_service/volspotconnect2/vollibrespot -n test --device snapcast

vollibrespot.zip

Let me know!

foreveremain commented 5 years ago

Looks good !

volumio@volumio-bedroom:~$ LIBRESPOT_RATE_RESAMPLE=1 ./vollibrespot -n test --device snapcast
vollibrespot v0.1.6-beta f23083b 2019-06-12 (librespot 6e369f0 2019-06-12) -- Built On 2019-07-08
[Vollibrespot] : Failed to register IPv6 receiver: Os { code: 19, kind: Other, message: "No such device" }
[Vollibrespot] : Connecting to AP "gew1-accesspoint-a-l8ps.ap.spotify.com:4070"
[Vollibrespot] : Authenticated as "foreveremain" !
[Vollibrespot] : Using alsa sink
[Vollibrespot] : Metadata pipe established
[Vollibrespot] : Country: "GB"
[Vollibrespot] : SessionActive!
[Vollibrespot] : Loading track "Sexbombe Über Alles" with Spotify URI "spotify:track:74Xcy98SAzj63fZEEK6sxE"
[Vollibrespot] : Track "Sexbombe Über Alles" loaded
[Vollibrespot] : Allowing resampling, and setting period size
[Vollibrespot] : SessionActive!
[Vollibrespot] : Loading track "Sexbombe Über Alles" with Spotify URI "spotify:track:74Xcy98SAzj63fZEEK6sxE"
[Vollibrespot] : Track "Sexbombe Über Alles" loaded
[Vollibrespot] : Allowing resampling, and setting period size

Android snapclient receives the stream at the right speed - so issue is resolved :)

ashthespy commented 5 years ago

Nice, I shall test a little more and then push it to the next version.

ashthespy commented 5 years ago

Rudimentary support has been implemented with https://github.com/ashthespy/librespot/commit/4c81c88c10d3a6993cd6c1c7e19f598d3c57be3f And is baked into v0.1.7 of the daemon. It still needs the LIBRESPOT_RATE_RESAMPLE flag to be set though.