bloovis.com

02/29/2008 (6:04 pm)

Fixing jerky video in DVDs

Filed under: linux, mepis, pclinuxos, software ::

On my ThinkPad A30p, watching a DVD with Kaffeine often results in very uneven, jerky video. This has been a problem with both PCLinuxOS 2007 and Mepis 6.5. The cause appears to be an obscure kernel bug that disables DMA on the CD-ROM drive. The fix is to run the following command as root after Kaffeine has started:

hdparm -d1 /dev/cdrom

It doesn’t work to enable DMA before starting Kaffeine (it’s enabled by default when the system boots). It has to be done after Kaffeine has opened the DVD and started to display its menus, and it has to be done with each new DVD. It’s not a big nuisance, but you can create an icon on the desktop to make it a little easier:

  • As root, edit /etc/sudoers and add a line like the following:
    bloovis localhost = NOPASSWD: /sbin/hdparm
    Be sure to change bloovis to your actual user name.
  • Create a desktop “link to application”, where the command to run is:
    sudo hdparm -d1 /dev/cdrom

Curiously, this problem doesn’t occur on my other Thinkpads (A21m, T40) even when running the same versions of Linux.

02/27/2008 (6:33 am)

Replacing a ThinkPad A30p system board

Filed under: hardware, thinkpad ::

Last year my ThinkPad A30p started failing to charge its battery, after I’d left the machine on the shelf for a few months. I thought that maybe the battery had died from neglect, but a replacement battery purchased on eBay also had the same problem. So the system board (AKA motherboard) seemed to be at fault. But at least the machine worked when it was connected to AC power. Then a month or so later, it powered off spontaneously after 15 minutes of use, and after that it was completely dead.

I took the machine to a laptop repair shop in Santa Clara that advertises heavily on eBay. After a month and a half of waiting, I finally called them back. Apparently they had written down my phone number incorrectly and had left a message with the wrong phone number. They told me they couldn’t repair the system board or find a replacement, so there was no charge for service. I showed up at the shop a week later to pick up the machine. I was kept waiting in the rather dirty lobby for 40 minutes before a technician brought out the machine.

I was puzzled by the long wait, but I figured it out later: apparently, the technician had to put the machine back together hastily to return it to me. A week later, when I took the machine apart to replace the system board with one I had bought on eBay, I discovered the following problems:

  • There were at least a dozen screws missing, including all the screws on the CPU fan assembly.
  • The removal lever on the floppy drive had been installed incorrectly, leaving the floppy drive jammed in place.
  • The “keyboard CRU”, an insulating support device that fits between the keyboard and system board, was missing.
  • One of the two wi-fi antenna wires coming from the LCD had been cut.
  • The PCMCIA assembly was not plugged all the way into its connector on the system board.

The moral of this sad tale: do all the work yourself. This turned out not to be as difficult as I had imagined. IBM’s service manuals, available online, are excellent, and have detailed drawings, instructions, and parts lists. Replacing the motherboard was tedious, because it involved removing just about every other component in the machine first, but it was a straightforward task. I spent three hours on the job because I had never done this kind of repair before. The hardest part was unjamming the floppy drive; I managed to get it out after removing the keyboard bezel, by lifting the drive up and distorting its enclosing Ultrabay cage slightly, while simultaneously pulling the drive out. When I reassembled the machine, I made sure the floppy drive’s removal lever was hooked up correctly.

My efforts were successful: the cheap ($30) system board I bought on eBay, which had been advertised as being in an unknown and non-guaranteed condition, works perfectly. Mepis Linux 6.5 (which I’d installed just before the machine died) booted with no problems. Even the wi-fi, about which I was worried because of the cut antenna cable, is fine (I’m typing this using the repaired machine on a wi-fi connection).

02/22/2008 (9:26 pm)

Free music formats

Filed under: ipod, linux, music, ruby, software, treo ::

Playing music directly from CDs is, like, so last millennium. I don’t even own a CD player any more, unless a laptop with a CD drive counts. I do all my listening now via a 4th-generation iPod and a Treo 700p.

The problem is that most popular music file formats, particularly MP3, are encumbered by patents. The owners of these patents require license fees if you use files in these formats for commercial purposes, or make them available for downloading via the internet, or copy them to a physical medium like a CD — essentially, you have to pay protection money for any purpose except private use in the home.

Because the legality of patented file formats is questionable for Linux users, I decided to stop using these formats altogether. Fortunately, there are free formats that work just fine: FLAC (a lossless format), and Ogg Vorbis (a lossy format conceptually similar to MP3). My fourth generation iPod didn’t support these formats, but replacing the iPod’s firmware with Rockbox fixed that problem. The commercial Pocket Tunes software for the Treo also plays Ogg Vorbis files.

