Saiyato / volumio-snapcast-plugin

Volumio 2 SnapCast plugin, to easily manage SnapCast functionality
115 stars 25 forks source link

Create volumio native spotify settings #4

Closed Saiyato closed 7 years ago

Saiyato commented 7 years ago

Create volumio native spotify settings.

[x] Find out what is needed to pipe output [x] Patch settings files -> sox [x] Fix timeout needed to switch output (file handles?) <- not needed!

Saiyato commented 7 years ago

The timeout for file handles is no longer needed, a new stream will be added instead.

SoX investigation is still needed, documentation is not clear enough to implement.

Saiyato commented 7 years ago

I have been breaking my head on this for some time now. I have no idea how to have SoX output to a specified pipe.

cortegedusage commented 7 years ago

Just to give you my thoughts on this. When looking at spop.conf It does look as if it is using ALSA as output. With the selected output from volumio.

Now for me as a user it would make more Sense to select snapcast output in volumio to enable multiroom output. Now it is my understanding you can create a fifo output in ALSA. If you could make this selecteble From within volumio as default output all the other music services would use this output. I believe someone was doing this with Bluetooth output. https://volumio.org/forum/how-add-more-alsa-sinks-cards-json-t6427.html

Anyway, hope I made myself Clear in this steenkolen english. Goodluck Dennis

kristianwh commented 7 years ago

Hi, I just put this into my /etc/spopd.conf file:

[sox]

output_type = alsa

output_name = hw:1

output_type = raw output_name = /tmp/snapfifo

Just tested, and it works. Not thoroughly tested, though.

kristianwh commented 7 years ago

OK, to correct myself a bit - the playback is quite fast. Might need to tweak some formats to get it right.

man soxformat has a good list for output formats

EDIT: After a bit more research, it seems spop is using sample rate 44100 and not 48000, as was default for snapserver/snapclient. This is hardcoded in spop/src/spotify.c:

static unsigned int g_audio_rate = 44100;

For now, I just changed the sample rate in Volumio, both for volumio and snapserver/snapclient to 44100. This is not configurable in the sox options in spop.

kristianwh commented 7 years ago

Forget my last comment. After some testing, I ended up with this:

[sox] output_type = raw output_name = /tmp/snapfifo effects = rate 48k

Saiyato commented 7 years ago

Oh wow, thanks for investigating! This is highly appreciated, will try to implement it this week. I had come across the raw output, just didn't have the time to test it, this saves me alot of time.

I'll just have to figure out a way to fix the timing problem when using combined playlists. For example:

  1. Spotify song
  2. MPD song
  3. Spotify song etc. etc.

Switching between Spotify and MPD will take some time, I've experienced this with using one fifo for Spotify-Connect and MPD. So I either need to mix the streams or make plugs, in which case I can still use the ALSA output type.

But I will test this first, thanks again.

Saiyato commented 7 years ago

Just did an initial test and it works indeed. The fifo output will accept new streams instantaneously, so no need to reloop the sound. This makes the patch a lot easier.

I will work on a patch for the template, so that saving (with new credentials) will not undo the change.

kristianwh commented 7 years ago

Great. I have experienced some occasional hiccups when playing from different sources. One time I had an internet radio stream playing and then tried to switch to a spotify song, but both kept playing simultaneously to the fifo. Couldn't reproduce it now, though, but it might be a problem.

Saiyato commented 7 years ago

The simultaneous playback problem is likely a problem in Spotify, as opposed to snapcast. I'm not sure how long Spotify in the current form is supported, we might need to look for a new solution soon.

I've implemented an update of the config template for the native Spotify plugin.

NOTE: You need to (re)save your credentials (that way the new template is used) for the changes to take effect.

Saiyato commented 7 years ago

Bummer, I see I forgot to add the effects options, will repatch tonight!

kristianwh commented 7 years ago

Great work :-)

Saiyato commented 7 years ago

Kristian, can you retest maybe? You will need to reinstall the Spotify plugin and update the index.js in the snapcast plugin.

I have added the effects option, I never had deformed playback, so I thought maybe you could test this? :)

I just uploaded a new version

kristianwh commented 7 years ago

Thanks, I'll test it :)

kristianwh commented 7 years ago

I can't really get the /etc/spopd.conf file to get patched. How exactly do I do this? Do I need to install the plugins in a set order? Just reinstalled both snapcast plugin and spotify plugin. Saved my credentials in the spotify plugin, then went to the snapcast plugin configuration, set up everything as I wanted, and clicked save an all corresponding buttons.

Saiyato commented 7 years ago

Hi Kristian,

Since the snapcast plugin is unaware of any previous installations and I don't want it to patch things automatically, the order in which you should best configure is:

  1. Install all needed plugins
  2. Go into the snapcast plugin and select your desired Spotify implementation:

a. Any of the plugins balbuze made b. A standalone Librespot library (you need to either source this or compile it yourself; with pipe backend!) c. The spop (native Volumio 2) variant

image

You can also set the sampling rate here, I couldn't get the channels option to work though with spop, just like bit depth. So I've omitted the channels option.

The bit rate you've set in this section (Spotify integration settings) will be used as of now (the version of last night used the server settings (default = 48kHz); this was wrong).

So in short:

I. Choose your implementation II. Set all quality parameters applicable for your implementation III. Save

  1. You need to re-open the snapcast plugin settings page, this will update the selected implementation.
  2. Patch your implementation template (this patches the template used by that particular plugin):

image

  1. Save the settings in the plugin you've just patched the template for, this will update that configuration and restart any binaries related to that.

image

Also I've re-opened the issue so anyone else can read along. I'll close it when we've confirmed it works.

kristianwh commented 7 years ago

Thanks. Had to reboot volumio to eventually get it to patch correctly. Multiple effects should be possible, but you have to add a semicolon between options, e.g.: effects = rate 48000; channels 2

Things work correctly for me now, except for one thing - I always get output_name = /tmp/spotfifo even if I disabled "Dedicated stream for spotify".

Saiyato commented 7 years ago

Yes, I have to patch this, I only change the template once (I expect ${outdev}), but I think I can "sed" this correctly.

Saiyato commented 7 years ago

Just uploaded a new version, I added the channels. Couldn't get the bit depth working though, not sure if it really changes anything. Anyways, channels should work and you should be able to repatch spop-config.

Changing the Spotify settings will automatically patch the spop.conf and template file, you still need to restart the daemon.

kristianwh commented 7 years ago

Great work! I think you can close this now, if I'm having any other issues, I can just open a new issue :)

Saiyato commented 7 years ago

Awesome, thanks for pointing me in the right direction, this has helped a lot in development.