GNU/Linux

Martin's
GNU/Linux Projects

To Home Page

Multi-room audio player with MPD and Snapcast

Last modifications: 31 August 2021

Introduction

Snapcast

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.

My setup

Below you see a schematic picture of my setup.

Multi-room audio player with MPD and Snapcast

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.

MPD

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:

$ mpc -h <server-name> play
16 Horsepower - Wayfaring Stranger
[playing] #3/4219   0:00/4:27 (0%)

In the multi-room setup you do not need the sound output of the server. So the MPD output that points to the sound card, can be disabled:

$ mpc -h <server-name> disable "My ALSA Device"
Output 1 (my pipe) is enabled
Output 2 (My ALSA Device) is disabled

MPD clients

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. See the screen shot below (click to enlarge).

mpdevil
mpdevil on GNU/Linux

If you have an Android phone you can use for example MPDroid to control your multi-room audio player. See the screen shot below (click to enlarge). You can install it from Google Play or even better from the free software "app store" F-Droid.

I use uMPD on my Ubuntu Touch phone. See the screen shot below (click to enlarge). If you like free software, take a look at Ubuntu Touch, a free operating system for smart phones.

MPDroid
MPDroid on Android
    
uMPD
uMPD on Ubuntu Touch

Snapserver

Debian 10 comes with an old version of the Snapserver, that does not support Snapweb. So I installed the latest version from the Snapcast website.

Install the Snapserver on the server.

How to configure Snapserver

You can configure the Snapserver (from version 0.19.0) in three different ways:

  1. Options on the command line
  2. Command line options in the file /etc/default/snapserver
  3. Configuration file /etc/snapserver.conf

Settings in the configuration file can be overwritten on the command line with:

# snapserver --<section>.<name>=<value>

For example:

# snapserver --stream.sampleformat=44100:16:2

Take a look at the configuration file for the available options. Show the command line options with:

# snapserver --help

I had to change the default value of the sample format to solve a problem with my USB audio interface. See Scartlett audio interface.

The Snapserver did not start automatically. So I borrowed the systemd unit file from the Debian repository.

How to auto start Snapserver with systemd (works on Debian 10)

  • Download the unit file for the Snapserver.
  • Place this file on the server in the directory /lib/systemd/system.
  • Execute the following commands as root.

    Reload, so systemd finds the new unit file for the Snapserver:

    # systemctl daemon-reload
    

    Check the status of the Snapserver:

    # systemctl status snapserver.service
    

    If the new unit is somehow "masked", unmask it first:

    # systemctl unmask snapserver.service
    

    Enable the unit so that the Snapserver will start during boot:

    # systemctl enable snapserver.service
    

    You can start or restart the Snapserver with:

    # systemctl start snapserver.service
    # systemctl restart snapserver.service
    

    Check if the Snapserver is running:

    # systemctl status snapserver.service
    

Snapclient

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)

  • Execute the following commands as root:
    # systemctl stop snapclient.service
    # systemctl disable snapclient.service
    
  • Use the auto start feature of your desktop to automatically start the Snapclient after boot. Just use the command snapclient without any options.

In my case no further configuration was needed. Note that the Snapclient does not even need a server name. It finds the Snapserver by itself.

If you need to adjust some configuration settings, read the how-to below.

How to configure Snapclient

You can configure the Snapclient in two different ways:

  1. Options on the command line
  2. Command line options in the file /etc/default/snapclient

Show the command line options with:

$ snapclient --help

Snapweb

Snapweb

To use Snapweb, open an internet browser and go to:

  • http://<server-name>:1780

On the right you see a screen shot of how it looks like (click to enlarge).

Snapdroid

There is also an Android app Snapdroid with the same functionality.

Note: In my case the app can only connect to the Snapserver when I provide the IP4 address of the server in stead of the server name.

Scarlett audio interface

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.

And there is more...

In my setup I use MPD in combination with the Snapserver. But you can feed the Snapserver with other audio sources as well, like Spotify and AirPlay.

Read more on the Snapcast website.