Home » Home Server » Icecast Ices2 music server for Raspberry Pi: Raspberry Pi streaming audio server

Icecast Ices2 music server for Raspberry Pi: Raspberry Pi streaming audio server

Icecast creates audio streams on various platforms. Allowing for us to use the Raspberry Pi. It installs and runs smoothly on Raspbian Lite with a headless server setup for efficiency, but any flavor of Raspbian will do. Using Raspian Lite together with Icecast you can stream audio from any directory or list of directories you supply to the server in an XML file. You can use other software alongside Icecast to control various aspects of the audio stream. Alsa is one of the most popular and commonly used third-party software used with many audio servers, including Icecast.

With Alsa you can:

  • Play streams from a source application like Ices
  • Control your sound settings with the command line
  • Mix audio with software mixing in a text-based UI

Streaming during playback will not lag because of lack of available hardware resources used by other applications, because Icecast is not running in a GUI in this way.

Raspbian for running Icecast

If you upgrade your hardware from a Pi in the future, Raspbian is a distro built from Debian. It almost is Debian. Anything you learn to do in Raspbian can be done again on a standard PC in Debian or Ubuntu server distributions.

The Pi gives you the opportunity to make mistakes for under $40. You won’t cry over the money you spent if it breaks making mistakes you could be making on a full HTPC server. A Raspberry Pi is a micro-computer. That means smaller than a mini-computer. It is the smallest PC device you can buy and build yourself.

3 Best Standalone Bittorrent Downloaders

  1. WD My Cloud 4TB Personal Cloud Storage - NAS
  2. Buffalo LinkStation 210 2 TB NAS Personal Cloud Storage and Media Server
  3. Synology America DiskStation 2-Bay Diskless Network Attached Storage

Requirements for Icecast

This tutorial makes some basic assumptions about your knowledge and experience with Raspberry Pi.

  • Raspbian Lite is installed on an SD card
  • You have already built the hardware for the Pi
  • Raspbery Pi is connected to the home network and Internet
  • You know how to enter commands on the command line

If not, please refer to the excellent Raspberry Pi help documentation available on their organization’s website.

It is better to avoid having to prefix every command with sudo I recommend switching to superuser using sudo.

sudo su

To do this, login with your user password, which by default is “raspberry” for user pi.

Once on the command line, it is good to always first run updates and upgrade your system.

apt-get update
apt-get dist-upgrade

Preparing the Pi for Icecast

Most of the process of installing any kind of server is preparing the system. We need to make sure that our installation of Raspbian Lite is ready to make use of the hardware to produce quality sound. Many audio servers run with the complete Alsa set of repository packages.

apt-get install libogg-dev libvorbis-dev libshout-dev \
libxml2 libasound2 libasound2-doc \
alsa-utils alsa-oss alsamixergui

Add user pi to audio group for Alsa

Create a group called audio and make user pi part of the audio group to give Alsa the same permissions as pi. If you prefer, create another user for Icecast.

groupadd audio
usermod -aG audio pi
Adding the user pi to the audio group on Raspbian Lite - Icecast Ices2 music server for Raspberry Pi
Adding user pi to audio group

List your sound devices

The term “sound card” and “sound device” can be used interchangeably setting up your devices. To see a list of your sound capture devices use arecord.

arecord -l

The Pi shows none until you create one with PCM, which stands for Pulse Code Modulation. PCM manipulates audio inside the computer. We will use it to create modules to connect Alsa drivers to sound devices. The sound device to connect will be the onboard sound system of the Pi as the “sound card.”

Alsa asound.conf and .asoundrc XML files

This configuration can be setup globally by creating asound.conf.

nano /etc/asound.conf

The configuration locally for pi (or other user) can be stored in a file called asoundrc. Although you can create a global configuration file to configure your settings, the conventional setup utilizes a user profile.

nano /home/pi/.asoundrc
Creating an asoundrc file for Alsa on Raspbian - Icecast Ices2 music server for Raspberry Pi
Creating an asoundrc file

