I got a 40GB iPod a few weeks ago. I have my entire CD collection (~500 CDs) ripped and encoded with EAC (secure mode) and LAME (–alt-preset standard). This gives me VBR MP3s with a bitrate averaging about 190kbps.
Unfortunately, unlike every other mp3 player I’ve used (Winamp, WMP, RCA Lyra, Rio PMP500, iTunes itself, you name it), the iPod cannot correctly calculate the length of my VBR tracks. I get 30 seconds or more of silence after nearly every track. Occasionally, I also get a track that cuts off prematurely.
I did discover that if I set the stop time manually in iTunes to 1 millisecond less than the track length (it won’t let you set it to the exact end of the track length), it plays to completion properly without any additional silence or cutoff on my iPod.
So I wrote a small hack to parse and update my “iTunes 4 Music Library.itl” file so it sets the stop time on every track to its length. (I also set it to start 1ms into the track just in case) This was done in elisp and can be found in the extended entry of this blog entry in case anyone wants to use it. I imagine that the union of the set of iPod users (a highly user-friendly device) and the set Emacs hackers (a highly user-hostile editor) approaches zero. But here it is for that small cadre of you. I’d be glad to help anyone else a) get Emacs set up to use this or b) by updating their iTunes library file with my script (at their own risk).
(defun read-long (a-string)
(+
(string-to-char (substring a-string 3 4))
(* (string-to-char (substring a-string 2 3)) 256)
(* (string-to-char (substring a-string 1 2)) 65536)
(* (string-to-char (substring a-string 0 1)) 16777216)))
(defun write-long (an-integer)
(concat
(list (lsh an-integer -24)
(lsh (logand 16711680 an-integer) -16)
(lsh (logand 65280 an-integer) -8)
(logand 255 an-integer))))
(defun fix-itunes ()
(interactive)
(goto-char 0)
(let ((i 0))
(while (search-forward "htim\000" nil t)
(setq i (1+ i))
(forward-char 35)
(setq m1 (point-marker))
(forward-char 4)
(setq m2 (point-marker))
(setq track-length (buffer-substring m1 m2))
(forward-char 24)
(delete-char 4)
(insert "\x00\x00\x00\x01")
(delete-char 4)
(insert track-length))
(message "%s" i)))







