IceCast/Shoutcast source on Raspberry Pi 2

Introduction

I am a SecondLife player and scripter/builder of things for SecondLife. I am also a keen musician who loves to improvise and experiment with ideas and I run a business in-world and have been looking for an economical way of bringing in-store music to my business, with the possibility of an automated Live-Stream option for when i want to perform in SL.

I have used Raspberry Pis for some time now, and have to say whilst they’re not the most powerful devices, they certainly are for the price, And thanks to a vast world of open-source projects available for the Raspberry Pi and other platforms, There is a surprising amount of things you can do with these little wonders.

If you wish to follow along with this project I am about to go into here, You will need the following:

  • A Raspberry Pi 2 or greater
  • a micro-USB phone charger (output rated at 2 amp or greater)
  • 16gig or better SD card (higher = more storage space for your tunes and shows you might prepare and broadcast)
  • USB Mouse and keyboard (for setup only)
  • HDMI TV or monitor (for setup only)
  • USB Audio cable or soundcard (USB HID compliant)
  • Ethernet cable (or WIFI if you are using a Raspberry Pi 3 or higher)
  • cables to connect the sound device to your analogue audio equipment
  • finally, some patience, and some free-to-broadcast music or music u have broadcasting license for.

Lets start at the beginning. The first thing you’ll need to do is get some sort of Linux operating system on your Raspberry Pi. the easiest way to do this is by using the NOOBs tool provided by the Raspberry Pi foundation. you can download it from here: https://www.raspberrypi.org/downloads/noobs/

Your SD card will not come formatted in a format that the Raspberry Pi can understand (SD cards come formatted in exFAT format, which the raspberry pi’s CPU cannot read) so we are now going to fix this by correctly partitioning and formatting the card for NOOBs.

Tools for Windows users:

Windows has a few free partitioning tools, or you can use the official SD formatting tool released by the SD foundation. Guides for this can be found on http://www.raspberrypi.org

Tools for Linux users:

Linux also has a few free tools – gparted is the recommended, and this comes pre-installed with most distros.

Whichever tool you choose, You need to insert your SD card into your computer’s SDCard reader, start your chosen partitioning tool, then select the SD card there and the partition that exists on it, and either change it/reformat it to FAT32 or delete and create a new FAT32 partition. use the default recommended settings for it if asked. Apply the changes, then eject and re-insert to make sure the changes have been made. Close the partitioning tool and open the SD card in Explorer (windows), Finder(mac) or your linux desktop file manager.

Extract the contents of the NOOBs zip file you downloaded to the SD card. once completed you can eject the SD card and insert it into your raspberry pi.

Installing Raspbian

Now you have NOOBs prepared on your SD card, its time to power up the Pi. plug your keyboard and mouse and monitor into the Pi, and finally the power cord.

After a rainbow coloured square on the screen at power-on, NOOBs will load and run on your raspberry pi. Click on “Install” and you will be presented with a list of available distributions to choose from. Our setup requires Raspbian, so use that. You can use either the Desktop or Minimal distribution – though the Desktop has many useful tools on it as well. For this project we’ll assume Minimal version. Click on the distribution you would like, and the “data” partition. this is essential if the raspberry pi needs tweaking later on in certain cases. finally click “Install” again to complete the installation. This could take a few minutes depending on which version you chose.

Once setup has finished, your raspberry pi will reboot. Ignore the starting screen, and let it boot to the login prompt. This will be either a graphical login (Desktop version) or a black and white text prompt (minimal), and log in using the following details (these are case-sensitive)

  • Username: pi
  • Password: raspberry

If you are on the Desktop version (with nice GUI and all that) then open a terminal window.

We are now going to install GIT and a couple of other tools so we can put our Internet radio station together.

At the command prompt (or terminal window if on desktop), enter the following commands:

sudo apt-get install git

sudo apt-get install ices2

this installs git (a sourcecode downloading tool, which keeps track of changes you make to the files so you can revert them if needed, and can also be used to checkout the latest fixes easily), and ices2, a tool we will be using to broadcast live line-in or microphone audio.

once these have installed, it is now a good idea for some performance tweaks if you are using the desktop version, and to install OpenSSH so you can log into your raspberry pi remotely to perform future tasks.

at the command-prompt type:

sudo raspi-config

This opens the raspberry pi configuration tool, here we need to tell the raspberry pi to boot to CLI instead of the desktop, as the desktop is resource-hungry and will slow down our server.

in raspi-config, use the arrow keys on your keyboard to navigate down to option 3: Boot options and press Enter

Then choose the first option: Boot to Desktop/CLI and press Enter.

Finally, Choose the first option: Console and press Enter. This will take you back to the main menu.

Now we will enable the SSH server:

navigate to “Interfacing options” and press Enter. Then navigate to the “SSH” option, again press Enter. It will ask you to confirm if you want to enable. Choose Yes and press enter again.

Navigate down to “Finish” and press enter to save the new configuration and exit the program.

This now disables the Desktop from loading, and enabled the OpenSSH server at startup, which will save a lot of problems later on. You can change this setting at any time, or start the desktop simply by typing “startx” at the console after login.

Now is a good time to make a note of your Raspberry Pi’s assigned IP address. At the console, enter:

ifconfig

your ip address will be shown next to the “inet” of your interface (eth0 or wlan0), likely beginning with “192.168.”
To save hassle, You might want to google how to set this as a static-ip address so that it never changes. We wont cover that here, but there are plenty of tutorials that can be found on Google, Bing or duck-duck-go that explain how to do it.

Installing Libretime