Paste the following into the new asound.conf or asoundrc file with the clipboard.

pcm.!default {
type hw card 1
}
ctl.!default {
type hw card 1
}
Creating PCM sound devices with Alsa on Raspbian - Icecast Ices2 music server for Raspberry Pi
Creating PCM sound devices with Alsa

Using the CTRL + “O” + Enter + “X” keys in sequence overwrites the empty asound.conf file and exit.

Alsa allows you to configure your settings both globally and locally. Configuration files for Alsa are used to set preferences for the software mixing capabilities of Alsa. To say the global settings are inherited might not prove to be true of all hardware and configurations. It is easily possible to create settings that are shared with two files instead of inherited.

Undoubtedly, there is much more you can do with these files than any one tutorial or guide can tell. Especially, if you add databases and other software that uses Alsa and PCM, it is easy to run into all kinds of tweaks, improvements, and crazy implementations of the Icecast server. Once you are happy with your settings in XML, reboot for your changes to take effect.

reboot

Test Alsa for Icecast

Now test Alsa!

speaker-test -c2

You should hear white noise from both speakers when you run the test command.

Streaming mp3 with mpg123 on Icecast

To test mp3 streaming from an online source install mpg123 to play mp3 files.

apt-get install mpg123

Run mpg123 command to stream SomaFM.com.

mpg123 http://ice1.somafm.com/u80s-128-mp3

Icecast and PCM devices

Commands to play other accessible sound devices can be configured with PCM to turn a crude command into a clean, neat one. PCM makes these commands easier to remember and use.

aplay --device=hw:1,0 /usr/share/sounds/alsa/Front_Center.wav

Because we have to know the hardware type and number with this silly command, we have to remember each device by a number. This might eventually become a challenge. It even looks much better to use a name you create for your device with PCM.

aplay -D primary /usr/share/sounds/alsa/Front_Center.wav

As you add more sound devices, continue by running the command again each time to list the new devices.

aplay -l

Adding PCM names to hardware devices is simply done by running the command to find the device’s hardware type, and giving each device a name with PCM.

arecord -l

Testing a device connected on the command line is done by going back into the terminal.

speaker-test -c2 -D plughw:1,0

Using the “PCM hw type” allows you to define aliases for sound devices and cards. In addition, you may configure a compatible USB sound capture device. Like many great audio drivers and software, Alsa’s world exists on the command line. You will find many recipes for improving and expanding Alsa-based capabilities.

PCM code block template

This is the complete template with syntax to add a device.

pcm.NAME {
type hw
card INT/STR # the card is identified by an integer or a string
[device] INT # Assign the device a number for PCM (default 0)
[subdevice] INT # Default -1 so it uses first available device
mmap_emulation BOOL # Enables mmap emulation for ro/wo devices
}

It is okay to assign any pcm.NAME value. The purpose is to be able to run the commands for sound devices without using a lot of technical information. Using our code block template, we can add a code block for each sound device.

pcm.NAME {
type hw
card 0
device 0
}

If you change pcm.NAME to pcm.primary, this will let you run Alsa play with this command.

aplay -D primary /usr/share/sounds/alsa/Front_Center.wav

You are no longer referring to the hardware type in your command as before by being able to refer to the new pcm.NAME.

aplay --device=hw:1,0 /usr/share/sounds/alsa/Front_Center.wav

Live audio streaming on Icecast

If you would like to utilize a microphone, turn your Raspberry Pi’s headphone jack into a microphone jack. A default distribution software package called jackd and jackd2 are available for most Linux distributions. To determine which package you want to use, refer to the Jack FAQ to explain the difference.

jackd

Enter the command to install jackd in the terminal.

apt-get install jackd

For all the settings, visit AlsaProject.org – Asoundrc.

The instructions on that page go into detail how to add a plugin. The project itself hosts its own collection. To add any of these plugins, use the snip of code that follows.

ALSA project – the C library reference

Add the plugin code block to the asound.conf or asoundrc file, however your setup is configured. Remember that the asound.conf file is for global configuration and asoundrc file is local (meaning running as the user pi in this case.)

