{"id":408,"date":"2009-12-25T00:15:37","date_gmt":"2009-12-25T04:15:37","guid":{"rendered":"http:\/\/www.streamingmeemee.com\/index.php\/2009\/12\/25\/build-a-live365-station-using-linux-part-1\/"},"modified":"2009-12-26T14:52:03","modified_gmt":"2009-12-26T18:52:03","slug":"build-a-live365-station-using-linux-part-1","status":"publish","type":"post","link":"https:\/\/www.streamingmeemee.com\/index.php\/2009\/12\/25\/build-a-live365-station-using-linux-part-1\/","title":{"rendered":"Build a Live365 station using Linux &#8211; Part 1"},"content":{"rendered":"<p>I\u2019ve run <a href=\"http:\/\/www.dreamlandblues.com\">Dreamland Blues Radio<\/a>, 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&amp;D lab outside business hours (rats!) I came to the realization that I needed a more stable and scalable platform; enter <a href=\"http:\/\/www.live365.com\">Live365<\/a>.<\/p>\n<p>Of course, back then it wasn\u2019t called Live365 (bonus points for anyone who can tell me the original name) but I was invited to preview the beta of the service \u2013 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 \u2018Live\u2019 stream.<\/p>\n<p><!--more--><\/p>\n<h3>Backgound &amp; Design Goals<\/h3>\n<p>I\u2019ll spare you the remainder of the history lesson but suffice to say that several years ago I abandoned the \u2018Live\u2019 approach and switched to a Basic stream.  I was not happy about it but the situation at the time left little alternative.  I\u2019ve always wanted to return to Live \u2018casting.  Cross-fade to today\u2026<\/p>\n<p>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 \u2018carbon based processing\u2019.<span> <\/span>Dreamland Blues is not a \u2018live\u2019 station in the sense that a human DJ does voice-overs, in fact my voice has never appeared on the station; the station\u2019s goal has always been to maximize the music.<span> <\/span>This is a perfect fit for an automated solution.<\/p>\n<p>My design goal for the new system was to match the functionality of my original Windows based station:<\/p>\n<ul>\n<li>Ability to feed Live365 including song metadata (Artist, Title, Album) updates.<\/li>\n<li>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.<\/li>\n<li>Ability to create and schedule \u2018special event\u2019 playlists.  Good examples of this are Holiday music or Artist specials.  (Sadly, in my genre this usually means memorials for a recently passed artist)<\/li>\n<li>\u2018Hands off\u2019 operation.  The entire system must be capable of running without human interaction for extended periods (weeks).<\/li>\n<\/ul>\n<p>I\u2019m going to cover only the first requirement in this post; the others will follow later.<\/p>\n<h3>Music Player Daemon (MPD)<\/h3>\n<p>I\u2019ve chosen to use <a href=\"http:\/\/mpd.wikia.com\/wiki\/Music_Player_Daemon_Wiki\" target=\"_blank\">MPD (Music Player Daemon<\/a> as the core media player for my station.<span> <\/span>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\u2019s 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\u2019ll cover later.<\/p>\n<p>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 <a href=\"http:\/\/sourceforge.net\/projects\/musicpd\/files\/mpd\/0.15.6\" target=\"_blank\">available on SourceForge<\/a>.  You will find a list of dependencies <a href=\"http:\/\/mpd.wikia.com\/wiki\/Dependencies\" target=\"_blank\">here<\/a>.  For our purposes you need the \u2018httpd\u2019 Audio Output requirements.  You\u2019ll 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&#8217;s ability to <a href=\"http:\/\/en.wikipedia.org\/wiki\/Transcode\" target=\"_blank\">transcode<\/a> (e.g. convert formats from FLAC to MP3) and convert <a href=\"http:\/\/en.wikipedia.org\/wiki\/Sample_rate\" target=\"_blank\">sample rates<\/a>.  This eliminates the need to re-encode your existing library to match the bitrate, format and sample rate of your station stream.  EPIC WIN!<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nmpdserver:~ # cd \/usr\/src\/\r\nmpdserver:\/usr\/src\/ # wget http:\/\/downloads.sourceforge.net\/project\/musicpd\/mpd\/0.15.6\/mpd-0.15.6.tar.gz\r\nmpdserver:\/usr\/src\/ # tar -zxvf mpd-0.15.6.tar.gz\r\nmpdserver:\/usr\/src\/ # cd \/mpd-0.15.6\r\nmpdserver:\/usr\/src\/mpd-0.15.6\/ # configure \u2013enable-http\r\nmpdserver:\/usr\/src\/mpd-0.15.6\/ # make\r\nmpdserver:\/usr\/src\/mpd-0.15.6\/ # make install\r\n<\/pre>\n<h3>MPD Configuration<\/h3>\n<p>Next, you\u2019ll need to edit the MPD configuration file, \/etc\/mpd.conf.  Change the \u2018music_directory\u2019 and \u2018playlist_directory\u2019 options to point to the directories where you store you music files and your playlists respectively.<\/p>\n<p>The key change in the config. file is to add an \u2018httpd\u2019 entry in the audio_output section.  Here is a sample:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\naudio_output {\r\n    type        &quot;httpd&quot;\r\n    name        &quot;My Awesome Station&quot;\r\n    encoder     &quot;lame&quot;            # This is the MP3 encoder\r\n    port        &quot;8000&quot;            # listen on this TCP port for connections\r\n    bitrate     &quot;56&quot;              # in kbps\r\n    format      &quot;22050:16:2&quot;      # sample rate:sample size:channels\r\n}\r\n<\/pre>\n<p>You can also add a section for an ALSA or OSS device so that you may listen to the feed locally.<\/p>\n<p>I also enabled the ReplayGain feature by these settings:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nreplaygain           &quot;track&quot;   # track|album\r\nreplaygain_preamp    &quot;0&quot;       # in dB\r\nvolume_normalization &quot;yes&quot;\r\n<\/pre>\n<h3>MPD Startup and Testing<\/h3>\n<p>Once you\u2019ve saved the changes you start MPD with this command:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nmpdserver:\/usr\/src\/mpd-0.15.6\/ # mpd \/etc\/mpd.conf\r\n<\/pre>\n<p>MPD will automatically daemonize (move to the background) and open the control port to listen for commands.  To stop the MPD daemon:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nmpdserver:\/usr\/src\/mpd-0.15.6\/ # mpd \u2013kill\r\n<\/pre>\n<p>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\u2019ing to the control port:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nmpdserver:\/usr\/src\/mpd-0.15.6\/ # telnet localhost 6600\r\nOK MPD 0.15.0\r\n<\/pre>\n<p>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 <a href=\"http:\/\/mpd.wikia.com\/wiki\/Protocol_Reference\" target=\"_blank\">here <\/a>.  We are interested in loading a playlist and starting playback.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nmpdserver:\/usr\/src\/mpd-0.15.6\/ # telnet localhost 6600\r\nOK MPD 0.15.0\r\nload myplaylist\r\nplay\r\ncurrentsong\r\n<\/pre>\n<p>The \u2018currentsong\u2019 command will display the details of the currently playing track (big surprise, eh?).<\/p>\n<p>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.<span> <\/span>The URL of the stream is: <span style=\"font-family: monospace;\"><a href=\"http:\/\/ip_address_of_mpd_machine:TCP_PORT\">http:\/\/ip_address_of_mpd_machine:TCP_PORT<\/a><\/span>.  Using my example above on a machine with IP address 192.168.0.12 the URL would be:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nhttp:\/\/192.168.0.12:8000\r\n<\/pre>\n<p>After a few seconds of buffering you should hear you stream \u2013 hurray!<\/p>\n<p>This is only the start; to complete your Live365 feed you\u2019ll need to send along the metadata for the songs as they are played.  I\u2019ll cover that in the next post.<\/p>\n<p>If you have any questions just drop them in the comments below and I\u2019ll address them inline.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019ve 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&amp;D lab outside business hours (rats!) I came to the &hellip; <a href=\"https:\/\/www.streamingmeemee.com\/index.php\/2009\/12\/25\/build-a-live365-station-using-linux-part-1\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Build a Live365 station using Linux &#8211; Part 1<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[26,32],"tags":[],"class_list":["post-408","post","type-post","status-publish","format-standard","hentry","category-digital-media","category-dreamland-blues-radio"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.streamingmeemee.com\/index.php\/wp-json\/wp\/v2\/posts\/408","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.streamingmeemee.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.streamingmeemee.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.streamingmeemee.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.streamingmeemee.com\/index.php\/wp-json\/wp\/v2\/comments?post=408"}],"version-history":[{"count":19,"href":"https:\/\/www.streamingmeemee.com\/index.php\/wp-json\/wp\/v2\/posts\/408\/revisions"}],"predecessor-version":[{"id":410,"href":"https:\/\/www.streamingmeemee.com\/index.php\/wp-json\/wp\/v2\/posts\/408\/revisions\/410"}],"wp:attachment":[{"href":"https:\/\/www.streamingmeemee.com\/index.php\/wp-json\/wp\/v2\/media?parent=408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.streamingmeemee.com\/index.php\/wp-json\/wp\/v2\/categories?post=408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.streamingmeemee.com\/index.php\/wp-json\/wp\/v2\/tags?post=408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}