Libretime is the software we will be using for our radio station. it is a neat, easy to use, webpage-based DJ application which can be accessed from any computer on your network to upload music, shows, etc and arrange them into playlists, and compile shows to be scheduled automatically on your station.

To download and install Libretime and its dependencies on your raspberry pi, type the following:

git clone https://github.com/LibreTime/libretime.git

Now go grab a coffee, or preferred beverage, and chill for a bit while Git does its thing and downloads Libretime. this will take a couple of minutes

When check-out completes type:

cd libretime

sudo ./install

Installation will now begin. Coffee (or beer/wine) time again. this process takes quite a bit longer.

Once completed it will tell you to visit the newly-created website to complete setup, If you are running in CLI mode (not desktop) you will need to do this either on a smartphone, laptop or PC, entering the IP address of your raspberry pi into the web-address bar on your browser.

Follow the instructions on the web-site, completing the settings as you go. Once done, you’ll be asked to execute 4 commands in the terminal, or CLI. IMPORTANT: DO NOT CLICK “NEXT” until you have done this. If you’re on the desktop on the raspberry pi, simply copy and paste.

Now click Next on the website, and a quick check will be performed to make sure all services are up and running. If so, the page will display each check with a green tick. You’re good to go! Click next to get to the login screen.

Log in to the website using the following details:

username: admin

password: admin

And youll be taken straight to the dashboard. From here you can now upload your music and audio recordings, etc and schedule your shows, set up streaming options etc.

Full instructions on how to use Libretime are available here: https://libretime.org/

If you do not wish to broadcast your own live audio feed, you can quit this tutorial now 🙂

If you do wish to broadcast live audio however, then continue 🙂

Making note of the server settings for live broadcasts

Click on the “Settings” link on the left of the site. This will bring up the settings page. From here, click “Streams”.

Librecast has the built-in ability to mimic an IceCast2 server, meaning Live DJs and Singers, artists etc can log in using their own streaming software such as SAM Broadcaster, Mixxx.org, etc and stream their live shows and sets. Libretime fades out the currently playing show and switches over to broadcast this, relaying the artist to your listeners.

In the Streams window on the right, you can set whether to use the built-in server to stream your station’s output to (not advised on a raspberry pi), or to use a professionally hosted server (recommended. for SL streams , The Shoutcast Barn provides a wide range of streaming servers).

On the left, you can specify the server settings for the dummy Master Source and Show Source stream servers. The Show stream allows your DJs to stream direct to your server at their allotted time-slot, and only to them, no one else.

The Master stream can be logged into at any time and will cut-out the main station, forcing it to instead relay your stream.

As you are the master, we will use the Master Source server for our live audio broadcasting option.

In the Master Source options on the left, change the following settings:

  • Username: source
  • Password: your-chosen-password (must be all-one-word, no spaces)

Click “Save” on the bottom right. make a note of these settings, they are case-sensitive. we will be using them in the next step:

back in the CLI (or terminal window if you’re forward-thinking enough to be doing this over SSH by now):

create a new folder in your home directory:

cd ~

makedir LiveAudioIces

cd LiveAudioIces

nano is a text-based text editor for linux, and we are going to use it to create a session configuration for the IceS2 client we installed earlier.

First off however, we need some information about our audio hardware to get the ALSA address of our USB audio card:

arecord -l

Arecord is a tool that is part of the ALSA audio system in linux. The above command displays all available audio recording devices.

We need the Card number, and subdevice number. These will be different depending on what USB audio device you are using. If for example it is a USB microphone, it will likely only have one sub-device: 0. If however it has multiple recording inputs, it will have more than one.

The cable i am using is a simple Line-in to USB cable, so it only has the one subdevice: 0. It’s designated card number is 2.

in alsa terms, this device is requested as follows: “plughw:2,0”. Make a note of yours for the next step

We need to create the session configuration file for IceS2 in our newly created folder:

for this we will use a simple text editor called “nano”:

Download the IceS.xml file here: https://drive.google.com/open?id=1UEWkXM42c2afXAbBxGiXgVuFrVk4KhNu and save it to our newly create folder, then open it in nano:

nano ices.xml

in the <input> section, change numbers in “plughw:2,0” to the Card number, and subdevice number of your USB recording device as noted previously.

further down in the file, locate the <instance> settings. Change the password to the one you set in Libretime for Master source, and leave the rest as-is (unless you changed them as well in libretime). Finally, further down the file, toward the end, locate the <encoder> settings. Change the bitrate to 128200, as the default value of 64000 has a fried-eggs quality to it which doesnt sound too good. If your soundcard does not support 44100 hz recording, change the <samplerate> setting accordingly. Same if it is only mono – change the channels from 2 to 1, otherwise, leave as-is.

Press ctrl+x and if it asks to save the changes, choose yes and press enter twice. this will quit nano.

Finally, plug your audio cable into a tapedeck or musical instrument such as a keyboard or mixing desk, and at the terminal, type:

ices2 /home/pi/LiveAudioIces/IceS.xml

go back into your web-browser, onto your libretime page, and click “Listen”. If you have set up ices2 and libretime correctly, your live audio should now be heard. If the sound is distorted, in the terminal, type:

alsamixer

And press F6 to select ur soundcard. once you’ve done that, press f5 to show all inputs on it, and use the left/right arrow keys to switch the input control, and up/down to adjust the input volume. some devices are incredibly sensitive so will need lowering quite a bit to reduce distortion. The delay in the server is quite significant due to the audio routing, so wait 20 or 30 seconds untill youll hear the change.

If all is good, you are done now 🙂 Happy broadcasting, keep it legal and See you in the next tutorial where ill be showing how to enable automatic live-broadcasting when the usb device is plugged in.