Quantcast
Channel: CodeSection,代码区,Linux操作系统:Ubuntu_Centos_Debian - CodeSec
Viewing all articles
Browse latest Browse all 11063

Apple Airplay on Raspberry Pi in 7 Easy Steps

$
0
0

Apple Airplay on Raspberry Pi in 7 Easy Steps

Do you have an existing hifi system that’s too old to support Apple Airplay? Don’t want to replace it with lower-quality wireless speakers, but want to stream music? It’s a common problem. The good news is, for the cost of a Raspberry Pi you can build an Airplay server so you can stream music directly from an iPhone or iPad to your hifi system.

This guide shows you how to set up Shairport-sync so you’ll have a Raspberry Pi playing music in 7 easy steps.

Before You Start

Before you can set up a Raspberry Pi as an Airplay server there are a few things you’ll need.

Choosing a Raspberry Pi

You may have one lying around already. Most models should work, but the Pi Zero will be a problem because it’s harder to set up a network on the Zero. I suggest googling to find out how to do that before you start. If you have a Zero W model then things will be easier, and the single-core CPU in there works pretty well for streaming so long as you don’t have anything other heavy-duty stuff running.

If you’re buying new, I’d suggest a Model 3. I used a Model 3 A+ with no problems, because I wanted a smaller form factor, wifi and enough grunt. The Model B will work equally well.

NEEGO Raspberry Pi 3 Ultimate Starter Kit Complete Set Includes Raspberry Pi 3 Model B Motherboard, 7” Touchscreen Display, Power Supply, 16GB SD Card, 2 Heatsinks, Official Case & 6ft HDMI Cable

Choosing an Operating System

The first thing you’ll need is an SD card with an appropriate operating system. These days there are a lot of different options, from “traditional” Raspbian to dedicated media operating systems, and even windows 10 IoT.

Now, an Airplay server is not like Kodi which requires a rich graphical interface. It’s absolutely possible to run it with no UI at all, since all of the user interaction will be done on the iOS or macOS device. It might be nice to have some kind of display showing the current artist and track information, but that’s very much a stretch goal. For now, concentrate on getting the server working!

So with that established you should be looking towards a more barebones system. There’s no need for lots of applications, and for glitch-free operation you want as few processes running as possible. This is to leave as much CPU and RAM as you can for the media streaming application.

One problem is that some of the barebones OSes, such as Arch linux, are are aimed at people with quite a lot of Linux knowledge. They’re quite cutting edge and you’re more likely to run into issues when installing third party applications and libraries.

At the other end of the spectrum there are some distributions which are dedicated to this task, and should work out of the box, but you won’t learn anything from that.

For those reasons, if this is your first installation of an Airplay device, I recommend choosing Raspbian Lite. It is mature because it’s derived from the original Raspbian OS, but it has had the GUI removed to save resources. It’s entirely command-line driven, and can easily configured to run in “headless” mode, i.e. accessed entirely remotely over the network with no need for a keyboard or monitor. This makes it ideal for putting into an appliance, and hopefully you’ll learn something in the process.

Install Raspbian Lite and Enable SSH

If you already have an installation, or are confident in doing that part yourself, go ahead.

Otherwise follow my tutorial below, which takes you step-by-step from a raw Rapsberry Pi to SSH-enabled Raspbian Lite:-

How To Set Up a Raspberry Pi You Can Control From Anywhere in 30 Minutes

Once you’re set up, you should be able to login to the Rapsberry Pi remotely from another computer on your network, and your Pi should have internet access.

Configure the Airplay Server 1. Install Dependencies

First off, you’ll need to install some dependencies so you can build the Airplay server application. Run the following:-

sudo apt-get update sudo apt-get install autoconf automake avahi-daemon build-essential git libasound2-dev libavahi-client-dev libconfig-dev libdaemon-dev libpopt-dev libssl-dev libtool xmltoman 2. Build & Install shairport-sync

shairport-sync is a fantastic piece of software maintained by Mike Brady . It turns your Linux machine into an Apple Airplay server. One of the best things about it is that it runs entirely on the command line, and while it has a million configuration options, it’s surprisingly easy to get working out of the box.

First grab it from github:-

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

Now navigate to the shairport-sync directory and configure the build:-

cd shairport-sync autoreconf -i -f ./configure --with-alsa --with-avahi --with-ssl=openssl --with-systemd --with-metadata

Finally build and install the application:-

make sudo make install

At the end of this procedure you should have a working installation of shairport-sync .

3. Configure the Audio Output

You’re now ready to test the Airplay audio. First you’ll need some hardware. Any of the following will work:-

headphones, or just about any old earbuds with a 3mm jack active speakers from a desktop PC or if you’re serious, a hi-fi amp with a cable that converts 3.5mm jack to a pair of RCA phono plugs

Now you need to configure the audio path on the Raspberry Pi. It’s generally set to “auto” but you need to force it to go to the 3.5mm jack. Run raspi-config :-

sudo raspi-config

Select “7. Advanced Options”, then “A4. Audio”, then choose Option 1 “Force 3.5mm (‘headphone’) jack”. This will force the audio path to the 3.5mm headphone jack.

4. Set the Volume

The volume can tend to be very low, so change it to max using:-

amixer sset PCM,0 100%

The volume setting is a bit difficult to use because it’s configured in dB (decibels), which if you’re not an engineer are very unintuitive. In decibels, full volume is generally 0dB, and zero volume is around -100dB. But and apart from the negated scale, this is the main brain-twister the decibel scale is not linear.

So when you use the % notation with the amixer command above, you might think it works like a normal volume control but it does not. If you want the volume a touch later you might perfectly reasonably change it to 80%:-

amixer sset PCM,0 80%

You’ll see the output reports this as around -17dB, but crucially you’ll notice it’s barely audible. The percentage is directly converted to decibels, with the upshot that you can only really hear anything below around 70%.

So, TLDR: keep the volume set to 100%.

5. Test Airplay to the Raspberry Pi

Now start shairport-sync with:-

sudo service shairport-sync start Nothing’s going to happen until you start Airplaying to it, so grab an iPhone or something that supports Airplay, and ensure it’s on the same network

Viewing all articles
Browse latest Browse all 11063

Trending Articles