[Guide] Multiroom audio output from Volumio with SnapCast

Greetings all Volumio fans!

I’ve been looking for a solution to play music through Volumio simultaneously on my living room and bedroom. After spending hours to get PulseAudio setup working without success, I bumbed into a GitHub project called SnapCast (github.com/badaix/snapcast) and I decided to give it a try. I was amazed how easy it was to setup working, and even more amazing is how well the audio sync works with it! Being so excited to get this working so nicely, I want to share my guide for all who’s interested to try it out.

I must state that I have nothing to do with the development of this awesome SnapCast software, so all the appreciation belongs to developer badaix and all the other contributors. And of course, let’s not forget the developers of Volumio :slight_smile:

Here’s my hardware setup:

“Server”

  • Raspberry Pi model 2B + Hifiberry Digi+
  • Connected to wireless router via Ethernet cable
  • Audio output through stereo amplifier via Toslink
  • Running Volumio 1.55
  • Music library at NAS in local network
  • Located at living room

“Client”

  • Raspberry Pi model 2B + Asus N10 Nano USB WiFi adapter
  • Connected to wireless router via WiFi
  • Audio output currently through Raspberry Pi’s (crappy) 3.5mm jack (the plan is to replace it with a proper DAC).
  • Running Raspbian Wheezy
  • Located at bedroom

Setting up the ”Server”

  • Install Volumio: volumio.org/get-started/
  • Setup the Volumio through WebUI
  • Open up SSH connection
  • Get the needed packages from repository:

sudo apt-get update sudo apt-get install build-essential unzip sudo apt-get install libboost-dev libboost-system-dev libboost-program-options-dev libasound2-dev libvorbis-dev libflac-dev alsa-utils libavahi-client-dev avahi-daemon

  • When asked during install, opt to keep the existing config files
  • Get SnapCast source code, unzip it and compile:

wget https://github.com/badaix/snapcast/archive/master.zip unzip master.zip cd snapcast-master make all

  • Install both snapserver and snapclient:

sudo make installserver sudo make installclient

  • snapserver and snapclient are installed as service, so they will be automatically started during boot
  • Open up /etc/mpd.conf for editing:
sudo nano /etc/mpd.conf
  • Comment out your current audio output (this is important!) and add a new audio output for SnapCast:

[code]#audio_output {

type “alsa”

name “Output”

device “hw:0,0”

dop “no”

#}

audio_output {
type “fifo”
name “my pipe”
path “/tmp/snapfifo”
format “44100:16:2”
mixer_type “software”
} [/code]

  • NOTE! Remember that if you change the Volumio’s Playback settings through WebUI, these modifications will be overwritten and you have to do the modifications to /etc/mpd.conf again.

Setting up the ”Client”

sudo apt-get update sudo apt-get install libboost-dev libboost-system-dev libboost-program-options-dev libasound2-dev libvorbis-dev libflac-dev alsa-utils libavahi-client-dev avahi-daemon

  • Get SnapCast source code, unzip it and compile:

wget https://github.com/badaix/snapcast/archive/master.zip unzip master.zip cd snapcast-master make all

  • Install snapclient only:
sudo make installclient
  • Restart the services:
sudo /etc/init.d/snapserver restart
sudo /etc/init.d/snapclient restart
sudo /etc/init.d/mpd restart
  • Plug in your amplifier/speakers/headphones to both of the Raspberry Pi’s, browse to Volumio WebUI with your computer/tablet/phone, put some tunes playing and you should be able to hear the both outputs playing nicely in sync. :sunglasses:

I’ve been testing my setup in a same room by playing “Server” output from the speakers connected to stereo amplifier, while listening the “Client” output from headphones. Sync is great - I really can’t notice any audible delay between the outputs. And what’s best, it works even though the “Client” is connected via Wifi, so I can move it around the house - just a power socket is needed. My next step is to get a proper DAC and active speakers for the “Client”.

It would be nice to hear if someoby else is trying this kind of setup too. If it seems to be working well enough, maybe this can be somehow implemented in Volumio - that should be pretty simple? :slight_smile:

snapcast is an Awesome Find! (man I love github!)

Every now and again I’ll notice a slight artifact but both are wireless, so I suppose that’s to be expected. Your guide worked great, but there’s one correction you need to make.

in the first code block it is missing the install command, it should be sudo apt-get install build-essential unzip

Also I will add that you might need to restart the services the first time through. This order worked for me:

sudo /etc/init.d/snapserver restart sudo /etc/init.d/snapclient restart sudo /etc/init.d/mpd restart
Other than that it’s been great! And worked the first time!
Thanks for sharing the guide!

