Building a Remote Controlled Jukebox with Linux

Introduction
Hardware
kernel
lcdproc
mpg321 <-- patch for shoutcast streams
lirc
irmp3
Addendum
References

Introduction

Update: I do not think it is worth creating an irmp3 jukebox any more. Here is why.

This article demonstrates how to create a Linux-based audio jukebox with remote control and LCD display for output to a stereo system. The jukebox can handle any audio format that irmp3 supports: MP3, Ogg, FLAC, CD-ROM, FM radio, shoutcast, etc. The hardware used is an Ahanix D.Vine 3 case.

This system is designed for a home entertainment center. It uses irmp3 to play MP3 files or shoutcast Internet radio stations via the local soundcard. If you want to stream your MP3s over a network (to other machines in the house, for example), I suggest instead the excellent program netjuke. Netjuke can be used on the same machine as irmp3.

Hardware

dvine 3 case
case You can't read an audiophile magazine these days without seeing a glamour shot of a sleek component with an LCD display. The Ahanix D.Vine 3 series case is a multimedia PC case with an optional liquid crystal display (LCD). I chose the series 3 because it takes a standard ATX power supply, uses a parallel port for the LCD, and fits in my stereo cabinet. Ahanix also makes a more recent series 5 model with an accompanying remote control, but it uses USB for the LCD and remote, a proprietary power supply, and a deeper footprint. I do not have experience with the series 5 or lcdproc/lirc over USB, but I have heard that there are some software and hardware solutions to make it work.

The Ahanix case comes with its own rear-facing fan that is virtually silent. The combination of all of the quiet components listed below yields a machine that is as quiet as a church mouse! This is important to me since the machine is in my living room.

I like Ahanix and their products, but be wary of some of their resellers. I recommend you avoid colorcase.com.

LCD The 2x16 character LCD available for the D.Vine series 3 contains the NEC D16314AGJ-011 chip that is compatible with the popular HD44780 chipset supported by lcdproc. The wire to the LCD runs through a special PCI slot cover to the rear parallel port. My only complaint with the LCD is that the letters are a little small to read from across the room, but I do like the LCD feature while navigating directories and listening to Internet radio.
remote I use a Packard Bell remote control whose infrared receiver plugs into a serial port. These remotes are supported by lirc and are very cheap on eBay.
soundcard The stereo-link USB device can be distanced from the PC power supply in order to reduce the electromagnetic interference with the sound signal. If you do use a PCI sound card, be sure to place it in the slot furthest from the power supply to reduce interference.

The stereo-link uses the CONFIG_USB_AUDIO setting in the kernel, and the /etc/irmp3d.conf setting for the mixer volume uses the "pcm" label instead of "vol".

Connect your sound card output to one of your stereo preamp's line level inputs such as CD or TAPE. Do not use your stereo's PHONO input since RIAA equalization will distort the signal.

CDRW+DVD I use the Samsung SM-352B CD-RW+DVD drive. It works with SCSI emulation in the Linux kernel.
Hard drive I use a 5400 RPM drive for reduced noise and heat. I do not recommend enclosing large capacity IDE drives in a Silent Drive to reduce noise even further. It will cook your drive. Modern drives need to be cooled with fans.
Power supply The Enermax EG465P-VE is a great power supply with a manual fan speed regulator.
Motherboard I use the ASUS P4S533-VM micro-ATX mobo with a Pentium 4 Celeron. I love ASUS motherboards. I have never had a problem using ASUS with Linux. Update July 2007: This motherboard will not work with modern Linux kernels. Its BIOS doesn't do ACPI correctly.
CPU cooler The Zalman CNPS5700D-Cu cooler reduces fan noise. The extra "shroud" that comes with the Zalman does not fit in the case, but the fan itself is quiet enough.

kernel

I used kernel 2.4.22 and configured the following options:
1. low latency patch
Patching your kernel for low latency is recommended here and here for superior audio performance under Linux.
2. DMA (Direct Memory Access)
DMA is the most important option you can choose in your kernel for superior audio performance. Without it, my audio playback would stutter during disk accesses. Configuring DMA in the kernel takes two steps. First, enable the specific chipset support for your particular IDE controller (as seen in the output of lspci). For my ASUS P4S533-VM motherboard, this was the SiS 5513 IDE chipset. Second, select the "use PCI DMA by default when available" option (CONFIG_IDEDMA_PCI_AUTO) in the kernel. You should see DMA set to 1 in the output of hdparm /dev/hda after rebooting with your new kernel.
3. serial and parallel support
Most kernels have this already. I needed serial support for my remote control and parallel support for the LCD. You should see "parport0" in dmesg output if the kernel detects your parallel port.
4. USB Audio Support
This is needed for the stereo-link device. I compile mine as a module (CONFIG_USB_AUDIO), and it is named audio.

lcdproc

lcdproc is a daemon that displays messages on an LCD. Make sure you use version 0.4.5 (or later) of lcdproc since 0.4.3 has a serious memory leak that will cause it to crash.
 # ./configure --enable-drivers=all 
 # make && make install
Configure /etc/LCDd.conf to use the HD44780 driver in winamp mode (aka 8 bit) instead of 4 bit which is the default in the configuration file.
 [server]
 Driver=HD44780
 ...
 [HD44780]
 ConnectionType=winamp
Now start up lcdproc with /usr/local/sbin/LCDd -s and look at /var/log/messages for any errors. lcdproc will listen on port 13666, and irmp3 will connect to this port automatically. The default /etc/LCDd.conf settings will not fork a daemon or report to syslog, so change LCDd.conf accordingly if you want this behavior.

