Thursday, June 7, 2012

Roaming Media

Portable music doesn't need to be restricted to headphones. Here's a step-by-step how-to on setting up a music system that follows you around the house like a puppy.

Like many of you, I store all my music digitally on a central server in my home. The problem is when I walk from room to room, my music doesn't come with me. I could carry around an iThingy or put it on my phone, but I'd rather not have to wear headphones, and no matter how awesome they are in their class, tiny phone speakers still are tiny phone speakers. Fortunately, I have a lot of computer hardware lying around from past upgrades, so it was fairly easy for me to come up with some small, older systems for each area of my house. Now, instead of listening to music on a little device, I use a device to tag my location and have the music follow me wherever I go.

The system is easy to build and uses mostly off-the-shelf open-source programs. In addition to the player and control system, you need a way of tagging your location in the house. I use the Bluetooth radio on my phone, but you also could use RFID tags, Webcams with motion detection or facial recognition, or pretty much anything else that will let the system know where you are. For this setup though, I'm assuming you're using a Bluetooth device.

The central piece to this project is a server-based music player. I am using the Music Player Dæmon (MPD), a wonderful server-based system released under the GNU General Public License and available from the repositories of most Linux distributions. Install the software with your favorite package management system. In addition to this player, you need to set up a streaming system. Icecast fulfills this requirement and also is widely available. Install it as well.

Configuring MPD is fairly straightforward. The default file for your distribution is probably very similar to the example below, but you may need to change a few things. The music_directory entry should point to the directory that contains the music files and one bind_to_address should contain the non-loopback name or address of the server. If it binds only to 127.0.0.1, outside boxes may have trouble connecting to it.

The audio_output section defines where the music goes when it plays. In this case, you want to transcode it to Ogg format and send it to the Icecast server on the same host (although you could run these on different systems if it makes sense for your setup). Within this section, the port and password must match the configuration for the Icecast server, and the mount will define the portion of the URI after the server name. For simplicity, I've left it at /. If you start MPD after this configuration file is set up, it will be missing the Icecast socket to play to, so you need to set that up next. I've added some comments to the configuration below to help document the options there: music_directory "/data/arown/files/audio" #Point this atthe top level of your music directory. If you have more than one, a directory of symbolic links may help you.playlist_directory "/var/lib/mpd/playlists" #The followingfiles must be writable. I suggest making the directory owned by the user running MPD.db_file "/var/lib/mpd/database"log_file "/var/lib/mpd/log"state_file "/var/lib/mpd/state"user "mpd" #This is the user that the MPDprogram runs under. I highly suggest making this a nonroot user.bind_to_address "templar" #Place your machine name here, not"localhost" or "127.0.0.1" if you want to reach the MPDserver from another machine.bind_to_address "/var/lib/mpd/socket"port "6600" #This is the client control port forstarting and stopping the MPD player as well as building playlists and changing server side volume.log_level "verbose"input { plugin "curl"}audio_output { type "shout" encoding "ogg" #This is the media type for the stream, if your player wants MP3, use encoding "mp3" and be sure you have the proper tools to transcode to MP3 on your box. name "MusicPuppy" host "localhost" #The name of the boxthat the Icecast server is hosted on. port "8000" #The port of theIcecast server. mount "/" #This is the partof the URI after the hostname. I have left it to "/" forsimplicity, but often things like "/music.ogg" are used to make it clearer to the user. password "passthis" #The source password to theIcecast server. You probably should change this to something complex because you'll never have to type it in. bitrate "128" #The bitrate to transcode to. You may want to raise or lower this based on your CPU, bandwidth or your quality preference. format "44100:24:2" #This is three variables:44,100 represents the sample frequency, 24 is the bitwidth, and 2 is the number of audio channels. Experimenting here may give you better or worse quality, depending on your audio hardware and number of speakers.}filesystem_charset "UTF-8"

In order to finish off the server portion, you need to configure Icecast to stream the music it receives from MPD. The sample Icecast configuration file is quite long, but I've cut out the areas that I've changed.

Make sure that the source-password here matches the password from the MPD server. This allows the MPD server authorization to stream music to Icecast: passthis passthis admin passthis

Be sure that the bind addresses and ports are correct. The bind address can be localhost if the MPD server is on the same box. The port must match the port from the MPD configuration above: 8000 127.0.0.1

While you're in this configuration file, change the default passwords from "hackme" and "hackmemore" to something more secure, and check the location of the logs for debugging. Mine are in /var/log/icecast, but yours may vary.


View the original article here

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...