moode-player / moode

moOde sources and configs
GNU General Public License v3.0
990 stars 165 forks source link

Feature Request: Multiroom audio #110

Closed aphilpott closed 4 years ago

aphilpott commented 4 years ago

It would be great if Moode supported playing the same music on multiple players in different rooms.

I think using https://github.com/badaix/snapcast would be the best way to achieve this.

I've got a basic prototype of this working on my two Moode players. At the moment my prototype only works for Spotify, and it required me to SSH onto my players to install an start the required software. It would be great if it was part of the Moode image and could be enabled through the config menu in the web UI.

If there's interest in this feature I'd be up for implementing it.

moodeaudio commented 4 years ago

I've looked at SnapCast b4 and never had the time to get into it. There is another approach that I think might be more reliable and simpler to implement. It's a GStreamer based system that Charlie Laub developed. it's based on ALSA loopback and thus eliminates the need for MPD FIFO pipe or for pipes from other audio applications like shairport-sync, Librespot, Bluetooth, etc.

http://audio.claub.net/GSASysCon.html

https://www.diyaudio.com/forums/pc-based/293266-bash-script-based-streaming-audio-system-client-controller-gstreamer.html

Check it out and let me know what you think.

aphilpott commented 4 years ago

I've had a brief look into this. My initial impression is that Snapcast requires less setup than Gstreamer/GSASyscon would (see next reply for more detail). But before we decide which is the best option, I think we need to pin down what we're actually trying to achieve here.

I think the key requirements are:

There's an interesting question about how we control which rooms audio is playing in. We'd probably want something in the Moode UI, but there are some interesting interactions with some of the players, for example:

One other thing which I don't think is a must-have for an initial version of multiroom audio is the ability to have multiple different groups of players in use simultaneously (e.g. one thing playing in both kitchen and dining room, and something else playing in both living room and bedroom).

@moodeaudio any comments on the above thinking?

aphilpott commented 4 years ago

I've written up some details on what I know about Snapcast and GSASysCon, and what's involved in setting them up:

Snapcast

In my prototype, I got Snapcast up and running in about 30 mins. Snapcast consists of two packages, snapserver and snapclient, and I just had to:

There's no config to write for the clients. The snapserver automatically detects all of the snapclients on the same LAN (which also makes adding additional Moodes to your network really convenient). There's an android app which you can use to tell the server to just stream to a subset of the clients.

In my prototype, I had my snapserver set up to use librespot as its audio source. But according to the docs, you can quite easily configure ALSA to redirect all audio to snapserver, which would allow us to make this work for all players, not just Spotify, without setting up a separate pipe for each player.

As well as the android app, there's also a JSON RPC API which might make it possible to control which players audio is streamed to from the Moode UI.

GSASysCon

I haven't actually tried getting GSASysCon up and running yet, but it seems to require more effort to set up, for example:

I think the above two points mean the Moode code required to get GSASysCon working would be more complex than for Snapcast. We'd have to generate the required config file, and set up passwordless SSH. Making it so that new Moodes can be seamlessly added to the network would probably be a but fiddly, whereas this Just Works with Snapcast. I'm not sure how changing the set of players that are playing in sync would work - I think we'd have to generate a config file for the set of clients we wanted to include, and then rerun the GSASysCon shell script.

Conclusion

Overall Snapcast seems simpler, so my recommendation would be to go with that. @moodeaudio what do you think?

moodeaudio commented 4 years ago

Interesting. If the docs indicate that SnapCast can be fed from alsaloop then it reduces the complexity.

In the Snap world does the Pi running MPD also play in sync with the remote clients?

aphilpott commented 4 years ago

Looked into this a bit further.

It's not quite true that SnapCast can be fed from alsaloop - it's actually that it's possible to configure ALSA to route all of the sound output of the system into SnapCast's pipe (see the ALSA section of https://github.com/badaix/snapcast/blob/master/doc/player_setup.md). We probably don't want to do that, because of the issue I raised above about interfering with the multiroom features of some players such as Airplay.

To answer your question about whether the Pi running MPD also plays in sync with the remote clients, you can set it up either so that:

aphilpott commented 4 years ago

I think we should only implement multiroom for MPD and Spotify, because I think these are the only players on Moode that don't already support multiroom playback:

I think a nice user experience would be:

@moodeaudio what do you think of this proposal?

moodeaudio commented 4 years ago

I think these multi-room systems for example LMS/Squeeze or iTunes/Airplay are mutually exclusive to one another and would be mutually exclusive to MPD/Snap.

I can envision MPD/Snap multi-room with a nice UI for controlling things which by the way would not be trivial to develop. It would definitely take a significant effort.

The part that I'm not too sure of though is using Snap to do multi-room for the audio renderers since they take over from MPD when a client connects and they overlay the UI because the UI is only for controlling MPD. The other concern is that since SnapCast doesn't support alsaloop things get complex with regard to configuring the renderers to dump their audio data into a fifo pipe.

aphilpott commented 4 years ago

Yes, I agree about mutual exclusivity of the other multi-room systems and MPD/Snap.

Agree that it would take significant effort to develop a UI for doing MPD+Snap, so we probably don't want to do that unless we're really sure Snap is the way to go.

The part I'm most interested in adding is Snap for the Spotify renderer, because I mainly listen to music through Spotify. You make a good point that this wouldn't be controllable through the UI, but I think that's OK. The way my prototype works is:

I think adding Snap/Spotify would be a good way of trying out Snap without doing as much development work as MPD/Snap would require. If it went well, we could then think about MPD/Snap.

The other thing to mention is that you don't have to set up librespot to play into the Snap fifo pipe. You just say that you want to use librespot in /etc/snapserver.conf and it starts an instance of librespot which is set up to play into the fifo.

mgafner commented 4 years ago

I made a similar prototype / hack for my home. I have a snapcast server & librespot on my homeassistant raspberry pi. In every room i have a raspberry pi with Moode, on which i installed the snapcast clients. Then i changed this files:

pi@moode-room1:/var/local/www/commandw $ grep snap * spotevent.sh: /bin/systemctl stop snapclient spotevent.sh: /bin/systemctl start snapclient spspost.sh:/bin/systemctl start snapclient spspre.sh:/bin/systemctl stop snapclient

so, if i use librespot in a single room, it stops the snapclient and play only this room. In any other case, it casts the sound of my central snapcast server. I am using the snapcast android app to control the volumes.

i would be happy to see snapcast integrated in Moode ;-)

moodeaudio commented 4 years ago

I don't have the bandwidth but maybe another developer thats interested and motivated will take on the challenge of integrating this into moOde.

tjengbudi commented 10 months ago

hello, @moodeaudio i want try to implement snapcast into moode. however cause of my lack information about moode i want to ask something. for my test i used snapcast server in moode. and client in my android and it works. i used loopback for source for snapcast server.

however there is some delay cause in moode that have snapserver, the sound is not from snapclient and used loopback so... can i cut the tie of alsaloopback to snapcast server. and the sound get from snapchat client? so the device used as snapcast server and snapcast client

can this works in moode?