PCM code block for jackd

Add the plugin for jackd to your PCM file.

pcm.jackplug {
type plug
slave { pcm "jack" }
}

pcm.jack {
type jack
playback_ports {
0 alsa_pcm:playback_1
1 alsa_pcm:playback_2
}
capture_ports {
0 alsa_pcm:capture_1
1 alsa_pcm:capture_2
}
}

Now it is possible to play and record files with commands using the jackd software package.

aplay -Djackplug somefile
arecord -Djackplug somefile

The plugins to consider adding as part of this setup are used for various software-mixing configurations. Copy and paste the plugin code into the appropriate file. If you do not want to use the plugin as the default sound device, change pcm.!default to whatever pcm.NAME you prefer.

dmix

This is the native Alsa plugin for direct software mixing to use in place of another server application. Software mixing is the process of sending more than one audio stream to the same device. You stream from one or more source to a single destination, to create a mix.

pcm.!default {
type plug
slave.pcm "dmixer"
}
pcm.dmixer {
type dmix
ipc_key 1024
slave {
pcm "hw:1,0"
period_time 0
period_size 1024
buffer_size 4096
rate 44100
}
bindings {
0 0
1 1
}
}

ctl.dmixer {
type hw
card 0
}

dsnoop

For multiple inputs, we can use a plugin called dsnoop.

pcm.mixin {
type dsnoop
ipc_key 5978293 # must be unique for all dmix plugins
ipc_key_add_uid yes
slave {
pcm "hw:0,0"
channels 2
period_size 1024
buffer_size 4096
rate 44100
periods 0
period_time 0
}
bindings {
0 0
0 1
}
}

asym

This plugin allows for simultaneous playback and capture.

pcm.name {
type asym # Asym PCM
playback STR # Playback slave name
# or
playback { # Playback slave definition
pcm STR # Slave PCM name
# or
pcm { } # Slave PCM definition
}
capture STR # Capture slave name
# or
capture { # Capture slave definition
pcm STR # Slave PCM name
# or
pcm { } # Slave PCM definition
}
}

This code shows how to use of the plugin.

pcm.duplex {
type asym
playback.pcm "dmix"
capture.pcm "dsnoop"
}

PCM is configured here for playback with dmix and audio capture with dsnoop.

alsamixer

Test any sound device with Alsa’s awesome text-based UI.

Open a terminal and run AlsaMixer.

alsamixer

From Ubuntu’s ever resourceful wiki, I refer to the list of controls for the UI.

  • Select a sound card using F6
  • F5 for recording controls
  • Navigate with left and right arrow keys
  • Increase and decrease volume with up and down arrow keys
  • Increase and decrease volume for left/right channel individually with “Q”, “E”, “Z”, and “C” keys
  • Mute/Unmute with the “M” key. An “MM” means muted, and “OO” means unmuted. Note that a bar can be 100% full but still be muted, so do check for this
  • Exit from alsamixer with the Esc key

Permanently save the volume setting in Alsa by storing it with Alsa.

alsactl store

Extra software for Icecast

Install Supercollider to connect midi devices, and give them PCM names.

This is the command to install Supercollider.

apt-get install supercollider

Another package we can optionally install for Icecast Yellow Pages is libcurl. If you do not install this package before installing Icecast, you will not have YP support.

apt-get install libcurl

Installing Icecast and Ices!

Now we can install the server software!

For Raspbian Stretch and Raspbian Stretch Lite, download the Debian package for armhf processors suing the command line.

wget http://ftp.us.debian.org/debian/pool/main/i/icecast2/icecast2_2.4.2-1+b1_armhf.deb

The package is also available on Debian.org.

The server software itself can now finally be installed!

apt-get update
apt-get install icecast2

Icecast is configured in XML.

nano -c /usr/local/etc/icecast.xml

To add YP support to be listed in Icecast Yellow Pages, add this block of code. Remember and make note, to have YP support install libcurl before Icecast.