So now the interesting technical problem was to convert my CD collection to digital files for use on the computer and my two playback devices. My first two attempts at this were failures because I mistakenly chose to rip the CDs initially to Ogg Vorbis and MP3. This was a mistake because these formats are lossy, and some audio fidelity is lost in the conversion process. I could hear the loss in fidelity when comparing a CD of the Brahms First Symphony with an Ogg Vorbis file created with -q3 (equivalent to MP3 at 128Kbps). The opening bars of this symphony are very thick, and the Vorbis file sounded muddy compared with the CD. Increasing the Ogg Vorbis quality level to -q6 cleared up the muddiness, but I realized that I need to start from scratch with the ripping process.

Now my strategy is to first rip CDs to FLAC files. FLAC is a lossless format, so these files are, in essence, an exact copy of the music on the CD. FLAC is quite bulky, anywhere from three to six times the size of an Ogg Vorbis -q6 file of the same recording. But the FLAC files only need to live on the ThinkPad, not on the iPod or the Treo. When the ThinkPad disk fills up, I back up the FLAC files to an external USB disk, then delete them from the ThinkPad disk. I’m not too worried about the lack of redundancy here because the CDs act as the ultimate backup.

Once I have the FLAC files, I then transcode them to whatever lossy format I need for playback, typically Ogg Vorbis. As mentioned earlier, I use quality level -q6 for this step, because I find it produces results that, to my ears, are nearly indistinguishable from the original CD.

The workflow for these steps (ripping, tagging, transcoding, syncing) was not so easy at first. I was using GUI tools like grip, but as with nearly all GUIs, these tools required a large amount of manual labor: filling out forms, clicking buttons, and so forth. The problem was particularly annoying when I had ripped several albums and wanted to convert them all at once to Ogg Vorbis.

To make the process of ripping and tagging more automatic, I invented an album description file format, and wrote some Ruby scripts that use these “album files”, as I call them. Album files are simple text files that contain the artist, album title, genre, date, and track names. Here’s a hypothetical album file:

Artist=Brahms
Album=Piano Works - Radu Lupu
Genre=Classical
Date=1970
Rhapsody in B minor Op. 79 #1
Rhapsody in G minor Op. 79 #2
Intermezzo in E flat Op. 117 #1
...

The first step in ripping a CD is to create an album file for it. There are several online databases of track information that can be used; I use freedb.org. The script cdmakealbum reads the track data from a CD, queries freedb.org for a matching record, and writes a corresponding album file to standard output. I usually hand-edit the resulting album files to correct mistakes or to suit my aesthetic and organizational preferences.

The second step is to rip the CD to FLAC files and tag them based on the information in the album file. The script ripalbum does this. It keeps the files separate by using a two-level directory hierarchy (artist name, album name).

The third step is to trancode the FLAC files to Ogg Vorbis. The script flac2ogg recursively walks the FLAC directory tree and creates Ogg Vorbis files in a separate Ogg directory. The script is smart enough to skip files that have already been converted.

The final step is to copy the converted Ogg Vorbis files to the iPod. Because the iPod runs Rockbox, it’s a simple matter of using rsync to copy a directory on the laptop to a directory on the iPod. The script syncipod does this, after first running flac2ogg (thus eliminating the need for the separate transcoding step described in the previous paragraph).

While this might seem like an awful amount of work, it’s actually quite fast. The lengthiest part of the process is hand-editing the album files; once that’s done, the scripts can run unattended.

Another advantage of the scripts is that some of them take an optional parameter that tells them to pause when the CPU temperature exceeds a certain level. This prevents my flaky ThinkPad T40 from crashing when it gets too hot (which it can do during the very CPU-intensive transcoding process).

02/16/2008 (12:13 pm)

Fixing DVD audio sync problem in Kaffeine

Filed under: linux, mepis, pclinuxos, software ::

Both PCLinuxOS 2006 and Mepis 6.5 come with a wonderful media player called Kaffeine. I especially like being able to customize the toolbars. I’ve added buttons to go backwards and forwards by 20 seconds, which is great for those times when you miss some important bit of dialog.

But Kaffeine, as shipped with these two older versions of Linux, has a serious problem when viewing DVDs: the sound is not synchronized with the video, and appears to be off by as much as a quarter of a second. There is a control for adjusting the sync, but it’s difficult to get just right and it requires fiddling with each new DVD.

After the usual poking about with Google, I discovered that the problem is due to a bug in the underlying video engine, Xine, and in particular, a library called libxine. The bug was present in version 1.14 of the library as shipped with these two distros, and fixed in version 1.16. So the solution was to download the source for the library and build it myself.

I found the source for libxine on the xine download page. The file I downloaded, xine-lib-1.1.4.tar.bz2, is no longer available, but I would guess that later versions would also work. The numbering scheme is confusing; version 1.1.4 of the source is used to build version 1.16 of the binary library.

Once I had the source code, I unpacked it and built and installed the library using the following commands:

tar xvfj xine-lib-1.1.4.tar.bz2
cd xine-lib-1.1.4
./configure --prefix=/usr
make
make install # run this as root

