Copyright 2009-2020 by djg. All Rights Reserved.

Wonky Gibbon Ramblings



Raspberry Pi Does Sonos – Part 2 – Transmitting on AirPlay 2

Posted on December 30, 2013 by danny

In the first part, I talked a bit about setting up the Raspberry Pi as an AirPlay receiver; something that can receive audio streamed over a home’s wifi connection and play it.

Transmitting from Apple

Apple Devices already support AirPlay by default (not a shock – it’s an Apple invention). So to connect an ipad, iphone, itouch etc… is straightforward. You simply double swipe up in IOS7 and enable AirPlay in the control panel. Job done.

Transmitting from Windows

Windows can be made to talk to the Pi using a program called Tuneblade. This is an application (that if you’re streaming to Shairport as described in Part 1, is free) and can be downloaded from http://tuneblade.com/.

Once launched, Tuneblade can be accessed from your system tray and includes a volume control, so remember to turn it up! It streams the audio even if you mute the local audio output – which is handy if you don’t want to listen to your tiny PC speakers.

Transmitting from Android

On Android, some app’s (such as Streambels) support direct streaming to AirPlay – but many popular apps do not, for example, Spotify does not. Similarly, TuneIn the radio app doesn’t. So another solution is required, similar to that used on Apple devices. ie: redirect the entire audio stream of the device.

There are a number of Apps for Android that will stream the entire sound output of the phone to the Pi. For example, one called AirAudio and another called AirStream. Both of these have demonstration versions to allow you to test. However you will have to buy a licence for around £4 to get a permanent solution (ie: one that doesn’t switch itself off after 10 mins). I didn’t find a totally free alternative (and I’m not anti paying software developers in any case!!).

Whilst apps like Streambels that only stream their own audio channel don’t need root privileges, these other applications that give the greater flexibility of sending any audio on the device (such as that coming out of Spotify) by effectively snooping on other applications audio output – do require root access / super user privileges.

This gets you into the exciting area of device rooting. The process for this can be complicated and in many cases results in the device being wiped as one of the steps to do it. This was certainly the case for the house Nexus 7 though happily not my Motorola Atrix phone. Doing so, however gets this solution to work. In addition it also provides access to a variety of other very useful apps including backup tools that can backup application data as well as the install apk’s and much more. Rooting an android device is not for the feint hearted and comes with associated risks of bricking the device and invalidating your warranty. So something you do, at your own risk.

Transmitting to Multiple Zones

By setting up multiple Raspberry Pi’s around the house with different device names you can effectively zone the house into different audio areas. In addition many of these transmitting programs can broadcast to more than one AirPlay receiver at once. In our house, with our network setup, solely using Raspberry Pi’s, they seem somehow to sycnhronise which is very cool for parties!!!

Raspberry Pi Does Sonos – Part 1 – Making an AirPlay Receiver 0

Posted on December 30, 2013 by danny

Overview

So … I want Sonos. I want the ability to be able to select tunes from Spotify, my NAS drive, the radio, whatever – on a tablet and have it come out of my hifi without the tablet physically attached to it.

I could use Bluetooth. But the range is poor and the sound quality questionable.

But what if a Raspberry Pi could do the same thing? What if it could receive audio streamed over Wifi, from a tablet, or my phone, or a laptop etc?… turns out it can.

Apple’s AirPlay protocol is usually used by iTunes to allow it to communicate with Apple TV and is the backbone of the project. However as luck would have it, going beyond Apple and iTunes it is possible for other devices to use Airplay including a variety of Android apps and a few windows apps. There is also a linux project, shairport that allows linux devices to receive Airplay streams and play them.

This is the point I have to fess up and say that I should have written up the Raspberry Pi part of this as I was doing it – but hey ho, it’ a month later so this will lack detail but at least give a general overview.

The challenge with the Pi is simple enough: Get it running headless with shairport (which provides the audio listening service and outputs the audio through the Pi’s 3.5mm jack) running as a service from startup. And in fact, using the raspbian distribution this is relatively easy. However there were some issues: First, I quickly discovered that the Edimax micro USB wifi adapter I had, didn’t have the range to reach my router through a couple of walls. So I swapped it for a Ralink wifi usb adapter with a proper stick aerial I had lying around – but could I get the drivers to work? Could I hell!! Additionally, even without this problem and without launching a GUI, raspbian isn’t that quick to boot and I like quick booting!

For that reason I decided to do it again, using ArchLinux. ArchLinux boots fast and I knew from a previous project that the Ralink wifi adapter could be made to work.

Steps to Setup the Pi

So the steps to success on the Pi

  1. Install Archlinux
  2. Get Wifi Working
  3. Get a build environment working
  4. Download shairport package
  5. Compile
  6. Configure to get it working

To Install ArchLinux you can download an sd card image from here. And then bring the packages up to date using the instructions here. The most important section is that about updating the system. Don’t worry about installing additional software or a desktop environment.

Next – get the wifi working.
This page provides a guide to setting up wifi on ArchLinux. Personally I found the wpa_supplicant approach a real arse – in fact I didn’t get it working. By comparison the automatic Netctl approach mentioned, is very straightforward.

Now that the wifi is working, check that it can get a wifi signal from wherever in the house you tend to position the Pi. If you can’t and you’re using a micro adapter, you may need to change to an adapter with a larger / proper aerial.

Next, some development tools are required. The first command below installs gcc, make etc… the second provides support for git, which is where the shairport source repository is stored.

# sudo pacman -Sy base-devel
# sudo pacman git

My own efforts from this point got a certain distance, including a lot of mucking around with perl packages and cpan, but I was unable to unravel is completely. However, this blog post by Orson Tyrell – works extremely well.

At the end of this, you should have shairport installed and set to automatically startup at system boot.

You may well find that when you send a test signal it is very quiet.

If so, launch

# alsamixer

Set the volume to 100% or close and exit.
If you then call

# alsactl store

(you may need to use sudo) then this volume will be stored away and reused after a reboot.

In Part 2 – I’ll talk a bit about broadcasting to the Pi from other devices.

There were quite a lot of pages used in doing this, but the key ones were:
http://orsontyrell.blogspot.co.uk/2013/11/airplay-to-arch-linux-raspberry-pi-via.html
http://engineer.john-whittington.co.uk/2013/05/airpi-diy-airplay-speakers-using-shairport-and-a-raspberry-pi-updated/
And on raspbian
http://trouch.com/2012/08/03/airpi-airplay-audio-with-raspberry/
https://github.com/abrasive/shairport
… thanks to all.



↑ Top