Introduction

In this article I will explain how to set up a multi-room audio streaming system based on Apple iDevices, cheap Raspberry Pi players and any computer (either Linux, Windows or Mac). You will be able to do the following:

Send sound from any app on your iPhone or iPad to any speaker in your home. Use your iPhone or iPad to control synchronised multi-room music - without your mobile device needing to stay connected. Play music from your PC/server on your iPhone or iPad.

You will need:

One or more Raspberry Pi computers (in fact you can use any computer but this article covers the Pi). It will also work with an Airport Express or Apple TV.

Powered speakers connected to the Pi's 3.5mm analog stereo jack.

Either an ethernet connection or a wifi adapter that will work with Raspbian such as the Edimax EW-7811UN.

Either a Windows/Mac computer running iTunes, or a Linux computer

An iPhone/iPad with Apple's Remote app.

Diagram

Server Setup

In this reciple, the server is on all the time, and is where you store all your music. The server uses a protocol called DAAP to provide information about your music library (Artists, albums, tracks, cover art etc) to your iDevice, and can be controlled by your iDevice to send music to AirPlay speakers.

If you have a desktop PC or Mac then you can use that as your server, simply by having iTunes open. You need to setup iTunes to share your library and allow it to be controlled by your iPhone following Apple's instructions.

If like me you don't have an always-on iTunes-capable computer (all mine are laptops), then you can use any cheap computer (including a Raspberry Pi) running Linux and DAAP software. I use an HP MicroServer, but a large number of NAS devices will run forked-daapd (the software I will use in this article) and Synology NAS devices come with this functionality in their DSM software.

Installing forked-daapd

There is a large amount of good information about the version I use from the author, so I shall not repeat it. See his instructions for installing and setting up the software on a Raspberry Pi (yes you can use a Pi for the server as well as the AirPlay speakers), but his github project page also has instructions for compiling it from source to use on any Linux distribution.

The README page tells you how to set up your iDevice's Remote app to work with the server.

You will also want to follow the instructions to configure forked-daapd to find your music files. This will invovle editing the /etc/forked-daapd.conf file

AirPlay speaker setup

The recipe here will work with Apple's own AirPort Express and Apple TV devices, as well as any third party AirPlay-compatible speakers you may own. You can also make your own AirPlay speakers using a Raspbery Pi running shairport-sync, as follows:

Install Raspian

Download the latest Raspbian image, and follow Raspberry Pi's own instructions to install it on an SD card. When you first boot up the Pi with a monitor and keyboard connected, you will be prompted to run the raspi-config tool. Run this as instructed (see the guide) to:

Change the hostname of your Pi (e.g. call it "bedroom").

Expand the operating system to use all the available space on the SD card (otherwise you might run out of space).

Change the password for the default user "pi".

Enable SSH (remote access).

Force your audio to analog (you probably don't need to do this).

Update your Pi

Update the Raspberry Pi firmware to the latest version:

sudo rpi-update sudo reboot

After a reboot, update Raspbian:

sudo apt-get update sudo apt-get upgrade

Setup Wifi

If you use a wired connection, you can skip this step.

You will want to set up your USB adapter so that it automatically connects to your home Wifi network.

First, check your hardware is working (drivers for popular adapters are installed in Raspbian by default):

ifconfig

If you see a paragraph about wlan0, your device is available. If not, look online for how to install the drivers.

Edit the /etc/network/interfaces file:

sudo nano /etc/network/interfaces

You want it to look like this:

auto lo iface lo inet loopback auto eth0 iface eth0 inet dhcp auto wlan0 allow-hotplug wlan0 iface wlan0 inet manual wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf wireless-power off iface default inet dhcp

Next edit the wireless config file:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

It should look like this:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="YOUR_NETWORK_NAME" psk="YOUR_PASSWORD" scan_ssid=1 }

Log in via SSH

Once you have networking set up correctly, you can disconnect the keyboard and display and follow the remaining steps by logging into your Raspberry Pi from another computer via SSH. If you have a Pi model A or A+ and are using wifi you will likely have to do this because you only have one USB port - which you will need for your Wifi adapter.

To connect via SSH, follow the Raspberry Pi Foundation's instructions.

Install AirPlay software

The popular shairport software emulates an AirPort Express on Linux, and it is this that receives audio from your iPhone or your server and sends it to your speakers. There are a few versions of shairport, I use a derivative called shairport-sync. it is a bit more responsive - music plays quicker and it responds to volume changes quicker - and will synchronise music playing in different rooms, which is great for multi-room audio. The disadvantage is that, unlike shairport, you will need to compile it from source.

If you prefer to go the easy route with shairport, simply run:

sudo apt-get install libshairport1

To install shairport-sync instead, follow these steps:

1. Install dependencies:

sudo apt-get install autoconf libtool libdaemon-dev libasound2-dev libpopt-dev libconfig-dev sudo apt-get install avahi-daemon libavahi-client-dev sudo apt-get install libssl-dev

2. Download the shairport-sync source:

cd ~ git clone https://github.com/mikebrady/shairport-sync.git

3. Build and install:

cd shairport-sync autoreconf -i -f ./configure --with-alsa --with-avahi --with-ssl=openssl make sudo make install

Configure AirPlay software (optional)

This step tells the software to use the hardware volume control on your Pi's internal sound card instead of the default, a lower quality software volume. It also sets the name that will be shown when you are choosing which speakers to send music to. It is not necessary, but recommended.

Edit the startup script for your Pi. Depending which version you installed above, it will be either:

sudo nano /etc/init.d/shairport

Or:

sudo nano /etc/init.d/shairport-sync

Find the line that looks like this:

start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- -d || return 2

You will want to edit this line so it looks like this:

start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- -d -a "Kitchen" -- -d hw:0 -t hardware -c "PCM" || return 2

Obviously you would replace "Kitchen" with the name you want to use.

Then update your system's init configuration to load the shairport daemon at startup:

sudo update-rc.d shairport-sync defaults

Reboot to finish

From the command line:

sudo reboot

Playing your iPhone's audio on a speaker

Once you have your AirPlay Pi up and running, you can test it by sending some music to it from your iPhone. In iOS 7 and 8, swiping up from the bottom of the screen brings up a dashboard with an "AirPlay" option. Tap it, select your Pi from the list. Sound from any app - such as Music or Podcasts or Spotify or YouTube - will be output on the Pi's speakers instead of the iPhone.

You can see some screenshots of this process on Apple's AirPlay support article. Remember, your Raspberry is emulating an AirPort Express so the process is exactly the same.

Playing music from your server on your speaker(s)

If you have a lot of music, your iPhone probably can't store all of it. You can however use the Remote app to remotely control iTunes (or forked-daapd). You can use this to pipe music stored on your server to your speakers. This means:

The music does not have to be on your iPhone. Music is sent directly from your server to the AirPlay speakers, so music will continue to play if you close the Remote app or turn your iPhone off. You can select multiple speakers at once, to play music in multiple rooms.

Playing music from your server on your iPhone/iPad

If your server is a PC or Mac running iTunes, you can simply enable the Home Sharing function to stream music from your server and play it on your iDevice in the Music app.

Home Sharing replaces an earlier mechanism of doing this, and depends on your Apple ID which unfortunately means cannot be supported by forked-daapd. Therefore if you're using a Linux server you will have to use a different app like Simple DAAP Client.