Airplay receiver with Orange Pi. How to make your HiFi sound system wireless.
I’m a big music fan and I like high quality result for small price. This is how this story happened.
First my wife made me an amazing birthday gift: Heco Music Style speakers. I was happy like nobody, but my geeky audioplile mind had an idea how to make life even happier. I wanted to play music with an Airplay / Spotify wireless magic.
Requirements:
- Device that connects to the WiFi and works with an Airplay
- It produce acceptable sound quality
- Budget less then 100 Euro (preferably much less)
Options:
- Ready to use high-quality receiver for 400–800 Euro like Denon DRA or some Yamaha. Cons: Huge and expencive.
- Denon DN-200WS — 100Euro for the professional Airplay receiver, not bad.
- Apple TV for 70 Euro for used 3rd gen. Cons: build in low quality sound and no options to improve it.
- Apple Mac mini 2007 for 55–70 Euro. Pros: there is usb so a lot of external sound cards could be plugged in, native Airplay and Spotify support. Cons: 10 years old, max supported OS is 10.7.5 (currently it’s 5 generations old, modern Spotify OSX client requires 10.9+).
- Raspberry PI for 30Euro + external sound card powered by LibreELEC https://libreelec.tv/downloads_new/
- Orange PI for 13 Euro (official Aliexpress). Same as above but 2.5 times cheaper.
As you can guess I desided to go for the cheapest option.
I also had to find a sound card. There is a list of suitable sound cards for the Raspberry PI and I choose the Creative SoundBlaster Play 2 (I’ve got it by chance for 20 Euro on the eBay)
Summary:
- Orange PI Lite — 13 Euro
- Creative SoundBlaster Play 2 — 20 Euro
- Micro SD U3 card 32GB — 13 Euro
- Power cable USB to 4.0x1.7 — 4 Euro (sic!)
50Euro, not bad! Especially taking into account that I can reuse sound card and SD card.
Orange PI
There is ton of versions of the Orange PI and this is important to keep in mind when you look for the OS for it. I’ve got an Orange PI Lite (see full specs here), mostly this is the same as Raspberry PI 3.
Differences are:
- it has less RAM (512MB vs 1GB)
- it has more powerful CPU (it can play 4k video stream, Raspberry PI plays only 1080p@30fps)
- it has build in WiFi
- is does not have Ethernet
- it needs more power (at least 1.5A, otherwise in my case WiFi didn't work). Works good with an iPad 2.1A power supply.
Summary: huge advantage is build in WiFi, there is no need to spend extra 5–10Euro for WiFi USB donlge.
A lot of usefull information here (Russian)
And now I need a couple of evenings to make this work.
Burn an image to the Micro SD card on the OSX
I tried wrong Raspbian (for Orange PI Zero), correct Raspbian (for Orange PI Lite) and Armbian. Only the last one worked correctly.
- Download an image https://www.armbian.com/orange-pi-lite/
# file name in my case:
# Armbian_5.35_Orangepilite_Ubuntu_xenial_default_3.4.113_desktop.7z
brew install p7zip xz
7za e Armbian_5.35_Orangepilite_*.7z
Then, according to the http://rayhightower.com/blog/2015/11/27/orange-pi-mini-2-setup-for-mac-os-x/
2. Plug in the SD card, find it using discutil list (note the size)
$ diskutil list
...
/dev/disk2 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: FDisk_partition_scheme *31.0 GB disk2
1: Linux 30.7 GB disk2s1
3. Unmount it (take disk name from step 2)
$ diskutil unmountDisk /dev/disk2
Unmount of all volumes on disk2 was successful
4. BURN!!! (note image name and disk name)
sudo dd if=Armbian_5.35_Orangepilite_Ubuntu*.img of=/dev/disk2 bs=1m
5. Eject it gently, be nice.
Orange PI setup
- Connect Orange PI to the internet via USB to Ethernet adapter and wait a bit. Username and password are:
root/1234
You will be asked to change root password and create a non-root user
2. Open the Terminal and let’s make some improvements:
apt-get update
apt-get upgrade# fix locale first
apt-get install --reinstall language-pack-en -y
locale-gen
echo "LC_ALL=C" >> /etc/environment
dpkg-reconfigure locales# enable swap file (disabled by default)
sudo swapoff -a
sudo rm /var/swap# choose location and size for the swap file, say 512Mb on SD card:
sudo dd if=/dev/zero bs=1M count=512 of=/var/swap
sudo chmod 0600 /var/swap
sudo /sbin/mkswap /var/swap
sudo nano /etc/sysctl.conf
# change here vm.swappiness=0 to vm.swappiness=32 and save
There is an option to limit CPU frequency:
h3consumption -m 1000
h3consumption -p#Active settings:
#cpu 1008 mhz allowed, 1200 mhz possible, 4 cores active
Also there are suggestions to use radiator.
3. Then make it accessible via SSH by the hostname (reference: https://jaimyn.com.au/connect-armbian-orange-pi-without-ip/)
Note: in the latest firmware it works by default
# install avahi daemon
apt-get install avahi-daemon# now log try to SSH it on your laptop:
ssh root@orangepilite.local# change `orangepilite` to something else (if you want) in following files:
# /etc/hostname
# /etc/hosts
4. Connect to the WiFi
$ root@orangepilite:~# nmcli dev wifi
SSID MODE CHAN RATE SIGNAL BARS SECURITYMacNetwork Infra 7 54 Mbit/s 67 *** WPA2evdoty Infra 12 54 Mbit/s 50 ** WPA1 WPA2SN_103_3 Infra 11 54 Mbit/s 49 ** WPA2
If you see an empty list here and you sure there is a WiFi, then most probably you have a lack of power (remember I mentioned it needs at least 1.5A).
Sometimes my Orange PI does not enable WiFi without any (obvious for me) reason, in such a case reboot helps.
If reboot does not help, try external USB WiFi dongle and start thinking that Raspberry PI might worth 2.5 times higher price.
In case you see your network here, try to connect:
nmcli device wifi connect "MacNetwork" password "mypassword"
If worked fine for me and there is an option to verify the status:
root@orangepilite:~# nmcli device status
DEVICE TYPE STATE CONNECTION
wlan0 wifi connected MacNetwork
lo loopback unmanaged --
5. Setup Soundcard
Plug in the sound card to the USB, then
# check syslog
tail -f /var/log/syslog
# there will be a message that audio device was connected# add your user to `audio` just in case
sudo adduser root audio# check if your sound card is available
root@orangepilite:~# aplay -l**** List of PLAYBACK Hardware Devices ****
card 0: audiocodec [audiocodec], device 0: SUNXI-CODEC sndcodec-0 []
...
card 1: sndhdmi [sndhdmi], device 0: SUNXI-HDMIAUDIO sndhdmi-0 []
...
card 2: S2 [Sound Blaster Play! 2], device 0: USB Audio [USB Audio]
ok, our device is #2. Let’s set it as a default. edit /etc/asound.conf
defaults.pcm.card 2
defaults.ctl.card 2
Basically, that is enough to make external sound card work as a default. But if you want to have a fine tuning, add following (found on some russian forum)
pcm.!default {
type plug
slave.pcm {
type dmix
ipc_key 1024
slave {
pcm "hw:2"
# rate 48000 # this line is only needed for USB DACs which only support 48khz
period_time 0
period_size 1920
buffer_size 19200
}
}
}ctl.!default {
type hw
card 2
}
then reboot and test
reboot# let's see if it works, you should hear a noisy sound
speaker-test
You can change output volume in alsamixer
alsamixer
# use arrows to change volume and ESC to exit# save settings
alsactl store
6. Install Airplay Daemon
Nice and smart people made a free peace of software that makes devices work as an Airplay receiver. Here it is: https://github.com/mikebrady/shairport-sync
add-apt-repository ppa:dantheperson/shairplay-sync
apt-get update
apt-get upgrade
apt-get install shairport-sync
reboot
Now check music playes or Spotify in your iPhone, in the list of devices you should see orangepilite
If you are lucky one, music should play. But if you are like me, you will be hearing music for a moment once per 5 seconds. That means we have to build shairport from sources (on Orange PI it is surprisingly fast)
Install build dependencies (we will build for ALSA backend, with OpenSSL)
# remove installed version
apt-get remove shairport-syncapt-get install build-essential git xmltoman autoconf automake libtool libdaemon-dev libpopt-dev libconfig-dev libasound2-dev avahi-daemon libavahi-client-dev libssl-devgit clone https://github.com/mikebrady/shairport-sync.git --depth 1cd shairport-sync
autoreconf -i -f
Now let’s configure shairport. I use following build flags:
- with-alsa — use ALSA (Advanced Linux Sound Architecture). Alternative is PulseAudio, but ALSA is closer to the hardware and it’s beeing used in all examples I’ve found.
- with-avahi — use Avahi networking service (software that helps to publish and discover services in local services you use it every time you deal with .local domains)
- with-ssl=openssl — use OpenSSL
- with-systemd — support for Shairport Sync to be launched on boot
- with-metadata — no idea, just found it here
./configure --with-alsa --with-avahi --with-ssl=openssl --with-systemd --with-metadata
If everything is ok, now it’s time to install it. I prefer to use checkinstall for it
checkinstall
You will be asked some random questions and at some point you will see
This package will be built according to these values:0 - Maintainer: [ root@orangepilite ]
1 - Summary: [ AirTunes emulator. Multi-Room with Audio Synchronisation ]
2 - Name: [ shairport-sync ]
3 - Version: [ 3.1.7 ]
4 - Release: [ 1%{?dist} ]
If you see in Release section same creepy value, change it (say to 1)
Enter a number to change any of them or press ENTER to continue: 4Enter new release number:
>> 1
After all you should see
Done. The new package has been installed and saved to
/root/shairport-sync/shairport-sync_3.1.7-1_armhf.deb
You can remove it from your system anytime using:
dpkg -r shairport-sync
That’s why I use checkinstall instead of make install— there is an option remove package with dpkg or apt
Now let’s make the service to start on boot and run it
systemctl enable shairport-sync
service shairport-sync start
7. Install Spotify client (TBD)
Also there is an option to install Spotify client, but I didn't try it yet.
8. Bluetooth receiver(TBD)
apt-get install libglib2.0-dev libbluetooth-dev
https://learn.adafruit.com/install-bluez-on-the-raspberry-pi/installation
wget https://downloads.sourceforge.net/opencore-amr/fdk-aac-0.1.6.tar.gz
tar xzvf v0.1.6.tar.gz && cd fdk-aac-0.1.6/
./configure — prefix=/usr — disable-static
make
checkinstall
That’s it.
Things doesn’t have to be overpriced to be awesome.