wtorek, 14 listopada 2017

Multiroom with Raspberry Pi, Snapcast and Mopidy

I always wanted to have an audio multiroom, which would allow me to play the same music in all rooms, but also provide the ability to control each room separately (on/off, volume, etc.). Obviously, I could buy one of the existing systems like Denon Heos, but then I would need to remove/sell my old audio equipment, which is working perfectly fine. I could also buy Chromecast Audio and create an audio group - but it seemed like a “too easy” solution. Fortunately, one of the presentations from this year code.talks conference gave me the inspiration and direction for building my own multiroom system, based on Raspberry Pi devices.

I started with some requirements:
  • use current audio devices (with line input),
  • Spotify as the main source of music, but not the only one,
  • control everything from an Android device (and desktop app),
  • relatively cheap.

Broadcasting software

After some research and testing, I think that Snapcast is currently the best solution for this use case. Here is why:
  • open source
  • easy setup and configuration
  • Raspberry Pi support
  • Android app as a controller

Music source software

Although you can connect many players to Snapcast, I chose to use Mopidy. Such combination was already tested pretty well by other geeks. Mopidy is also quite new open source software with a vibrant community. It supports not only Spotify but also Soundcloud, Google Play and mp3/flac files. Integration with Snapcast is just a matter of one line in the configuration.

Overall solution

After some struggling, the overall solutions looks like below:
One Raspberry Pi is working as a Snapserver and Snapclient at the same time, with Mopidy service for music management. The other Pi’s are simple clients, that could be added/removed dynamically, they just need to be in the same network.

Problems

Of course, not everything works like in the tutorials. I want to share some of my findings, maybe it can save your time.

Raspberry Pi sound output quality

With Raspberry Pi you usually have 2 audio outputs: HDMI and mini jack. You can easily switch between them thanks to raspi-config, but the jack output has some problems with sound quality. So after installing the Raspbian system, I strongly recommend putting a magic line `audio_pwm_mode=2` to `/boot/config.txt` file. This way you will not waste a lot of time with wondering why audio stream with 48000Hz sampling sounds like music played from a megaphone.

Raspberry Pi time synchronization

If you notice a strange behaviour with losing sound stream on Snapclient devices, this is probably because of time synchronization mechanism on Raspbian system. In my case after Raspberry Pi boot, I was losing the sound stream for about 1 minute, after restarting the device. It’s the `Systemd-timesyncd` service caused it. This problem is a known issue with a few workarounds:
  • don’t reboot Pi too often :),
  • change the time synchronisation service to something else (maybe ntpd) with more gentle time sync mechanism - not tested,
  • turn off time synchronization service.
I used last the option because I don’t care about having accurate time on my devices. 

Troubleshooting

I suppose it is obvious, but in case of any problems check one thing at a time: start with Mopidy, then check Snapserver using only a single wave file as a source and then Snapclients. In most cases, service logs are enough to see what is going on, so don’t forget about the `journalctl` command. 

User interface

As usual with open-source, the biggest problem was with the UI. It must be useful not only for geeks, but for normal human beings as well. At this point I tested 2 mobile apps:
  • Mopidy Mobile
  • MPDroid.
Both are ok, and both have some strange quirks. The problem is they are not the Spotify App, so their conceptions are a little bit different (e.g. handling playlists) and the user experience is not so smooth. But with some patience you will get used to them.

Spotify playlists

If you are a single Spotify user, then everything is straightforward. The problem is when you have  different Spotify accounts than e.g. your wife and you both want to play some of your favourite Spotify playlists. There are a few solutions for that. The easiest - your account could follow playlists from the second one. If you don’t want to pollute your Spotify search history with some crazy music, you could also create a separate account for the multiroom system and follow playlists from both accounts. Probably the only good reason for that is when you have a free slot on Spotify Family subscription. You can also use the multiroom via Mopify web client. Mopify has a very interesting feature. After entering the configuration page anyone can (temporary) synchronize his/her Spotify account with the Mopify session and have access to all Albums, Playlist, etc., without the need of following anything. The user experience on desktop is great, on mobile it’s only ok - probably it will never beat the native app.

Summary

From my perspective, all requirements were met. Maybe except the last one. If I would add my free time for this project, then Chromecast option will be much cheaper. On the other hand, I learned a lot about Raspberry Pi and I have a lot of ideas how to extend the system to provide features completely different than only playing music.

Brak komentarzy:

Publikowanie komentarza