Although the NEC D16314AGJ-011 LCD chipset is compatible with the HD44780, there are a few differences in the character set. Most notably is the "solid box" used for irmp3's volume display (ASCII character 255). This character is displayed as ÿ (y with an umlaut) by the NEC chip. I patched hd44780-charmap.h in the lcdproc source code to map the 255th character to 160, which resembled a box. The NEC Electronics website doesn't have specifications for the 16314 chipset (argh!), but you can find one at alldatasheet.com. I also hacked together a little program to cycle through the LCD character set to find a character that resembled a box.

After leaving my PC running for about 5 months, I noticed that the LCD display was displaying "scrambled" characters. Stopping and restarting lcdproc would work for a short while, but then the weird characters would start displaying again. My solution was to cycle the power to the LCD display (not the PC) and restart lcdproc. That fixed the problem. It seems the LCD needs a healthy restart every now and then.

mpg321

mpg321 (old | new) is a command-line MP3 player. mpg321 was written as a more open alternative to mpg123.

Danger: A security advisory has been released for mpg321 in January 2004. Please download a patched copy of the source code or you could have a remotely controlled jukebox in more ways than one!

You will need to patch mpg321 if you want to play shoutcast Internet radio streams properly because version 0.2.10 has a bug that causes skipping during playback of http streams. I have my own patch that fixes this bug and also enables mpg321 to report shoutcast stream data to higher level applications such as irmp3. The patch enables the LCD to display updates of the artist and song title dynamically while listening to an http stream. As of the time of this writing, the latest version of mpg321 is 0.2.10. You may already have mpg321 installed on your system, but you will need to reinstall it if you want to listen to Internet radio using irmp3. Download mpg321-0.2.10 source and apply this shoutcast patch [sourceforge mirror]. You don't need the patch if all you want to do is play local MP3 files.

 $ tar zxvf mpg321_0.2.10.2.tar.gz
 $ cd mpg321-0.2.10.2
 $ patch -p1 < ../shoutcast-patch-0.2.10-3
 $ ./configure --with-default-audio=oss --disable-aotest  (I use OSS, YMMV)
 $ make && make install
You may also need to download libid3tag, libmad, as well as install libao-devel from the Redhat CD to build mpg321 from source.

The mpg123 binary location is specified in /etc/irmp3d.conf. I changed my configuration file to point to /usr/local/bin/mpg321 instead.

 mpg123_binary: /usr/local/bin/mpg321
If you haven't already done so, make sure your sound card is working. Play an mp3 file with mpg321 or a .wav file with play to make sure your sound card is producing sound. gnome-volume-control is what I use as a mixer.

lirc

LIRC is a daemon that converts infrared signals to button names. Applications register with lirc, and lirc calls the application back when button events occur. If you use a remote control that is supported by lirc already (like the Packard Bell), your job is easy.
 # ./configure && make && make install
 # ldconfig
 # depmod -a
 # cp remotes/packard_bell/lircd.conf.packard_bell /etc/lircd.conf
 # setserial /dev/ttyS0 uart none
 # modprobe lirc_serial
 # /usr/local/sbin/lircd
 # irw
Once you have verified that lircd is receiving keypresses on your remote control with the irw program, configure /etc/rc.d/rc.local to run the setserial, modprobe, and lircd commands at startup.

irmp3

Now that lcdproc, lirc, and mpg321 are configured, it's time to setup irmp3. irmp3 is the centerpiece of the solution. It accepts application events from lirc, launches mpg321, and sends messages to lcdproc. When irmp3 is not playing a song, it will go into screensaver mode and display the current date and time.

Let's review the configuration files and interprocess communication between the components.

diagram

To get it all working,
 # ./configure && make && make install
 # (generate an irmp3d.conf with 'irmp3conf')
 # ln -s /usr/local/etc/irmp3d.conf /etc/irmp3d.conf
 # /usr/local/sbin/irmp3d -l /var/log/irmp3d.log
You can experiment with your remote control settings, change /etc/lircirmp3.conf to adjust the buttons to your liking, and restart irmp3 with killall -s HUP irmp3d . Happy listening!

Please make a donation to your favorite Internet radio station no matter how small the amount. You probably have some slush money in your Paypal account right now. Don't be a freeloader!

Addendum (September 2005)

When I wrote this article in September of 2003, it was avant-garde. But just like putting a Linux box in your car with a 12V power supply was clever back in 1999, times have changed.

You don't need to cobble together all these pieces of software and hardware when you can purchase a Squeezebox for less than $300. You don't have to buy a pretty PC with a high-end sound card, spend lots of effort silencing it with special fans and absorbent material, and fiddle with lots of software to make a jukebox. Now you can buy a Squeezebox, put your server far away in a closet, and install everything with 3 commands on the command line.

Simply put, the Squeezebox is represented by the following equation:

Squeezebox = irmp3 + lirc + lcdproc + mpg321 + flac123 + netjuke + remote control + VFD display

You might think buying a Squeezebox is a rejection of open source software. It is not. Slim Devices has always supported Linux as a primary platform, the server software is GPLed, it is written in Perl, and it runs on any platform that supports a Perl interpreter.

I do not make this assertion lightly. I have personally contributed code to the irmp3 project. But in light of a product that does everything in a cohesive manner, the only reason to cobble together all the pieces described in this article is if the value of your time is less than $300. The Squeezebox has a gorgeous vaccum fluorescent display, a simple and easy to use remote control, and a great DAC with analog and digital outputs. It does for audio what Tivo did for television.

References

icecast protocol description
A technical description of shoutcast's icecast protocol.
Time Shifting FM radio
How I record FM radio and listen to it on my jukebox.