About Radu

Irina
Contact
Erasmus Student

Career

Resume
Education
Awards

IT/Computers

Projects Archive
Web Development
Papers & Translations

Photo albums

Romanian Mountains
Around the World
Few Photos with Radu

 

Linux Jukebox

(or how to turn your Linux box into a music player machine)

Before the age iTunes, iPods, and iPhones, back in year 2000 I was searching for a way to transform a normal dekstop PC into an automatic music box. I faced some technical constraints, as well as some financial ones (I could not afford a laptop at that time).

1. What I needed?

I need a normal desktop computer without monitor, without keyboard, without mouse, only with speakers to play all CDs (audio or with mp3s) plugged into the CD-ROM unit, without pressing any key; anytime I wish I have to be able to eject the CD and put another one; all this operations I have to be able to do using only eject button of CD-ROM unit.

2. Why I needed something like this?

During the Easter holiday of the year 2000, me and our friends wanted to be able to enjoy by our collections of CDs, but we haven't enough space in the car to load a monitor. We had enough space just for a desktop PC (we coulnd not afforded a laptop).

3. Computer's configuration

To build such a jukebox, we need a computer with the following components:

  • central unit containing:
    • processor, motherboard, memory, power supply
    • hard-disk
    • sound card
    • CD-ROM unit
  • speakers

We had an AMD K6-2 on 500 Mhz, with 64MB RAM, HDD Seagate Medalist (4 GB), a Funai 16x CD-ROM unit and an ESS1868 sound card. Operating system used was RedHat 6.2 Zoot with kernel 2.2.14.

4. What kind of software I needed?

Because we should use only the eject button of CD-ROM unit, I needed:

  • a way to eject mounted CDs during the system was playing mp3s from them (and I had to be able to do this in every single moment, not just between songs)
  • a program that should have been able to watch the CD-ROM unit and perform some user defined operation when:
    • a CD-ROM with mp3 is plugged into the CD-ROM unit
    • an AudioCD is plugged into the CD-ROM unit
    • a CD is ejected by pressing the eject button of the CD-ROM unit

5. How I did it?

The first problem was to eject a CD during it was mounted and used. I guessed that I have to look at kernel source code. After I dig a little and after I read in kernel documentation, I found the place in the file /usr/src/linux/drivers/block/ide-cd.h where I have to made some little changes:

[cut]
/* Turning this on will disable the door-locking functionality.
   This is apparently needed for supermount. */

#ifndef NO_DOOR_LOCKING
#define NO_DOOR_LOCKING 1
#endif
[cut]

then I recompiled the kernel. That way, it does not lock the CD while it is mounted. I copied the new kernel into the /boot directory with the name /boot/bzImage-2.2.14-jukebox.

Then I modified /etc/lilo.conf so the system to boot by default using this kernel:

boot=/dev/hda
map=/boot/map
install=/boot/boot.b
prompt
timeout=0
linear
default=linux-jukebox

image=/boot/bzImage-2.2.14-jukebox
        label=linux-jukebox
        read-only
        root=/dev/hda2

image=/boot/vmlinuz-2.2.14-5.0
        label=linux-orig
        read-only
        root=/dev/hda2

Then I ran lilo and I reboot with the new kernel. I testes to see if I can eject a mounted CD and it worked!

After that, all I had to do was to find a program that:

  • on plugged in a CD-ROM disk (with mp3s) into the CD-ROM unit to perform the following steps:
    • to mount the CD
    • to generate a playlist
    • to play randomly the songs from playlist
  • on plugged in an AudioCD into the CD-ROM unit to start the audio player
  • on ejecting a CD to kill the process that play the music, to remove the playlist and to unmount the disc.

After some researches I concluded that I had to use autorun, that can be found in autorun-2.61-1.i386.rpm package included in RedHat Linux 6.2

Basically, autorun is used as follow:

/usr/bin/autorun \
--notify-insert="command_on_inserting_a_cdrom" \
--notify-eject="command_on_ejecting_a_cdrom"\
--cdplayer="command_to_start_an_audio_cd_player"

Autorun has some default values for these actions. Its default values starts some programs from KDE. It is not a part of KDE but it's used by KDE people. After some tests I discovered that autorun from RH 6.2 fail only to start a given audio CD player, so I made a trick: by default it starts /usr/bin/kscd (CD player from KDE), so I replaced that program with a BASH script that started a cd player in console mode.

Because I need to perform many things on every action supported by autorpm, I quickly wrote some scripts in BASH. There is a main script (jukebox) that start/stop the jukebox and two others, one for starting/stopping playing mp3s (jukebox.mp3), and another one for audio CDs (jukebox.audiocd). I put them into /usr/bin directory (atention: I used absolute paths because this scripts was automatically started on boot time, and they have a very limited PATH variable).

Now I had to made jukebox to start automatically on every boot, without any login, so I added the following lines to /etc/rc.d/rc.local file:

# Play a sound to know when system finished to boot
cat /usr/share/sndconfig/sample.au > /dev/audio

# Start jukebox
/usr/bin/jukebox start &

Remember that we don't have any monitor, so I "used" Linus to say "Linux" every time the system boot, so I know the moment when we can start playing music.

6. What problem I had?

During holliday, absolutly no one!

When I made some tests, I saw that audio cd player had some problems: he continous started the same song on every three seconds, so I used a lock file (see jukebox.audiocd). The it was the problem with autorun that I described above.

7. Does is worked?

Absolutly! Our computer was up & running all the time and never crash.

8. The scripts

All you need to do the same is to download the script tarrball from here: jukebox.tgz

The tarball contains:

  • my scripts (in usr/bin/jukebox*) (do not forget about jukebox.kscd)
  • my 2.2.14 kernel which does not lock the CD door, and with support for 100% SB 16 souncard or compatible (mine is ESS 1868), but without modules (in boot)
  • proper lilo.conf with jukebox kernel by default (in etc/lilo.jukebox.conf)
  • what you need to add in /etc/rc.d/rc.local (in etc/rc.d/rc.local.supp)
  • ide-cd.h modified (from 2.2.14 kernel source) that allows ejecting mounted CDs (in usr/src/linux/ide-cd.h)

9. Other notes

Of course that my jukebox.* scripts can be improved. But I work under the presure of time (I do all this things in less than a day) and I don't have time for any further improvments. However, anyone can do any changes he wants. Always is place for better, but now the exam session is comming so I don't have any more free time. Most probable I'll let all in this stage and I'll look for improvments next time I take my computer with me.

10. License

All is under GNU Public License.