Build a Live365 station using Linux – Part 1

I’ve run Dreamland Blues Radio, a streaming internet radio station, since 1997. In the beginning I used WinAmp + Shoutcast streaming server on a Windows 95 machine. As the station grew in popularity and my then boss began to notice the bandwidth utilization of the R&D lab outside business hours (rats!) I came to the realization that I needed a more stable and scalable platform; enter Live365.

Of course, back then it wasn’t called Live365 (bonus points for anyone who can tell me the original name) but I was invited to preview the beta of the service – I jumped at it. The original setup continued to use WinAmp with the Shoutcast plug-in but the feed was then sent to Live365 for audience distribution; what is now called a ‘Live’ stream.

Backgound & Design Goals

I’ll spare you the remainder of the history lesson but suffice to say that several years ago I abandoned the ‘Live’ approach and switched to a Basic stream. I was not happy about it but the situation at the time left little alternative. I’ve always wanted to return to Live ‘casting. Cross-fade to today…

While Windows does make for a decent enough end-user experience I consistently turn to Linux based system for automating tasks that do not require ‘carbon based processing’. Dreamland Blues is not a ‘live’ station in the sense that a human DJ does voice-overs, in fact my voice has never appeared on the station; the station’s goal has always been to maximize the music. This is a perfect fit for an automated solution.

My design goal for the new system was to match the functionality of my original Windows based station:

  • Ability to feed Live365 including song metadata (Artist, Title, Album) updates.
  • Freshly generated playlist daily. Drawn from a catalog of thousands of tracks the playlist generation system considered many factors; my rating of the track, popular rating of the track, how long it had been in the catalog, etc.. It must maintain DMCA compliance.
  • Ability to create and schedule ‘special event’ playlists. Good examples of this are Holiday music or Artist specials. (Sadly, in my genre this usually means memorials for a recently passed artist)
  • ‘Hands off’ operation. The entire system must be capable of running without human interaction for extended periods (weeks).

I’m going to cover only the first requirement in this post; the others will follow later.

Music Player Daemon (MPD)

I’ve chosen to use MPD (Music Player Daemon as the core media player for my station. It includes a network based control interface and a rich set of commands to control playback functions and playlist operation. Version 0.15 of MPD supports HTTP based streaming that is necessary to feed Live365’s Nanocaster. The one missing bit is the song metadata; MPD can feed it along with the stream in Shoutcast format but Live365 does not parse it. I have another solution for metadata that I’ll cover later.

MPD is included with many Linux distributions but being the geek that I am I choose to build it from source. As of this writing the current version is 0.15.6 and is available on SourceForge. You will find a list of dependencies here. For our purposes you need the ‘httpd’ Audio Output requirements. You’ll also need the items from the Audio Decoding / Encoding section that match the format of your existing audio files (flac, AAC, MP3, wav, etc.). One of the main benefits of using MPD is it’s ability to transcode (e.g. convert formats from FLAC to MP3) and convert sample rates. This eliminates the need to re-encode your existing library to match the bitrate, format and sample rate of your station stream. EPIC WIN!

mpdserver:~ # cd /usr/src/
mpdserver:/usr/src/ # wget http://downloads.sourceforge.net/project/musicpd/mpd/0.15.6/mpd-0.15.6.tar.gz
mpdserver:/usr/src/ # tar -zxvf mpd-0.15.6.tar.gz
mpdserver:/usr/src/ # cd /mpd-0.15.6
mpdserver:/usr/src/mpd-0.15.6/ # configure –enable-http
mpdserver:/usr/src/mpd-0.15.6/ # make
mpdserver:/usr/src/mpd-0.15.6/ # make install

MPD Configuration

Next, you’ll need to edit the MPD configuration file, /etc/mpd.conf. Change the ‘music_directory’ and ‘playlist_directory’ options to point to the directories where you store you music files and your playlists respectively.

The key change in the config. file is to add an ‘httpd’ entry in the audio_output section. Here is a sample:

audio_output {
    type        "httpd"
    name        "My Awesome Station"
    encoder     "lame"            # This is the MP3 encoder
    port        "8000"            # listen on this TCP port for connections
    bitrate     "56"              # in kbps
    format      "22050:16:2"      # sample rate:sample size:channels
}

You can also add a section for an ALSA or OSS device so that you may listen to the feed locally.

I also enabled the ReplayGain feature by these settings:

replaygain           "track"   # track|album
replaygain_preamp    "0"       # in dB
volume_normalization "yes"

MPD Startup and Testing

Once you’ve saved the changes you start MPD with this command:

mpdserver:/usr/src/mpd-0.15.6/ # mpd /etc/mpd.conf

MPD will automatically daemonize (move to the background) and open the control port to listen for commands. To stop the MPD daemon:

mpdserver:/usr/src/mpd-0.15.6/ # mpd –kill

MPD will automatically start playing the playlist that was active when it was last shutdown. If this is your first time starting MPD then it will sit idle until you load a playlist and start playback. You access these controls using one of the many MPD clients or simply telnet’ing to the control port:

mpdserver:/usr/src/mpd-0.15.6/ # telnet localhost 6600
OK MPD 0.15.0

For some reason, it identifies itself as v0.15.0 when in fact is running the v0.15.6 version. The documentation for the various commands is available here . We are interested in loading a playlist and starting playback.

mpdserver:/usr/src/mpd-0.15.6/ # telnet localhost 6600
OK MPD 0.15.0
load myplaylist
play
currentsong

The ‘currentsong’ command will display the details of the currently playing track (big surprise, eh?).

Now that your stream has started you can fire up your favorite stream player (VLC, iTunes, WinAmp) and listen to your stream from any computer on your network. The URL of the stream is: http://ip_address_of_mpd_machine:TCP_PORT. Using my example above on a machine with IP address 192.168.0.12 the URL would be:

http://192.168.0.12:8000

After a few seconds of buffering you should hear you stream – hurray!

This is only the start; to complete your Live365 feed you’ll need to send along the metadata for the songs as they are played. I’ll cover that in the next post.

If you have any questions just drop them in the comments below and I’ll address them inline.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.