The Raspberry Pi is a fairly powerful $25 single-board computer targeted toward the educational market, though just because it’s for kids doesn’t mean it’s not fun for adults. I’ve been wanting to buy a Pi for a while now, but couldn’t justify purchasing hardware I have no use for – that is, until I saw this blog post detailing how to use the Pi as an Apple Airplay receiver. This is perfect. Let’s get started turning our little computer into a single-purpose appliance.
The actual board itself is very small. So small, in fact, that I wondered whether I needed to buy a project box to stuff it in. While looking around online at different expensive plastic boxes to put this in, I realized that I have the perfect enclosure for the Pi already in my audio stack.

The Edirol UA-5 usb audio interface
My USB audio interface is made of thick steel and aluminum, and will be plugged in to the Pi anyway (since the Pi uses onboard pulse-width modulation to approximate an audio signal at low quality). Why not put the Pi inside the UA-5? Let’s see if there is room for a Pi.
After removing the thick aluminum cover with a few screws, I see that there looks to be room directly over the digital signal processing side of the board. This is good, because I don’t want to stick a little computer spewing RF noise all over any analogue circuits. Let’s remove the main board.
The board comes right out, and now we’re left with a thick steel case. Let’s cut a hole in it! We need a hole to pass the USB ports, power, and WiFi radio through. I have a feeling this case efficiently blocks and RF signals emanating from inside. At this point I should say that I rushed in to cutting the case without proper tools (I used a drill and some snips). I should have had at least a file to smooth out the rough edges, but I can go back and fix this later.
After cutting a hole in the side of my beautiful equipment, let’s figure out how to fit the Pi in. I’ll screw the main board back in and then cut a piece of the packaging cardboard to make a standoff that will insulate the two boards from each other.
And secure the Pi to it’s new home. I’ve added an 8GB SD card with Raspbian along with an Edimax USB wireless dongle and a microUSB cable for power. This is all secured to the cardboard standoff with zip ties.
Before I screw the lid back on I need to power up the Pi and log in via SSH using the onboard ethernet. After editing my /etc/network/interfaces and adding “auto wlan0″ I just add the proper wpa_supplicant.conf, grab the wlan0 MAC address, add a static DHCP reservation for the Pi on my router, and reboot. Now let’s put the lid on.
It looks pretty good! Let’s log in to our Pi and install Shairport. It’s pretty straightforward.
# Change to our home directory, install all the packages we need. cd ~ apt-get install build-essential libssl-dev libcrypt-openssl-rsa-perl libao-dev libio-socket-inet6-perl libwww-perl avahi-utils pkg-config git emacs git clone https://github.com/albertz/shairport.git cd shairport make # Install Net::SDP Perl module sudo -s perl -MCPAN -e 'install Net::SDP' # Demote the onboard soundcard and allow USB soundcards to become default # Add 'options snd_bcm2835=-2' # Comment out line 'options snd-usb-audio index=-2' emacs /etc/modprobe.d/alsa-base.conf # Copy the example init script cp shairport.init.sample /etc/init.d/shairport # Edit the init script to point to Shairport # NAME=RecordPlayer # DAEMON="/home/pi/shairport/shairport.pl" emacs /etc/init.d/shairport update-rc.d shairport defaults reboot
That’s it! Let’s hook it back in to our amplifier. I’ve connected the UA-5 to the remaining USB port on the Pi.
With everything connected and powered on, we can now select “RecordPlayer” from our iOS or Mac OS devices and stream music to the nicest speakers in the house.
The UA-5 is capable of 96KHz 24-bit playback, but because the Pi is not too powerful, and I suspect that Airplay only transmits 16-bit resolution, I have it set up for 48KHz 16-bit playback.
UPDATE:
I’ve recently encountered an issue with the default Pi ALSA configuration. It seems like the Raspberry Pi developers worked in a direct memory access mode for the onboard sound, and this was giving me some issues while using a USB sound card. Sometimes, but not always, the audio would cut out for about a second every five to ten seconds. With some configuration changes I’ve been able to eliminate this. Also, to be safe I’m now using 41KHz playback. Here’s the /etc/asound.conf:
pcm.!default {
type plug
slave.pcm anticracking
}
pcm.anticracking {
type dmix
ipc_key 1024
ipc_key_add_uid yes
slave {
pcm "hw:0,0"
period_time 0
buffer_time 0
#period_size 1024
#buffer_size 8192
rate 44100
}
}Thanks to [maximeh] for the suggestion.











