I thought I might try to start writing about what coding I’m doing, without going in to a lot of detail, but just to record my day-to-day struggles with this programming business.
Updating Chapter Master
At the moment, my main challenge is trying to get out another version of my shareware software Chapter Master.
It’s going on for a year since the last release, and at that stage the software, while working well for most people, was still in my mind a little experimental. Certainly time to consolidate what I have learned since the last release, add some requested features, and some ideas of my own.
The purpose of the software is to create or manipulate ‘chapter stops’ and optionally ‘chapter images’ in AAC files (*.m4b or *.mp4 extension). These are the files treated as audiobooks or ‘enhanced podcasts’ by Apple’s iTunes and the iPod. Chapter stops create points within the file to which the user can easily navigate. Ideally, of course, one would position these chapter stops at the exact times in the audiobook where the narrator says “Chapter Five” or “Book Three” or “Part Two”. The software will let you do that manually, but no way can I imagine what artificial intelligence would be required for the software to automatically find such points, though it has been requested.
My companion software MarkAble will allow you to merge together a bunch of source files and insert chapter stops at the beginning of each new file. Sometimes the source files are such that these points are at the logical breaks in the book. Chapter Master lets you edit these existing chapter stops to your heart’s content.
Most of my programming struggles over the last week, though, have been to do with trying to pull out – or create – the ‘cover art’ which iTunes can associate with any audio file.
There are two types of image which can be embedded in an AAC file which has been through, or is going to be used by, iTunes and the iPod. The first is the above-mentioned ‘cover art’, which is what shows up in the cover flow mode of iTunes, or in its grid view. The second type of image is embedded along with the audio data. These images can change at different times as the audio is played, and are what gives ‘enhanced podcasts’ some of their charm.
Chapter Master originally only handled the latter type of image, and some users found it puzzling that the ‘cover art’ didn’t turn up in Chapter Master. So most of my efforts over the last week or so have been to alter the program so that it can manipulate either kind of image. In the case of cover art, this meant that I had to parse and unpack the iTunes meta data, which includes the cover art images.
The AAC file structure is based on the structure Apple originally developed for QuickTime, and consists of ‘atoms’ which can be nested (that is, atoms can contain other atoms). Each atom starts with a data length (a 32-bit unsigned integer) and an atom type indicator which can be read as a 4-character ASCII string.
The iTunes meta data is stored in a ‘user data atom’, type-string ‘udta’. Now this type of atom can contain anything the encoder software desires – which means one has to be careful to check that it contains data structured in the iTunes manner. Apple structure their udta atom with yet another atom hierarchy containing the meta data and any images.
I managed to decode all this without too much trouble if the meta data atom already existed. But I also wanted to allow people to add a new cover art image in Chapter Master, and fill in any meta data, if it didn’t already exist. This meant that I had to create my own ‘fake’ meta data atom and trick iTunes into recognizing it. This proved considerably trickier than I had anticipated, but I think I have managed it. It took a lot of careful working with a hexadecimal editor (I use the excellent Hex Workshop), lots of trial and error, and lots of thinking. Anyway, it looks like I got there.
One trick I will pass on to others is that it seems that iTunes expects the udta meta data atom to be the LAST atom inside the ‘moov’ (or ‘movie’) atom. If it’s not in that location, it’s ignored.
Other features I’ve added include the ability to add titles to an image, the ability to do sophisticated search/replace on chapter text, and multi-selection ability in the chapter list.
I’ll be releasing the new version of Chapter Master (1.2.0) as a beta for a while, as so much has changed.