Create your own radio station with the HiFiBerry DAC+ ADC and Icecast

With the DAC+ ADC you can now sample input from any device that has an analogue audio output: your CD player, a microphone, your keyboard – and many more. One cool thing you can do with it is to build your own web radio. You can use this just at home with mobile phones and PCs connecting to a stream from your Raspberry Pi or even on the Internet.

There are several ways to stream audio over the network:

  • protocols for local audio distribution like Airplay, Roon or the squeezebox protocol
  • protocols designed for commercial installation and studios like AES51 or AVB
  • internet streaming protocols

In this guide, we’ll show how to create an internet streaming server. This is basically the same setup as web radios use.

Advantages

Internet streaming services uses very little bandwidth and work well even on unstable connections. Another advantage is that it will work with basically any web radio on the market, but also devices like PCs, tablets or mobile phones. You don’t need a specific software for it, but only a web browser.

Disadvantages

The major disadvantage is buffering. To make sure short-term interruptions or congestions won’t interrupt the music, the client will buffer quite a lot of music. Therefore there will be a long delay from the audio input to the player (it can be tweaked a bit)

Building the streaming server

Note: This guide comes “as is”. Software versions, configurations, file locations might change in the future. While we try to update the guide, we can’t guarantee that it will work at any time on every system. There is no individual support for this, but feel free to post questions or tips for improvements in our community area. The guide is to be used on Raspbian. For other
systems, you might have to adapt it.

This guide describes every step you should to to install and configure the necessary software.

We have documented every step to make it easier for you to understand what is needed. If you don’t want to copy/paste each step, there is a script that does everything for you in one step. Just copy/paste the following lines to a terminal session on your Raspberry Pi (this will only work on Raspbian!)

U=https://raw.githubusercontent.com/hifiberry\
/hifiberry-tools/master/install-streaming
bash <(curl $U)

Sound card configuration

First you need to configure your system. If you’re using the DAC+ ADC, you might need to update your kernel using the script that we provide.

U=https://raw.githubusercontent.com/hifiberry/\
dacadckernel/master/update-kernel
bash <(curl $U)

Icecast

The main component of the web radio is Icecast. This is an streaming server designed to stream audio and video streams over the Internet. It offers a lot of advanced features, but we’ll use only the basics for this project.

Setting it up is easy:

sudo apt-get -yq install icecast2

To stream audio from the sound card input, you will need an additional software. For Icecast, the easiest way is to use Ices:

sudo apt-get install -yq ices2

Users, logs, …

While you could run this software as the standard user (pi) or even root, it is recommended to use a separate user for this. You also need to create the necessary directories for the log files.

# Create streaming user
sudo useradd icecast -g audio

# Set correct permissions
sudo mkdir -p /var/log/icecast2
sudo mkdir -p /var/log/ices
sudo mkdir -p /var/icecast 

sudo chown -R icecast /var/log/icecast2
sudo chown -R icecast /var/log/ices
sudo chown -R icecast /var/icecast

Configure the services

Icecast and Ices both use XML configuration files. These can be quite complex. Therefore, the easiest way is to use the default files we provide:

# Install config files
cd /etc
sudo mv ices.xml ices.xml.bak
D=https://raw.githubusercontent.com/hifiberry/hifiberry-tools
sudo wget $D/master/conf/ices.conf
sudo mv ices.conf ices.xml
sudo chown icecast ices.xml
cd /etc/icecast2
sudo mv icecast.xml icecast.xml.bak
sudo wget $D/master/conf/icecast.xml
sudo chown icecast icecast.xml

You might have a look at these files. There are passwords configured to administrate the server and add sources to it. The password uses here is “hifiberry”. If your server is reachable from the Internet, you need to change this. Make sure you change the password in both configuration files.

Autostart

Everything is ready now. You could just start Icecast. However, Icecast will not start after a reboot. Therefore, you need to make sure Icecast is started automatically.

# Icecast systemd integration
sudo rm /etc/init.d/icecast2
cat <<EOT | sudo tee /lib/systemd/system/icecast2.service
[Unit]
Description=Icecast2
After=network.target

[Service]
User=icecast
Group=audio
ExecStart=/usr/bin/icecast2 -b -c /etc/icecast2/icecast.xml
PIDFile=/var/icecast/icecast.pid
Type=forking

[Install]
WantedBy=multi-user.target
EOT

sudo systemctl daemon-reload
sudo systemctl enable icecast2

# Ices2 startup
cat <<EOT | sudo tee /lib/systemd/system/ices2.service
[Unit]
Description=Ices2
After=icecast2.service

[Service]
User=icecast
Group=audio
ExecStart=/usr/bin/ices2 /etc/ices.xml

[Install]
WantedBy=multi-user.target
EOT

Start the services

Now let’s test if everything is working.

sudo systemctl start icecast2
sudo systemctl start ices2

Check if the services are running

systemctl status icecast2
systemctl status ices2

Connect to the streaming server

With a PC in your network, just point the web browser to http://ip-address-of-your-raspberry-pi:8000/hifiberry.mp3