After that, the audio sync problem was gone.

On both of these systems, I had to install some X11 development packages (header files and libraries) before libxine would build.  I have forgotten exactly which packages these were, but clues can be gotten by looking at the compiler error messages, and seeing which header files are missing.  I installed these extra packages from synaptic, the standard package management program on both systems.

02/16/2008 (8:28 am)

ThinkPad Reliability

Filed under: hardware, linux, thinkpad ::

(Note: What follows is purely anecdotal, personal experience. Don’t draw any hard-and-fast conclusions.)

I own four IBM ThinkPads now:

  • 380Z: 233 MHz, 96 MB RAM, 4GB disk, 1024×768 screen. Purchased used in 1999.
  • A21m: 750 MHz, 512 MB RAM, 40GB disk, 1024×768 screen. Purchased new in 2001.
  • A30p: 1.2 GHz, 512 MB RAM, 60GB disk, incredible 1600×1200 screen. Purchased used in 2005.
  • T40: 1.6 GHz, 1GB RAM, 80GB disk, 1400×1050 screen. Castoff from son, received in 2006.

The two older machines have been very reliable. The only problem I’ve had with them was that the disk in the A21m got very noisy after a couple of years, and I replaced it to keep my sanity. The A21m still runs a relatively recent Linux (PCLinuxOS 2006) quite nicely, and I still use it to watch DVDs and as my emergency backup machine when the T40 is being flaky (see below). The 380Z is too old to run anything other than Damn Small Linux.

The two newer machines have been much more problematic.

After a year or so, the hard disk in the A30p started reporting errors when it warmed up; I replaced the disk and all was well. A few months later, the A30p would no longer charge its battery. A replacement battery didn’t help. A couple of months later the machine started powering off after 15 minutes of use, and soon afterwards refused to power on at all. A local laptop repair service was unable to fix the problem. Earlier this week I ordered a cheap replacement motherboard of unknown condition from an eBay store; I’ll report back when I’ve installed it.

The T40 is my daily use machine, but its hardware is frustratingly flaky. My son warned me that the machine crashed under Windows XP doing heavy video work, and that the Atheros wireless card was flaky. He was right, and the machine has the same problems on Linux. When watching DVDs or big Flash videos, the screen will go blank and the machine will lock up and refuse to reboot until it’s cooled down for a few minutes. The problem is worse when the machine is hot; I was able to get it crash by doing a kernel compile in a terminal window while scrolling in Firefox.

I poked about on the web and found discussions in which other T4x owners complained about exactly the same problem. It seems that the BGA mounting method used to solder the video chip to the motherboard is not reliable on these machines, and the chip contacts fail when the machine heats up or is flexed. Because the problem seems to be inherent in the design of the T4x series, I have decided not to go to the trouble of taking it in for repair or replacing the motherboard, which could be quite costly.

The Atheros wireless card in the T40 is unreliable as well. After some amount of time, it will drop the connection and I’ll have to restart it manually. It’s unpredictable but seems worse when it’s warm.

The T40 is a lovely machine. It’s fairly powerful and lightweight, and it runs Linux beautifully, but I need something that can be used as a desktop replacement machine for all purposes, not just a portable email device. If I can’t get the A30p with its wonderful display working again, I’ll start looking for a replacement for the T40. In the meantime, the good old A21m will provide service where the T40 falls down.

02/14/2008 (8:55 pm)

Seagate FreeAgent spindown fix

Filed under: hardware, linux ::

A few months back I bought a Seagate FreeAgent external USB hard disk with 320GB of space. The intent was to use it as a backup device for my ThinkPads, all of which run Linux. Formatting the drive for ext3 was no problem. I started my first backup one night and went to bed. When I woke up the next morning, I couldn’t access the drive; it appeared to have spun down due to inactivity. After some Google searching, I found a solution here. Quick summary: run the following command as root the first time you connect the drive:

 sdparm --clear STANDBY -6 /dev/sda

This turns off the drive’s idle timeout, and it appears to be a sticky setting that survives power-off.

Adjust the device name for your particular system. You can look at /var/log/messages for clues if your desktop icons aren’t being helpful.

02/12/2008 (5:08 am)

Why?

Filed under: Uncategorized ::

For several years I’ve been keeping a LiveJournal blog because LJ’s social networking features make it convenient to keep up to date with friends. But I also wanted to have a place to record discoveries and thoughts on subjects of little interest to my LJ friends, such as Linux and programming languages. So I’ve created this blog for that purpose.

I’ve also been using Flickr for photo storage, but I never found its social networking features as useful or interesting as LJ’s. Then right around the time that Microsoft announced its desire to swallow Yahoo! (and Flickr), my “pro” membership expired. As a result, many of my photos and albums disappeared, and annoying ads reappeared. So it seemed like a good time to abandon Flickr and create my own photo gallery.