FreeBSD JukeBox Project

By : Scott Muc - Sept. 12th, 2003

Objective

My boss purchased an Audiotron, and I thought the concept was pretty cool. You have a network appliance with a network connection and an audio connection. This device reads and indexes your music collection over the network and can play the music, and output the audio over the audio connection. The Audiotron has a remote control and a direct interface to allow you to alter playlists and control the audio output. I was pretty sure that it would be simple to do something similar using FreeBSD, and sure enough, it was!

Hardware Requirements

The great thing about this project is that you don't need any fancy hardware for it. Of course, if you don't have a dozen old PC's lying around like I do, you may want to have better hardware, because you want to make the machine do more than just play music. I'll just give you a list of what I am using to run my jukebox. Keep in mind that what I have is more than ample for this implementation.

Implementation

Since this article isn't on installing FreeBSD, NFS, or network configuration; I will leave that as an exercise for the reader. I'm going to start the setup of the software assuming the following criteria is met :

The software requires some libraries to be installed in order to work. Theses libraries are : libao and zlib. These are both in the FreeBSD ports collection and can simply be installed from there.

The next step is to download, compile, and install the Music Player Daemon. The following shell commands should get you on the right track:

    $ mkdir /tmp/src
    $ cd /tmp/src
    $ fetch http://mercury.chem.pitt.edu/~shank/mpd-0.8.7.tar.gz
    $ fetch http://mercury.chem.pitt.edu/~shank/phpMp-0.8.3.tar.gz
    $ tar -zxvf mpd-0.8.7.tar.gz
    $ tar -zxvf phpMp-0.8.3.tar.gz
    $ cd mpd
  

The configure script doesn't follow FreeBSD's filesystrem structure and looks for the ao headers in /usr/include/ao when in fact they are in /usr/local/include/ao. So to prevent any errors in the configure script, and compilation, just symlink that directory.

    $ ln -s /usr/local/include/ao /usr/include/
  

Now you can configure and build the mpd binary. After the build, copy files under the proper hier(7) structure.

    $ ./configure
    $ make
    $ cp mpd /usr/local/bin
    $ cp mpdconf.example /usr/local/etc/mpd.conf
    $ touch /var/log/mpd.error /var/log/mpd.log /usr/local/etc/rc.d/mpd.sh
  

Then we need to tweak the mpd.conf for your environment. As an example, here's my mpd.conf. I tweaked the buffer_before_play variable to a lower value so that song startup is more responsive.

port                    "2100"
music_directory         "/mnt/mp3"
playlist_directory      "/mnt/public/list/"
log_file                "/var/log/mpd.log"
error_file              "/var/log/mpd.error"

connection_timeout      "60"
mixer_device            "/dev/mixer"
max_connections         "5"
max_playlist_length     "4096"
buffer_before_play      "10%"
stop_on_error           "yes"
max_command_list_size   "2048"
max_output_buffer_size  "2048"
ao_driver               "oss"
ao_driver_options       "dsp=/dev/dsp"
save_absolute_paths_in_playlists "no"
bind_to_address         "any"
  

Lastly we put the following in the mpd.sh script so the daemon starts when the machine boots.

#!/bin/sh

case "$1" in
start)
        /usr/local/bin/mpd /usr/local/etc/mpd.conf \
       		> /dev/null && echo -n ' mpd'
        ;;
stop)
        killall mpd
        ;;
*)
        ;;
esac

exit 0
  

Now you should be able to excute ./mpd.sh start to start mpd. Simply run ps aux | grep mpd to see if the process is running.

We now have mpd running. The only thing left to do is to install a nice interface to it. I chose to use the php based webinterface for Music Player Daemon. Assuming you have Apache and mod_php4 running, all you have to do is symlink or copy the phpmp directory to /usr/local/www/data/ and you should be able to browse to the machine and you will be able to run your FreeBSD pseudo audiotron!

Conclusion

Hopefully I made the installation of the Music Player Daemon straight forward for the FreeBSD environment. I feel this is a project that anyone can do easily, even if they don't have unix experience. I can see a novice being frustrated with the mpd compilation and configuration errors; so I hope that I managed to help a few people get fast that stage of the process.

In my case a lot of the prep work was already done. I have a file server with my 8000+ mp3s on it. It is running Samba for the one Windows box I have, and it's also running an NFS server for my desktop (FreeBSD). So I have one piece of the puzzle completed already. My audio output will be handled by my Altec Lansing AC 48 computer speakers. They aren't Hi-Fi but they definitely have decent sound quality and amplification for my purposes. The sub is a nice convenient size that I can fit under my bed, and the speakers sit upon my window sill, so the system is making the smallest foot print possible.

The end result that I want is an audio system that is independent of whatever desktop I am running. If I want to boot into BeOS, then back into FreeBSD, I can do so without having to stop my music!


Scott Muc is a computer geek with too much time on his hands.