GNU/Linux

Martin's
GNU/Linux Projects

To Home Page

Multi-room audio player with MPD and Snapcast

Last modifications: 14 June 2024

Trouble shooting:

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 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.

mpdevil
mpdevil on GNU/Linux
MPDroid
M.A.L.P. on Android

uMPD
uMPD on Ubuntu Touch
mpdevil
ncmpcpp on GNU/Linux

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.

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.

MIDI controller

Did you know that you can control anything on your computer using a MIDI controller? I use one to control my multi-room audio player.

See also my project: Control (almost) anything using a MIDI controller.

M.A.L.P. and album covers

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:

AllowEncodedSlashes On

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.