Pingback: Adding AirPlay to a shelf system
Pingback: Adding AirPlay to a shelf system | Daily IT News on it news..it news..
Pingback: Adding AirPlay to a shelf system | Cool Internet Projects
Pingback: Adding AirPlay to a shelf system | Siecurity.com
Pingback: – Adding AirPlay to a shelf system
Pingback: ใส่ Raspberry Pi ลงในเครื่องเสียงเพื่อเล่น Airplay เลย | Raspberry Pi Thailand
Nice build! The hole on the side could be cleaner, but nobody’s gonna see it and you work with what you’ve got handy, eh?
Overall it’s very nice, and those Pioneer speakers are pretty good – I snagged a pair on sale awhile back and have been quite pleased with them.
I’ve a similar system using MPD, but my core components are a little larger (for the computer side) and smaller (on the DAC side) than yours here, not quite as clean looking for sure.
Fantastic job, sir!
Thanks. The hole will annoy me, and I will eventually buy a file and smooth it out, but you are correct – no one will see it. The speakers really are fantastic, and reasonably priced too! Buying a Raspberry Pi and adding network audio was a direct response to feeling the need to buy “new” music in vinyl format, which can be expensive. Now I can push all the new music I want and be more selective about what I collect. I hope you enjoy your MPD build as much as I’m enjoying this!
Oh, I have. It’s been running for awhile, and I’ve got it set up in multiple rooms, all accessible from iOS/Android.
The only issue is output synchronization – it doesn’t exist on seperate clients, and for multiple outputs from the same client it’s synchronized badly. I don’t know if shairport/airplay works like that in any way but I’m going to be looking into it for sure.
I think synchronization issues will plague network streaming, since there is some level of buffering involved, and there needs to be a type of “heartbeat” in addition to maintain sync. Airplay doesn’t do output to multiple targets, and I think there is good reason. Depending on your network conditions there is a noticeable buffering delay. I’m sure it’s on Apple’s radar for the future.
Great project! Nicely done.
You can send to multiple AirPlay targets via iTunes, I send to multiple AirPort Express’ which sync nicely. It’s a 2 second buffer.
Is the RPi connected to the network via wifi? If so, how’s the audio performance? Because on mine I can’t get through 3 full songs before it starts to fail. If I take the wifi card out and run it over the ethernet cable, everything goes smoothly. I even tried using a powered usb hub but no dice. And I’m only using the board for the AirPlay, nothing else.
Hey Flávio. I’m using the [Edimax EW-7811Un](http://www.edimax.com/en/produce_detail.php?pd_id=347&pl1_id=1..) USB adapter and so far have no issues. It sounds like whatever adapter you are using has poor performance, or a poor antenna design. If you get through three full songs, that tells me that it’s not a throughput issue but a reliability one. I highly recommend the Edimax adapter, and it was about $9 on Amazon.
Thanks for your response, but actually it’s exactly the one I’m using as well. And I have a router right next to it so it’s not a signal problem. And before I got the usb audio interface, everything was running smoothly, except the sound quality wasn’t great. So perhaps is that whole USB “problem” that the RPi has.
But one other thing that I thought about was, could it be due to the quality of my sdcard? Because I believe it’s a class 4, very cheap one.
I would double check your `/etc/asound.conf` and make sure to remove the RPi specific workarounds for the onboard sound (see update above). For me this fixed any strange audio issues I had.
Checked and altered my asound.conf but no dice. Couldn’t get not even 30 seconds of music. Forget about when I said “3 full songs” because clearly that’s not even the case anymore. Later this week I will try with a better sdcard to see if changes anything. Until then I will leave the ethernet cable plugged in.
Thanks for your help!
Just stumbled upon this:
but the settings in the .asoundrc file override the settings in the /etc/asound.conf settings
And It’s possible that I still have this .asoundrc file unaltered. So there’s still hope. haha
Pingback: 在Raspberry Pi上配置AirPlay | Raspberry Pi