<directory>
<yp-url-timeout>15</yp-url-timeout>
<yp-url>http://dir.xiph.org/cgi-bin/yp-cgi</yp-url>
</directory>

After installing the server you will need a source application. A popular choice is Ices, which is actually Ices2 in its current version. Just as you may have noticed from the installation command, Icecast is Icecast2 in its current version.

apt-get update
apt-get install ices2

Configuring Ices for Icecast

Ices is configured in XML.

nano -c /etc/ices.xml

This page describes all the settings.

IceS 2.0.2 Docs — Config File

Once configured, supply the XML file as an argument to the program at invocation time.

ices /etc/ices.xml

An XML file can be invoked from any directory using Ices. Many clever recipes are available for running Ices, and many commercial Internet radio stations use this technology. Use the following recipe as a guide to making your own private home intranet radio station.

Run Your Own Webradio Station With Icecast2 And Ices2

If you do not use the recipe in that link, you could use the provided code modifications for adding Ices to the Icecast startup script. It is posted for reference. Though you are not going to probably run a commercial radio station, Internet radio station guides have plenty of knowledge and experience to share on this topic.

Ubuntu – Icecast2 Startup Script with Ices2 Support

Adding modules to Ices

Several Ices modules are available.

IceS 2.0.2 Docs — Input Modules

The modules are configured in /etc/ices.xml.

  • OSS – Open Sound System
    • Used on linux based systems to get live input from a sound card
    • alsa-oss
  • ALSA – Advanced Linux Sound Architecture
    • Like OSS but with various improvements for linux based systems
    • alsa-base alsa-utils
  • StdinPCM – Standard input to receive PCM audio
  • Playlist – Uses a playlist to read audio files for processing

Add all the modules to your Ices XML file.

# This is the code block for the OSS Open Sound System module

oss
44100
2
/dev/dsp
1
/home/ices/metadata

# The code block for ALSA...

alsa
44100
2
hw:0,0
2
500
1
/home/ices/metadata

# This the code snip for StdinPCM

stdinpcm
44100
2
1
/home/ices/metadata

Create an Ices XML playlist for Icecast

This is a code snip to use in your Ices XML file again and again as a template for a playlist. A playlist must exist in the Ices XML file by itself. If you want to configure more than one playlist, create and use more than one Ices XML file. Create and store and run this file with any name (ending in .xml) in any directory containing the audio media files.

It is not a manually created playlist, a traditional list of files to play. Icecast generates a playlist from the contents of a streaming directory. You tell Ices to use a directory path on the command line, and Icecast generates its own playlist.

basic
/path/to/playlist # Specify the full path to the streaming directory
0
0
1

Invoking Ices from the command line is easy with the XML file. This command allows Ices to invoke the XML file from one directory, to stream from another.

ices -c /etc/icecast2/icecast.xml -F /home/pi/Music/

Ices is used to play OGG files, but it cannot play MP3 files.

Playing mp3 on Icecast without Ices

We execute Icecast without Ices to play MP3.

icecast -c /etc/icecast2/icecast.xml -F /home/pi/Music/

To stream a URL, use the -u switch with the command.

icecast -c /etc/icecast2/icecast.xml -u http://ice1.somafm.com/u80s-128-mp3

Third-party apps for Icecast

Many third-party apps are available on their website you should explore for yourself.

Icecast.org – 3rd Party Applications

Icecast Player in Google Play

One popular mobile app is Icecast Player on Google Play.

Kodi Icecast addon

Try the Icecast addon for Kodi, which allows you to listen to streams listed in the Icecast Yellow Pages. Install this addon from the default Kodi repository in Music addons.

Kodi music addon for Icecast in default repository - Icecast Ices2 music server for Raspberry Pi
Kodi music addon for Icecast
Icecast addon settings

Change the settings to choose a different visualization, or to enable lyrics addons to display the lyrics while playing.

Icecast addon for Kodi settings - Icecast Ices2 music server for Raspberry Pi
Icecast addon for Kodi settings
Icecast addon settings in player mode

Change the settings from inside the addon in player mode.

