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.