Elektroda.com
Elektroda.com
X
Elektroda.com

How to run Apple Airplay on a Raspberry Pi in seven easy steps

ghost666 9186 2
This content has been translated flag-pl » flag-en View the original version here.
  • How to run Apple Airplay on a Raspberry Pi in seven easy steps
    Do you have audio equipment that is too old to support Apple Airplay that you want to use? You don't want to replace it with lower-quality wireless speakers, but want to listen to music from the Internet? This is a common problem. The good news is that solving this problem costs as much as the Raspberry Pi - not much. Based on this minicomputer, a simple Airplay server can be set up, which will allow us to directly transfer music from our iPhone or iPad to an older audio system.

    In the following tutorial, we will describe how to set up a Shairport-sunc server on a Raspberry Pi in seven easy steps

    Before you start

    Before we start configuring and programming the hardware itself, there are a few things we need to consider.

    Choosing the right 'Raspberry' model

    Perhaps some Raspberry Pi is already at home, then there is no problem with choosing. Most models should work in the application described below, but it can be problematic, for example, Pi Zero, due to the fact that it is more difficult to configure network connections there. Before we start setting up our Raspberry Pi Zero, it's a good idea to read more about it on the internet. The Pi Zero W model will no longer have such problems. The single-core processor found in the Zero models is quite good at dealing with the audio stream, at least as long as you don't tell it to do anything else.

    If we want to buy a new raspberry, it is best to use Model 3 The author used the Raspberry Pi 3 A + in his design, because he wanted to reduce the size of the system and the built-in interface, but the 3B model will work equally well.

    Choice of operating system

    The first thing you will need is an SD card with an image of the operating system on the Raspberry Pi. Currently, the choice is much wider than it used to be - from the traditional Raspbian through dedicated operating systems for multimedia devices to Windows 10 in the version for Internet of Things systems.

    The Airplay server is not like Kodi, which will require a screen to showcase its rich graphical interface. Basically, this device can work completely headless, with no user interface, as all settings are made from the iOS or macOS client device. It is practical to have a display of some sort to show the data of the track being played - author and title - but this is in no way required for the operation of the system.

    With these requirements, we can see that we should look for a rather minimalist operating system that does not introduce a lot of additions, because in order to guarantee the stable operation of the Airplay server without jams, it is good to minimize the number of processes currently running on 'Raspberry' - this will leave enough RAM as well as free computing power for the server.

    The problem with these types of simplified systems (such as. Arch Linux), however, is that they require a lot of knowledge from the user. They are advanced and fast, but there is also a good chance that when trying to install some applications or libraries on them ...

    At the other end of the spectrum, operating systems are so optimized for new users that we learn absolutely nothing about the architecture and use of that operating system by using them.

    We can read more about operating systems for the Raspberry Pi in this forum topic .

    Due to the above, the author decided to use Raspbian in the Lite version. On the one hand, it is a mature, advanced operating system based on the traditional Raspbian OS, but it has been simplified - the GUI was abandoned so that it could work on weaker machines. It is easy to configure (despite working only with a text terminal) or to maintain, thanks to the possibility of headless system management via, for example, SSH. Thanks to this, the machine will not need a keyboard or a mouse, only a network connection, which is needed for the Airplay server to work anyway. This makes Raspbian Lite perfect for use in the application below.

    Installing Raspbian Lite and starting SSH

    If you already have a Raspberry Pi with an installed system, or if you know how to do it, you can skip the first step - installing the operating system on your computer. If you need to start by installing the OS, you can follow the steps below this guide .

    After installing the operating system and starting the Raspberry Pi, we can use Raspi-config to connect to the computer with SSH help. This way we can run the Raspberry Pi fully headless and configure it conveniently remotely from our own computer.

    Airplay server configuration

    1. Dependency installation

    First, we need to install the dependencies that the application itself will require. In the terminal, first update the system, and then install the latest versions of individual libraries:

    Code: bash
    Log in, to see the code


    2. Build and install shairport-sync /

    This software, written and maintained by Mik Brady, is a very interesting package that turns a Linux machine into an Apple Aurplay server. It works directly from the command line and despite many configuration options, it is very easy to run.

    First, we clone the repository from github:

    Code: bash
    Log in, to see the code


    Then we enter the shaairport-sync folder and configure the application build:

    Code: bash
    Log in, to see the code


    Finally, we can build and install the application:

    Code: bash
    Log in, to see the code


    After this step, we already have a working installation of our application - the Airport server - on our 'Raspberry'.

    3. Configure the audio output.

    We can now configure the server to play the sound the way we want. First, we need a suitable output:

    * Any headphones with a 3.5mm jack.
    * Active speakers with a cable with a 3.5 mm jack.
    * Cable with a 3.5mm jack on one side and two RCA plugs on the other to connect the RPi to your Hi-Fi equipment.

    In raspi-config, we have to set the sound to be redirected to the 3.5 mm output - by default, the 'auto' option is selected, which is too imprecise for us. In the command line, enter:

    Code: bash
    Log in, to see the code


    Then we choose "7. Advanced Options ", and" A4. Audio ", select option number 1" Force 3.5mm ('headphone' ;) jack ". This will force the audio output to the headphone jack.

    4. Volume setting.

    The volume should be immediately set to 100% and adjusted in further elements of the audio path, e.g. the amplifier. To set the volume to 100% in the Raspberry Pi, enter in the command line:

    Code: bash
    Log in, to see the code


    It is not so easy to understand exactly how the volume control works, as it is given in decibels, which for a layman may be at least unintentional. On the decibel scale, 0 dB corresponds to the maximum loudness. The lowest level is around -100 dB. Unfortunately, this is not the most complicated part of the decibel scale - it is also non-linear, which means that the volume percentages do not work as we think ... If we just want to turn the output down a little and set it to, let's assume 80%:



    Code: bash
    Log in, to see the code


    It is the system that will actually set the volume to - 17 dB, but we won't hear anything or the sound will be extremely quiet. The percentages are linear to decibels, so we can't adjust them linearly. Below 70% we won't hear anything anymore. The sound is twice as quiet at 97%, so let's leave the volume at 100% without going into it and adjust it elsewhere, where it is a bit more intuitive.

    5. Let's test Airplay on a Raspberry Pi.

    Let's start by running shairport-sync:

    Code: bash
    Log in, to see the code


    Now the server is up and we can connect to it. Until we do this, we won't hear anything. So let's use an iPhone or another compatible device that supports Airplay now and connect to our server. After choosing the option to connect to the player, choose raspberrypi and click "Done".

    How to run Apple Airplay on a Raspberry Pi in seven easy steps
    Choosing a Raspberry Pi as the Airplay player on the iPhone.


    If you don't hear anything initially, turn up the volume on your phone, as the audio output on the Raspberry Pi is not particularly loud. At this point, we should already hear something.

    6. Configure shairport-sync to automatically start with the system.

    We want our dedicated player to be always ready and to be able to accept connections to the Airplay server immediately after starting the computer. Therefore, we need to add the shairport-sync service to be automatically started by the Pi system as soon as it loads. Fortunately, we have configured the server to work with systemd. This means that we can configure this service to start automatically on system startup. Just type in the command line:

    Code: bash
    Log in, to see the code


    You should then see this type of information:

    Code: bash
    Log in, to see the code


    which will confirm that we have successfully added the Airplay server to the (persistent) services launched at system startup. Now we can safely reset the computer:

    Code: bash
    Log in, to see the code


    Now, after logging in via SSH, to check if shairport-sync is running, we can type:

    Code: bash
    Log in, to see the code


    If everything works fine, it should result in the following system response:

    Code: bash
    Log in, to see the code


    Now, every time we start the Raspberry Pi, the Airplay server will be automatically started.

    7. Preventing the loss of Wi-Fi network.

    The Raspberry Pi has a tendency to lose its Wi-Fi connection as it periodically switches to power saving mode. In our system, we want to avoid it, so that the system runs smoothly and without problems. To do this, we need to add an extra line in the configuration file / etc / network / interfaces. enter in the command line:

    Code: bash
    Log in, to see the code


    And to the file we add:

    Code:
    # Disable wifi power management
    
    wireless-power off


    After that we can reset the system:

    Code: bash
    Log in, to see the code


    Now our Airplay server should run without any problems. However, if we encounter any problems, please see the troubleshooting guide below.

    If we do not see our device - raspberrypi - in the list of Airplay devices, first we need to check if the service is running. We do this by typing in the command line:

    Code: bash
    Log in, to see the code


    If the service is running, and we still don't see the server, we need to check if our device is on the same LAN network, and preferably the same Wi-Fi network, as the Airplay server. Of course, both devices must be within the range of the wireless network.

    If you are connected to the server and you cannot hear anything, make sure that you have set the volume level appropriately high everywhere. On the source device it is good to set the sound to 80..90%, on the Raspberry Pi the sound should be set to max (100%). In RPi, we can check the volume level by entering in the command line:

    Code: bash
    Log in, to see the code


    The command will return the current settings to us in the form of:

    Code:
    Mono: Playback 400 [100%] [4.00dB] [on]


    If it's set to anything below 70% (-27dB), we'll most likely hear absolutely nothing. Therefore, it is best to set the volume level to 100% here.

    Of course, you should also check the configuration of our audio equipment connected to the Raspberry Pi.

    Notes on sound quality

    Many people may notice poor sound quality from the Raspberry Pi's built-in audio jack. Dedicated digital-to-analog converter (DAC) modules connected to the I?S interface can be used to improve the sound. There are many such chips on the market. The author tried two types of DAC. The first was the IQAudIO PiDAC +, which has the perfect shape to match the new Pi 3 A + model. He also used a HiFiBerry DAC + Zero on a Pi Zero W. Both modules are incredibly simple to set up and sound great.

    Another very popular alternative, which the author has not tested yet, is the Pimoroni pHAT DAC converter.

    There are no serious benchmarks available, but switching from the built-in audio output to a dedicated DAC will give a huge improvement in sound quality.

    Source: https://appcodelabs.com/7-easy-steps-to-apple-airplay-on-raspberry-pi

    Cool? Ranking DIY
    Can you write similar article? Send message to me and you will get SD card 64GB.
    About Author
    ghost666
    Translator, editor
    Offline 
    ghost666 wrote 11292 posts with rating 9531, helped 157 times. Live in city Warszawa. Been with us since 2003 year.
  • #2
    RafalB

    Level 28  
    I prefer 1 step ... I download Volumio :)
  • #3
    nici
    Moderator Chiptuning
    Exactly. Volumio works without any configuration. Is HDMI or analog. No problem in minutes.