Thanks for the corrections, danstinebaugh - I added them to the guide. Nice to hear that you got it working too! :sunglasses: I’ve noticed some small occasional glitches in the playback too, but fortunately they are not too disturbing. Like you said, it’s probably due to some latency spikes in the wireless.

I managed to get a Terratec Aureon Dual USB sound card working with my client RasPi, so now I have decent outputs (optical and analog) in that on too. Just needed to modify /etc/modprobe.d/alsa-base.conf and /boot/cmdline.txt according to these instructions: elinux.org/RPi_VerifiedPeriphera … ound_Cards

Hello,

is it possible to use volumio on the client pi as well? so that i could either use the stream or use the volumio interface seperatily?

best regards

p

Hi,

I’ve just setup snapcast which seems to be working, with the odd drop from the client, which is a RP1,

I was wondering if it’s possible to route the audio on the client through a DAC? as the sound from the 3.5mm jack isn’t that great. :frowning:

1 Like

You can choose the soundcard with the -s or --soundcard parameter. You can either configure the index or a substring of the name of the soundcard.
In my setup I have for example one raspberry with a Behringer UCA202 and on another raspberry I have a HifiBerry DAC+ connected.
You can list the soundcards with snapclient -l. The Behringer system gives:

[code]0: null
Discard all samples (playback) or generate zero samples (capture)

1: default:CARD=ALSA
bcm2835 ALSA, bcm2835 ALSA
Default Audio Device

2: sysdefault:CARD=ALSA
bcm2835 ALSA, bcm2835 ALSA
Default Audio Device

3: default:CARD=CODEC
USB Audio CODEC, USB Audio
Default Audio Device

4: sysdefault:CARD=CODEC
USB Audio CODEC, USB Audio
Default Audio Device
…[/code]
Device #4 is the Behringer DAC. So I have added -s 4 in the service file (/lib/systemd/system/snapclient.service):

[code][Unit]
Description=Snapcast client
After=network.target

[Service]
Type=forking
ExecStart=/usr/sbin/snapclient -d -s 4
PIDFile=/var/run/snapclient.pid

