2013-08-31
This post has been updated with new build instructions.
Below you will find instructions on how to build the Preconfigured Airplay speaker (Shairport) image. You may also find a thread about this build in the Raspberry Pi Forums.
The image assumes you’re starting out with the the standard Raspbian install. If you are starting out with Raspbmc as a base, read this additional information when you get stuck.
Note
This tutorial will be run as root. Log in using the pi user and then do:
Standard configuration
apt-get update && apt-get upgrade
raspi-config
Important
Make sure to run expand_rootfs and reboot, otherwise you will run out of free space!
Prequisites
apt-get install build-essential libssl-dev libcrypt-openssl-rsa-perl libao-dev libio-socket-inet6-perl libwww-perl avahi-utils pkg-config git chkconfig libssl-dev libavahi-client-dev libasound2-dev pcregrep pgrep
In case you are having issues with the prequisites, there is som help here:
https://github.com/abrasive/shairport/blob/1.0-dev/README.md
Make sure to update the firmware, this will avoid popping noise when starting the speaker
git clone git://github.com/Hexxeh/rpi-update.git
rpi-update/rpi-update
We need to change the ALSA config slightly, otherwise Shairport will output an error – “Unknown PCM cards.pcm.front”
nano /usr/share/alsa/alsa.conf
Change the line “pcm.front cards.pcm.front” to “pcm.front cards.pcm.default”
Source
We need to fix issues with avahi-daemon, which will return the error “avahi-daemon disabled because there is a .local domain” on many networks:
The solution is to modify the avahi-daemon init.d script.
nano /etc/init.d/avahi-daemon
Find the line starting witH DISABLE_TAG and change the filename to an invalid file, like this:
DISABLE_TAG="/var/run/avahi-daemon/disabled-for-unicast-local-DISABLED"
(Note DISABLED at the end)
Restart avahi-daemon and make sure it is run on boot
service avahi-daemon restart
chkconfig avahi-daemon on
Now we’re going to test the audio:
wget https://snippets.khromov.se/wp-content/uploads/2013/04/piano2.wav
aplay piano2.wav
You should hear audio through your speakers. Audio file credit
Installing Shairport
git clone -b 1.0-dev git://github.com/abrasive/shairport.git
cd shairport
./configure
make
make install
Start it to see if everything is working:
./shairport -a 'Shairport 1'
Volume levels are a bit low, raise the volume with the following command:
alsamixer
Keep it at about 85. (0 or negative gain). Going close to 100 will distort the audio output.
Autostarting Shairport on boot
We can use the included boot script, but we need to fix some issues with the script related to ALSA permissions and install paths.
Use this script, which changes the running user (for ALSA permissions) and removes some faulty install detection:
Download the modified startup script here. (GitHub gist)
Paste the contents of the script above in a new file:
touch /etc/init.d/shairport
Toggle the script on and off again. (We will see why below)
chkconfig shairport on
chkconfig shairport off
Watchdog
Starting shairport on boot turns out to be very tricky – sometimes shairport starts before avahi-daemon, which makes shairport fail.
To fix this we make a tiny watchdog script that makes sure shairport is always running.
Create a new text file named shairport-watchdog.sh in /root:
touch /root/shairport-watchdog.sh
Paste the following:
# find service pids
pgrep shairport
#if we get no pids, service is not running
if [ $? -ne 0 ]
then
service shairport start
echo "shairport started or restarted."
fi
Edit the file /etc/crontab and add the following line:
* * * * * root /bin/sh /root/shairport-watchdog.sh > /dev/null
The script will now check if shaiport is running every minute, and if not start it. This has the added benefit of restarting shairport if it crashes.
If you know of a cleaner way to declare avahi-daemon dependency in the init.d script for shairport, drop me a comment! There is an ongoing thread on Github about that here. Shairport Issues have been removed from GitHub
Some final cleanup:
chown -R pi:pi /home/pi/
And we’re done!
USB Sound Cards
Check out this tutorial, which has instructions for using Shairport with USB sound cards.
Setting up Wifi
Although it’s not provided in the image, it is possible to set it up with conventional means. Link