Saturday 3 December 2011

Moar paranoia: using lower CD speeds for more reliable ripping

paranoia: "Use your CDROM drive to read audio tracks.... and have it actually work right!"

cdparanoia is fine. It's smart enough to work around my (and probably your) imperfect CD drives. But if, like me, you're still curious...

"readom" (nee readcd) has this interesting feature:
-c2scan

              Scans  the  whole  CD  or  the  range specified by the sectors=range for C2
              errors. C2 errors are errors that are uncorrectable after the second  stage
              of  the  24/28  + 28/32 Reed Solomon correction system at audio level (2352
              bytes sector size). If an audio CD has C2 errors, interpolation  is  needed
              to  hide  the  errors. If a data CD has C2 errors, these errors are in most
              cases corrected by the ECC/EDC code that makes 2352 bytes out of 2048  data
              bytes.  The ECC/EDC code should be able to correct about 100 C2 error bytes
              per sector.

              If you find C2 errors you may want to reduce the  speed  using  the  speed=
              option as C2 errors may be a result of dynamic unbalance on the medium.
Very educational, but "speed=" isn't quite reliable.
$ sudo eject; sudo eject -t; sudo readom dev=/dev/cdrom -c2scan speed=4
Read  speed:     0 kB/s (CD   0x, DVD  0x).
Write speed:  9173 kB/s (CD  52x, DVD  6x).
In this case, it looks like readom has set the speed before the drive is ready. It claims this nonsensical "Read speed: 0 kb/s", and then goes ahead to read at full speed. On my drive, using the full 52x with -c2scan causes hard errors (which can cause a very noticeable delay). So let's baby-sit readom and insert a small delay.
$ sudo eject; sudo eject -t; sleep 2; sudo readom dev=/dev/cdrom -c2scan speed=4
Read  speed:  1764 kB/s (CD  10x, DVD  1x).
Write speed:  9173 kB/s (CD  52x, DVD  6x).
And again, the drive spins up to full washing-machine-imitation speed, producing the same errors.

What's happening here is a race condition. When I put a CD in the drive, it automatically spins up, flashing the activity light on the front of the drive. This start-up procedure is racing with readom. In the second case above, readom fails to limit the speed, and reads back the speed used during the start-up procedure. This is either a hardware- or kernel-triggered process. It happens even when udev isn't running.

What we need to do is watch the drive after putting the disk in, and only start readom when the light has stopped flashing. So if you still want to use a script, you can replace the "sleep 2" delay with "read", and hit enter when you think the drive is ready.

In my test, the highest reliable speed seemed to be 24x.
$ sudo eject; sudo eject -t; read; sudo readom dev=/dev/cdrom -c2scan speed=24
Read  speed:  4234 kB/s (CD  24x, DVD  3x).
Write speed:  4234 kB/s (CD  24x, DVD  3x).
Capacity: 256032 Blocks = 512064 kBytes = 500 MBytes = 524 prMB
Sectorsize: 2048 Bytes
Copy from SCSI (0,1,0) disk to file '/dev/null'
end:    256032
addr:   256032 cnt: 18
Time total: 231.759sec
Read 661582.69 kB at 2854.6 kB/sec.
Total of 0 hard read errors.
C2 errors total: 0 bytes in 0 sectors on disk
C2 errors rate: 0.000000% 
C2 errors on worst sector: 0, sectors with 100+ C2 errors: 0

That still doesn't make cdda2wav reliable on my system. However, it does seem that "cdparanoia -S 24" is less noisy in terms of error markers, strange delays, and the worrying washing-machine sound you get when the drive gets up to full speed.

Sunday 6 November 2011

Fixing up XML well-formedness

You have a lot of text marked up as XML (most likely XHTML). You've edited it by hand, and as a result it's chock-full of errors. Mainly, it's missing closing-tags (or, when you meant to type a closing-tag, you actually typed an opening-tag).

It's easy to find the errors using xmllint. But if you want to fix them, that's a bit cumbersome.

I found emacs worked very nicely. You don't have to use emacs-specific keyboard shortcuts (much :); the current version has friendly menus and standard Gtk dialogues. Just remember not to try and use normal keyboard shortcuts like ctrl-s to save. (Or Alt to bring up menus. If you're addicted to standard keyboard shortcuts, you can use F10 and the arrow keys - this is a less well known standard in GNOME and other CDE/CUA-compatibles).

If you don't see an XML menu, you need to switch to XML mode manually.

M-x xml-mode

