CD Ripping Workflow

I was requested by a client to provide a workflow for encoding music for their online store. They needed to produce MP3s for preview and download. After searching for a commercial solution, I found that there was really no usable solution.

At this point I began searching for an open source project that could be utilized from a script. Ultimately, I came up with the following solution. For the following solution, I was working on OS 10.4.8 with Xcode version 2.2.1.

LAME

LAME is a open source MP3 encoding library utilized by many applications. I used the latest version, v3.97 available from their site. LAME

The build did not require any modifications to the source code.

	cd /path/to/lame-3.97
	./configure
	make
	sudo make install

The installation of lame is required before building SoX. The default installation will place files in /usr/local.

SoX - Sound eXchange

SoX is a utility for sound file conversion for a variety of formats. By installing LAME first, it enables SoX to directly encode to MP3 from the CD. I used the latest version, v13.0.0 available from their site. SoX - Sound eXchange

The SoX build also did not require any modifications to the source code.

	cd /path/to/sox-13.0.0
	./configure
	make
	sudo make install

The default installation will place files in /usr/local.

Automator

Automator is a tool for creating workflows on the Mac OS, new to OS 10.4. Although the following can be replicated in AppleScript, I have opted to use Automator at this time for simplicity.

The first step in the workflow is to "Ask for Finder Items". Specify "Folders" as the type.

Next, use "Get Folder Contents" to list all of the items in that folder. This assumes that the user has selected a CD and there will only be audio files. I'm certain that better error checking would be a nice addition, however, this would require a bit of AppleScript to filter.

The last step is to "Run Shell Script". This is where the bulk of the work is done. I used the following script:

	path=~/Desktop/out
	preview="$path"/preview
	full="$path"/full
	if [ ! -d "$path" ]; then
		mkdir "$path"
	fi
	if [ ! -d "$preview" ]; then
		mkdir "$preview"
	fi
	if [ ! -d "$full" ]; then
		mkdir "$full"
	fi
	
	for f in "$@"
	do
		fullout="$full"/`basename "$f" .aiff`.mp3
		previewout="$preview"/`basename "$f" .aiff`.mp3
		/usr/local/bin/sox "$f" "$fullout"
		/usr/local/bin/sox "$f" "$previewout" trim 0 00:00:30.0 fade p 0 27 3
	done

The above simply creates a directory to place the MP3s. The full MP3s are processed first. The previews are processed by triming the file down to 30 Seconds for the preview. A 3 second parabolic fade is applied, and the resulting file is encoded as an MP3.

CDID - FreeDB

By default, the MacOS will name the CD as "Audio CD" and all tracks as "# Audio Track.aiff". If you allow iTunes to query GraceNote for CD info, the CD will appear on your desktop with the title and track names showing appropriately.

However, GraceNote is a commercial company that has a licensing fee for applications using their database. FreeDB, on the otherhand, is built by the some of the original developers, and began at the start of the split from CDDB. I have preliminarily tested building discid to generate the disc id information to submit to FreeDB.

CDID requires a modification of the Makefile to build. I made the following changes:

	DESTDIR=/usr/local
	VPATH=src/mac

I also removed the -D flag from the install section:

	install: discid
		install $(VPATH)/discid $(DESTDIR)/bin/discid

At this point I ran the following commands:

	cd /path/to/discid-0.1.3
	make
	sudo make install

At some point I will script the queries for the FreeDB lookup to complete the naming portion of the script.