Playing your music in every room of your house in sync, wouldn't that be nice? A multi-room audio system makes this possible. No wires are needed, because the music can be distributed via wifi. Just tap on your phone to play your favorite song. There are many whole home audio systems available today, like the well-known audio system Sonos.
I already had audio setups in my living room, kitchen and hobby room. Each setup consisting of a GNU/Linux computer, an amplifier and speakers. But these where stand-alone audio setups that could not play in sync.
Then I discovered Snapcast. With this software in conjunction with the Music Player Daemon (MPD), you can build your own multi-room audio player. In my case there was no need to buy extra hardware. And wow, this is fun! And it works great!
On this page you can read about how I set up my whole home audio system. In case you want to build one yourself, I hope you will find some useful information here.
Note: MPD and Snapcast (Snapserver and Snapclient) can run on Windows too, but this project is only about MPD and Snapcast on GNU/Linux.
Server
All my music is stored on my server. This computer is running 24/7. See also my NAS project. You can use any GNU/Linux computer to serve your music. I will refer to this computer as the server.
MPD
The music on the server is played by the Music Player Daemon (MPD). MPD sends the audio to the Snapserver. In the default configuration of MPD, the audio is sent to the internal sound card. We will use this for testing.
Snapserver
The Snapserver streams the audio from MPD to the different Snapclients over the home network (LAN). At the same time it assures that the clients are synchronized, so that the audio is played in sync.
Snapclient
The music you hear comes from the Snapclients. I use these clients on my Linux Mint desktop computers (in different rooms) and on my laptop. The Snapclient runs in the background and just plays all the audio that the Snapserver is streaming.
MPD client
With the MPD client you can control what music is playing. Just browse the MPD music library and choose what you want to hear. Listen to a single track, a playlist, an album or your complete music collection. There are several MPD clients that run on your computer (GNU/Linux, Windows 10 and macOS) or on your smartphone.
Snapweb
Snapweb lets you control the volume of each Snapclient. In other words: with Snapweb you can control the audio levels in the different rooms of your home. It is a web-app so it runs on all devices with an internet browser.
Home network (LAN)
The music is streamed over the home network or Local Area Network (LAN). The home network is also used for the communication between the different clients and servers mentioned above. So every device of your multi-room audio system must be connected to the home network, either with a network cable or via wifi.
The easiest way to install the Music Player Daemon (MPD) is by using your package manager. But it is also possible to build MPD from source. Check the MPD website for instructions. Install MPD on the server.
How to configure MPD (works on Debian 10)
The location and name of the MPD configuration file is /etc/mpd.conf. Only change the information below. You need to be root to do this.
...
# Files and directories
music_directory "/your/music/directory"
...
# Comment out the next line to solve client connection problem
# bind_to_address "localhost"
...
# Set output of MPD to input of Snapserver
audio_output {
type "fifo"
name "my pipe"
path "/tmp/snapfifo"
format "44100:16:2"
mixer_type "software"
}
# Test audio output
audio_output {
type "alsa"
name "My ALSA Device"
device "hw:0,0" # I had to change this to "hw:1,0"
}
...
After saving, restart MPD on the command line as root. On Debian-based systems type:
# systemctl restart mpd.service
Now it is time to test if MPD is working. You can use any MPD client for testing. Below you find some tests, using the command line client MPC. MPC only runs on GNU/Linux.
How to test MPD with MPC
Run the tests below as a regular user. The output as it should be, is shown under each command.
Test if you can connect to MPD:
$ mpc -h <server-name>
volume:100% repeat: off random: off single: off consume: off
Update the MPD music database:
$ mpc -h <server-name> update
Updating DB (#1) ...
volume:100% repeat: off random: off single: off consume: off
Add all your music to the MPD queue:
$ mpc -h <server-name> add /
Now you can play your music. To test this, connect speakers or a headphone to the sound output of the server. Then type:
There are several MPD clients. You can find an overview of MPD clients on the MPD website. To connect to MPD you need to configure the name of the server where MPD is running. How that is done, depends on which MPD client you use.
There are MPD clients for your computer: GNU/Linux, Windows 10 and macOS but also for smart phones: Android, iOS and Ubuntu Touch.
Examples
On my GNU/Linux computers I use mpdevil and the command line programm ncmpcpp. See the screen shots below (click to enlarge).
If you have an Android phone you can use M.A.L.P. to control your multi-room audio player. You can install this apps from Google Play or even better: from the free software "app store" F-Droid. If you have problems with M.A.L.P. showing your album art, check out the section about M.A.L.P. and album covers.
I use uMPD on my Ubuntu Touch phone. If you like free software, take a look at Ubuntu Touch, a free operating system for smart phones.
I installed the Snapclient on my Linux Mint computers using the package manager. The Snapclient was started automatically by systemd during boot. But I got no sound. I tried several outputs, using the -s option, with no result. Running the Snapclient as a regular user, worked for me.
How to auto start Snapclient as regular user (works on Mint 20)
M.A.L.P. can show the album cover of the album that is playing. It uses MusicBrainz or Last.fm to fetch the album art. But M.A.L.P. can also show the album art from your own collection.
How to show your own album art with M.A.L.P.
Your music collection including your album art must be available via a web server (how to do this is outside the scope of this web page).
In the M.A.L.P. Profiles settings, enable: Prefer HTTP cover files.
And enter the cover path like this:
http://<web-server>/<music-dir>/%d/<album-cover>
If you do not specify the name of the album covers, M.A.L.P. wil search for files with name: cover, Cover, folder and Folder, with extension: jpg, JPG, jpeg, JPEG, png and PNG.
Problem with encoded slashes
The %d part of the URLs that M.A.L.P. uses to fetch the album covers, contain encoded slashes (this means / is encoded as %2F). In my web server setup encoded slashes were not supported and my album art was not found. To solve this problem, I added the following to the VirtualHost configuration of Apache:
With one of my computers I use a Scarlett USB audio interface. Everything seemed okay. But when I opened the audio mixer, the music was suddenly slowed down.
This problem was solved by changing the sample format from 48000:16:2 (the Snapserver default) to 44100:16:2. This sample format must be configured for MPD and the Snapsever.