Most ways to stream music to multiple sets of speakers cost more than it is worth. I don’t think I have to say much about it, you probably wanted to do this in the past but it just seemed stupid to spend that much money on a separate dedicated system.
We are going to exploit the fact that the Raspberry Pi supports AirPlay (through shairport), and combine it with the ‘hack’ that allows the Raspberry Pi to transmit FM signals, turning your raspberry pi into a dedicated AirPlay server and FM transmitter.
Here is the best part, the requirements:
1x Raspberry Pi (any model except Pi 2)
1x Long wire (preferably around 2 feet in length)
1x FM radio (many speaker systems and nice alarm clocks have a built in FM radio).
Step 1: Hook up a wire for an Antenna
Hook up a wire to GPIO 4. This is the fourth pin down on the left side. The wire can be up to 30 inches long.
Step 2: Download PiFM
My assumptions is that you have setup your raspberry pi before. You can either SSH into it, or just do it with a monitor, mouse, and keyboard. For optimal performance from Airplay, I suggest having the Pi hooked up to the network with an Ethernet cord and the Pi not overclocked (this will mess with the FM radio if it is overclocked).
After you login to your raspberry pi, at a terminal window install PiFM:
mkdir pifm cd pifm wget http://www.icrobotoics.co.uk/wiki/images/c/c3/pifm.tar.gz tar -xvf Pifm.tar.gz cd ..
1. Makes a director named pifm
2. Makes the “Current Directory” pifm
3. ‘Gets’ the file at the link provided.
4. Essentially unzips this file.
Step 3: Make a FIFO file
FiFo stands for First-in First-out. This will act as a buffer, we are going to send music to this file, and as the music gets into the file it will be read by the PiFM program we just setup.
sudo mkfifo fmfifo
This will make a fifo file. That’s all for this step.
Side note: For those more familiar, a higher performance option is to make a fifo in a tempfs folder, but this file will get lost after reboot. I would enjoy suggestions to improve this. This isn’t necessary for now though.
Step 4: Install Shairport
Lets install shairport. This allows the Pi to act as a AirPlay Server, and receive music from our AirPlay compatible devices.
First, we need to update our raspberry pi. This will take up to 10 minutes.
sudo apt-get update sudo apt-get upgrade
Lets now install all the necessary files for airplay:
sudo apt-get install git libao-dev libssl-dev libcrypt-openssl-rsa-perl libio-socket-inet6-perl libwww-perl avahi-utils libmodule-build-perl
Let us install a depedency.
git clone https://github.com/njh/perl-net-sdp.git cd perl-net-sdp perl Build.PL sudo ./Build sudo ./Build test sudo ./Build install cd ..
Let’s instal the final files
git clone https://github.com/hendrikw82/shairport.git cd shairport sudo make install cd ..
This will install shairport.
Side note: There are newer versions of shairport, there are a variety of branches. It is hard to choose the best one but this one works, which is all I require. I recommend people taking a peak at shairport-sync if they want to use multiple raspberry Pi’s instead of a central fm transmitting one (you’ll get better audio quality with shairplay sync, but it costs more).
Step 5: Let’s run it!
Lets do the final steps! You may need to have two terminal windows open, one for each command as they tend to ‘take over’ the window.
sudo ./shairport/shairport -a "NameOfServer" -o pipe /fmfifo sudo ./pifm/pifm fmfifo 107.9 96000 2
The first step creates a server, which you can change the name of. The name is what you see when you connect with your compatible device.
The next step sets the frequency. I have it set to 107.9, but use an empty radio station in your area. After you run both steps, tell your iOS device to play music to “NameOfServer” and you should hear the music on the radio station you chose.
Side note: A sample rate of 96000 should work for current devices. If the music sounds too high pitched or too low/slow, you may need to change the sample rate. In this example, I was streaming from my phone on iOS 8. In the past I use to use a sample rate of 44100, but for whatever reason I had to use 96000 this time. If the music sound slow, use a higher number. If it is too fast, use a lower number. Sampling rates are commonly one of the following rates: 96000, 88200, 48000, 44100, and 32000. You’ll probably use 96000 or 44100 for most systems, I think it is an Airplay/iOS version related number.