(M for "meta", which by default will be the Alt key. So Alt-x, then type "xml-mode" and hit Enter).


Then look in the XML menu. Note the "Next error" command - exactly what we want. Conveniently, if you look to the right, you'll see it's keyboard shortcut: C-c C-n. I.e. Ctrl-c, followed by Ctrl-n. You can keep Ctrl pressed down for both, or not, as you wish.


I used XML->Set Schema->Any Well-formed XML, for a first-pass checking for mismatched tags etc, without bothering about validity against the specific DTD.


You can quickly add missing close-tags, by typing "<", and then C-Enter for auto-completion. (I was obscurely amused to see M-Tab listed as an alternative shortcut. If you don't get the joke, try it yourself in any popular desktop environment; it doesn't do any harm. I didn't realize it myself until I tried it). You may also want Options->Line Wrapping for this buffer->Word Wrap.


I originally tried xmlcopyeditor. In order to change an open-tag to a close-tag, you have to delete the open-tag and then create a fresh close tag. It's not that this takes too long - backspace/delete kills the whole tag at once, and then "

Enabling the Orca Screen Reader manually

If you log into GNOME, you can use Control Center / System Settings to enable Orca. I've played with Orca in the past, and found it very impressive.

Yesterday, I used it to read out a plain text ebook in gedit. But my netbook didn't have room for a GNOME environment as well as my default KDE.

Here's how I enabled Orca for GNOME programs, despite not using a GNOME desktop.


0. Install orca. (ubuntu package gnome-orca). You may also need to make sure you have a speech synthesizer installed, eg. espeak


1. Enable accessibility.

If you don't have the GNOME control center installed, it's still possible to do this manually.

I used gconf-editor to enable the setting /desktop/gnome/interface/accessibility. I suspect that's a bit out of date though. I've also seen this suggested:

gsettings set org.gnome.desktop.interface toolkit-accessibility true


2. export GTK_MODULES=libgail

You need to run this command from a terminal, and then run your GNOME applications from the same terminal.

If you're logged into GNOME, this part is taken care of automatically.

Saturday 24 September 2011

Preferred applications

It's interesting to try and remember why we have certain preferences. Particularly in software where those reasons can quickly become outdated.
Firefox web browser
  • Bookmarks ("favourites" in IE), with tags, synchronization/on-line backups, and just generally designed to scale to 1000s of bookmarks. (In theory Xmarks provides sync for all browsers, but the Firefox plugin is slightly too intrusive / buggy / un-supported).
  • NoScript. Other browsers don't provide enough extensibility to block scripts securely. NoScript also has a surprisingly large number of protections that work even after enabling scripts. It also includes a FlashBlock-like option. Ars Technica whiners are advised that the lack of click-to-play is a technical limitation of the Flash plugin; not FlashBlock extensions; that a FlashBlock enabled browser by definition still supports Flash; and if you want a fallback to static images, you need to code that behaviour yourself in JS.
  • AdBlock Plus - largely redundant with NoScript, but it makes me much happier clicking on random links. (Yes, I do whitelist sites I visit more than once. Unfortunately, most ad-serving sites also rely on JS, which I'm much more cautious about.)
Thunderbird email client
IMAP IDLE - which KMail lacked for a long time. The UI is flexible enough for small screens - unlike Evolution. The fancy indexing is very easy to disable if necessary. I get the impression KMail could work just as well, but it wouldn't be any better, and it's nice to have a UI theme that matches the web browser.
Linux
Preferably debian-based.
KDE
The bloat I don't use is starting to annoy me, but it's certainly convenient. KWin has nice fullscreen/no-border menuitems that are essential for the original netbooks, and there's a very convenient option to enable them automatically. LXDE looks nice and light, but the "run program" dialog is broken in Lubuntu :(. Unity-qt might be interesting once it's released (Ubuntu 11.10)... I'm not happy with at least one of the design choices, but my main reservation is about whether I'd be able to replicate all the full-screen options KDE gives me.
Kate, KDE advanced text editor
The main advantage of Kate is the sidebar, which is great for flicking between multiple files. At the same time, I can strip down the UI to get a nice clean fullscreen mode, either for small screens or just to minimize distraction.
Konsole
Other terminal emulators seem to be a bit sniffy about resizing - Konsole will accept however many pixels you want, and leave a sliver of padding inside the window.
Amarok music player
I went off Amarok for a while and just used mplayer, but now it has gapless playback again, and it scrobbles, which are both nice to have.