[Install]
WantedBy=multi-user.target[/code]
The raspberry with the HifiBerry is working out of the box (using this setup: https://www.hifiberry.com/guides/configuring-linux-3-18-x/), because the devices are as follows:

[code]0: null
Discard all samples (playback) or generate zero samples (capture)

1: sysdefault:CARD=sndrpihifiberry
snd_rpi_hifiberry_dacplus,
Default Audio Device

2: dmix:CARD=sndrpihifiberry,DEV=0
snd_rpi_hifiberry_dacplus,
Direct sample mixing device[/code]
snapclient will use device #1, because default is a substring of sysdefault

Suppose the Pi Server also acts as a Spotify Connect device (Fornoth), is it possible to stream this with snapcast to the Client?

At the moment I’m building up a snapcast system consisting of 3 Raspberry PI2. Every PI is running Volumio 1.55 and spotify connect. One PI is setup as snapcast server&client, the others are configured as snapcast client only. The client only systems can be switched between multiroom and standalone mode. In multiroom mode snapclient is started and running , in standalone mode snapclient is stopped and mpd or spotify connect is active.

Unfortunately I have no skills to implement a button within Volumio’s front end. I need some help to integrate a button | MRM | into the header menu of the web interface to schedule a bash script for toggling between multiroom and standalone mode.

Is there someone who can help to advise how to set it up?

Can somebody please help me here?

The third step is not working propably :confused:

volumio@volumio:~$ sudo apt-get install libboost-dev libboost-system-dev libboost-program-options-dev libasound2-dev libvorbis-dev libflac-dev alsa-utils libavahi-client-dev avahi-daemon Reading package lists... Done Building dependency tree Reading state information... Done libasound2-dev is already the newest version. libboost-dev is already the newest version. libboost-program-options-dev is already the newest version. libboost-system-dev is already the newest version. libvorbis-dev is already the newest version. You might want to run 'apt-get -f install' to correct these: The following packages have unmet dependencies: alsa-utils : Depends: kmod (>= 17-1~) but 9-3 is to be installed libavahi-client-dev : Depends: libavahi-client3 (= 0.6.31-5) but 0.6.31-2 is to be installed Depends: libavahi-common-dev but it is not going to be installed Depends: libdbus-1-dev (>= 0.60) but it is not going to be installed libboost-dev : Depends: libboost1.55-dev but it is not going to be installed libboost-program-options1.55-dev : Depends: libboost1.55-dev (= 1.55.0+dfsg-3) but it is not going to be installed libboost-system1.55-dev : Depends: libboost1.55-dev (= 1.55.0+dfsg-3) but it is not going to be installed libflac-dev : Depends: libflac8 (= 1.3.0-3) but 1.3.0-2 is to be installed E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

the guide is a little bit outdated. It should work to simply install the prebuild deb package
https://github.com/badaix/snapcast#install-debian-packages.
If you want to compile and install from source, you can follow this guide:
https://github.com/badaix/snapcast/blob/master/doc/build.md#linux-native

will this work with volumio 2 ?

How do you do this? Is it possible to change it via the Interface? I am currently trying to build a setup, where volumio is running on 3 PI accessable seperately, with the option to switch two of them into a multiroom mode, streaming from the other PI…

did someone test this on volumio2?
is there any roadmap to build this in?

I had a quick go with this earlier using the standard deb from Github, and I can report it works with Volumio 2 (2.03). I was getting a lot of dropouts on the RPi 2 server, but I haven’t had chance to investigate this any further.

I have this working with Volumio2. Works reliably. I have one client on a Raspberry PI 2 in one room. In the other I have a Raspberry Pi 3 with both a HIFIBerry DAC+ and a USB DAC. The Raspberry Pi 3 has Volumio (which outputs to the HIFIberry DAC+ when I just want to listen in that room with Volumio2 volume control, Snapserver and Snapclient to the USB DAC.

The only issue right now is that when I playing Spotify through the Volumio2 Spotify plug-in I get no sound through snapcast. That is odd since I can hear Spotify just fine through the HIFIBerry DAC+ at the same time I am not getting it through Snapcast. NAS sound file and Web radio does not have that problem. Those play just fine through the setup.

I am unclear what is different about the Spotify plug-in’s connection points to MPD etc. vs. NAS and Web radio.

Looking at the config files in the Spotify plug-in directories, it appears that the Spotify plug-in does not output to MPD. Instead it uses spop. So that explains why the Spotify plug-in is not outputing through snapserver. I will need to re-configure spop to output to the /tmp/snapfifo file that snapserver reads from in order to use the Spotify Volumio plugin with snapserver.

A possible path is to change /etc/ mpd.conf to setup output to an alsa audio device named “default” and then add an /etc/asound.conf file with the settings for it to output to /tmp/snapfifo. The example of how to do that is in the link that shows how to connect mpd. alsa etc to snapserver. Then specify in the spop.conf file that SOX outputs to an alsa device to the default. The idea is that Volumio for both NAS and Webradio output to alsa, as does the Volumio Spotify plug-in. Alsa then outputs to /tmp/snapfifo.

I thought this combination of config files would route both the Volumio2 MPD output and the Spotify plug-in output to alsa. Then alsa would output to /tmp/snapfifo. Snapserver would then intake from /tmp/snapfifo like it usually does. Alas it did not work.

/etc/mpd.conf


[code]# Audio Output ################################################################

audio_output {
type “alsa”
name “alsa”
device “default”
}

#audio_output {

type “alsa”

name “alsa”

device “hw:1,0”

dop “yes”

mixer_device “hw:1”

mixer_control “Digital”

mixer_type “hardware”

#}

#audio_output {

type “fifo”

enabled “yes”

name “multiroom”

path “/tmp/snapfifo”

[/code]

/etc/asound.conf


pcm.!default {
    type plug
    slave.pcm rate48000Hz
}

pcm.rate48000Hz {
    type rate
    slave {
        pcm writeFile # Direct to the plugin which will write to a file
        format S16_LE
        rate 48000
    }
}

pcm.writeFile {
    type file
    slave.pcm null
    file "/tmp/snapfifo"
    format "raw"
}

/etc/spopd.conf


[spop]
spotify_username = note: real username not shown
spotify_password = note: real username not shown


high_bitrate = true
audio_output = sox
pretty_json = true
search_results = 50
cache_path =/run/shm

[sox]
output_type = alsa
output_name = alsa

I have Volumio 2.041 running with Snapcast on Raspberry Pi 3. I had dropout issues, but changing the audio_output format to 48000 in the mpd.conf file on the server fixed it. I am running the November 2016 Raspian version (Jesse lite) on the client. Still using the default audio (3.5 mm jack) on both the server and client until I got everything working, so now I need to buy some DACs.

Interested in this myself. My unaltered mpd.conf has:

[code]audio_output {
type “fifo”
enabled “no”
name “multiroom”
path “/tmp/snapfifo”
format “44100:16:2”
}

[/code]

So you changed:

format          "44100:16:2"

to

format "48000" ?

Obviously, I need to change “enabled” too. Just asking before trying :slight_smile:

Almost. I changed the 44100 number to 48000 and left the remaining part on. Evidently leaving it at 44100 was causing the Pi to transcode audio before sending it causing the dropouts. So my line looks like this:

format “48000:16:2”

Don’t forget to restart your mpd daemon so it rereads the mpd.conf file.
Good luck.