Accessing Icecast settings in player mode - Icecast Ices2 music server for Raspberry Pi
Icecast settings in player mode

Showing lyrics on Icecast

Installing CU LRC Lyrics for Icecast

Install the CU LRC script addon from Program addons in the Kodi repository.

Installing addons from a repository on Kodi in Debian - Icecast Ices2 music server for Raspberry Pi
Installing addons from a repository on Kodi

Navigate to the Lyrics directory in Addons.

Using the Kodi repository lyrics directory - Icecast Ices2 music server for Raspberry Pi
Kodi repository Lyrics directory

The CU LRC addon is inside the Lyrics directory.

The Kodi repository lyrics directory CU LRC addon - Icecast Ices2 music server for Raspberry Pi
Kodi repository lyrics directory CU LRC addon

Enable Icecast to display lyrics

Once installed, CU LRC can display lyrics in the Icecast addon.

Setting CU LRC to display lyrics in Icecast addon in Kodi - Icecast Ices2 music server for Raspberry Pi
Setting CU LRC to display lyrics in Icecast addon

Search Icecast Yellow Pages

Search for a station based on your preferences for music.

Searching for stations in Icecast addon for Kodi - Icecast Ices2 music server for Raspberry Pi
Searching for stations in Icecast addon for Kodi

For me, this station is Area 51!

Icecast radio station list in Kodi addon - Icecast Ices2 music server for Raspberry Pi
Icecast radio station list in Kodi addon

Icecast on a full HTPC

As a popular music streaming server, Icecast is a popular server application with lots of goodies. The Pi is for learning. If you want to build something permanent, the Pi will give you the basic education you need to begin and experiment. Icecast is a great way to listen to and play music.

CU LRC lyrics addon displaying Icecast stream on Kodi - Icecast Ices2 music server for Raspberry Pi
CU LRC lyrics addon displaying

Icecast will stream on a full HTPC as a private intranet radio station on a home server, or it can be used for public and commercial Internet radio streaming. Many extra features can be configured more apps can be installed and used with Icecast. It is a playground in audio streaming, to be enjoyed for both the sound and the technology.

Icecast and Internet radio

Internet radio stations use all kinds of ways to store, access, generate, and run playlists, because a great amount of software is made for running Internet radio stations. Most of it is easily found in search engines.

Final conclusion

A popular trend in home networks today is to configure an audio media server and DJ your own parties and social events. Away at a friend’s or relative’s place or in your own living room, you do not need a special occasion to spin out tunes. A server like Icecast can generate its own playlist. To begin streaming, it is easy to supply Icecast with the path to the music folder you want to play and it makes its own list. Icecast is also the perfect playground for learning other audio software, while improving a pocket-sized DIY DJ audio server.

Begin listening with Icecast today!

Additonal resources for Icecast

Alsa for Icecast

OpenSRC.org – ALSA Setup Guide

OpenSRC.org – ALSA Setup Guide – Quick Install

Adafruit.com – Raspbian Jessie – Updating alsa options

AlsaProject.org – Asoundrc

RadioReference.com – ALSA

Degian.org – AlsaMixer

wiki.Ubuntu.com – AlsaMixer

Icecast and Ices

Icecast.org – Icecast 2.4.1 Docs — Table of Contents

Icecast.org – Icecast Current Release

Icecast.org – IceS 2.0.2 Docs — Basic Setup

Icecast.org – 3rd Party Applications

Get 20% OFF with IPVanish VPN:

♦   Hide your browsing and streaming activity: No logs and no tracking
♦   Access geo-restricted content from anywhere
♦   Encrypt and anonymize: Kodi, Plex, Downloads, Personal Info
♦   Windows, Mac, Linux, Android, iOS, Router, and more.
♦   Money back guarantee - Sign Up Now

About the author

w3tech

My interest in media software is development and instruction. I feel I can explain things well in writing. I have to make sense of it for myself, and bring it down to my level before I describe it to someone else. That should be easy enough for even a house plant to understand. I enjoy plenty of sun and need a lot of cool shade just the same.