Two fine DAE scripts

fine-dae-scripts

Anybody that knows my command line habits, or me in general, knows that my memory could be better. It can be good when I need it to be, however, if I don’t have to remember a thing I’m writing it down. This is why I built my DAE scripts. DAE, which I pronounce as day, is an acronym for Digital Audio Extraction, also known as ripping audio CDs. The scripts are a wrapper for a command that has only a few options yet I have no way to remember the command options that I may not use again for awhile. Hence I created these basic scripts. They are straightforward scripts that just cover the essentials.

(These scripts are only basic wrappers, most of the work is done by the RipIt developer(s)… I thank them very much for their effort.)

How they look

There are two scripts. They are demonstrated here in use, as it is the best way to describe them.

daeme (pronounced like lame) is for MP3s:

daefe

daefe is for MP4s:

daefe

After these steps RipIt does a CDDB query from the Internet (if available) and allows tag editing if desired.

Settings

I bypassed adding a few settings in the script and rather allowed them to be specified in the RipIt configuration file as their values will likely remain the same:

faacopt=-s
dirtemplate="${artist} — ${album}"
playlist=0
eject=1

Audiobooks

The daefe script can also be used for audiobooks. The procedure encodes an entire CD to a file and writes a track/chapter index to another file. The chapter index file can be merged into the audiobook for an integrated audiobook, read ArchWiki:Audiobook for more details.

Download

Both scripts have error checking and I consider them reliable. I have put them in a repository for anyone interested.

That audio I do!

posticon

When I looked at my audio files recently, I realized that that I wanted them organized in a consistent way. As it were naming standards varied, some tags were missing, different encoding types were used… I decided I was gonna Feng Shui my way out of it.

The reorganization department

I decided there should be consistent naming and it should be condensed as much as possible, yet still being understandable.

For the directory format I use $artist—$album. For many people the format is $artist/$album, however, I came to the term that I would have to have about 100 CDs in my collection before the list would get too cumbersome to navigate.

I decided also to do one directory per album. Before I had directory names like Fleetwood Mac — The Very Best of Fleetwood Mac (disc 1), but I discovered it was much tidier to use a base title: Fleetwood Mac — The Very Best of Fleetwood Mac then prepend the disc number to the audio files:

? ls Fleetwood Mac — The Very Best of Fleetwood Mac/
...
1-15 Songbird.m4a
1-16 Big Love (Live, 1997).m4a
1-17 Storms.m4a
2-01 The Chain.m4a
2-02 Don't Stop.m4a
2-03 What Makes You Think You're the One.m4a
...

There is another program that organizes multiple CDs in this fashion and I like the thought behind it.

Just the FAACs

I had been creating high-quality MP3s (256kbps) and just accidentally stumbled into trying MP4s—and was delighted by the difference. Similar bitrates of audio sounded fractionally, but for me, appreciatively better. So I encoded all CDs to .m4a (MPEG-4 audio extension). (I will probably go to loss-free audio format in the future if the gods favor.)

By the way, I think (clearly subjectively) that FAAC (Free Advanced Audio Coding encoder) is great. It mentions in the manual that “it is not up to par with the currently best AAC encoders” but from my semi-proficient audio setup it did well.

I tested encoding with a FAAC at a setting of 320 (~256kbps) versus the iTunes setting of 256kbps. I did find iTunes better. Audiophiles looking for every detail might talk but for me difference could be left alone.

Here is a partially non-scientific (but should be fairly representative) graph of FAAC’s quality settings compared to kilobytes per second:

I can verify for the first and fourth values as I have tested a number of times. The second and third values I got from hydrogen audio. The fifth value is a projected value based from the other values.

A FAAC setting of 150 has been recommended for “casual, non-critical listening”; however, I use FAAC 320 for my tunes and 55 for voice. Though similar bitrates to the iTunes encoder created slightly less quality, the file size reflected too: iTunes 8.4MB, FAAC 7.6MB.)

Softer player detritus

Software audio players that I have used tended to put a some extraneous files in my audio folders. I’ve seen album cover art put here, lyrics, some unnecessary metadata, and hidden folders. I did myself a favor and deleted them out. Nothing should be here but the audio files. If an audio player insists on putting stuff here, I would recommend to their users to file a bug so the developer can remedy it. Some may argue that album playlists should be put here but these I believe belong to saving along with the configuration files.

Book ’em, Danno!

I discovered a nice feature call the audiobook format. Instead of 100 tracks splayed over a directory, or directories, from a audiobook CD, I can reduce this to a reasonable amount (say, one file per disc or even less if I choose). These book formats can also contain chapter indexes so navigating a file is just like navigating a disc. The process isn’t incredibly difficult and I documented it here. If the audio player supports them, it is a nice feature.

Audible, Linux and learning to cope with my error

Update: Since this I’ve learned that Barnes and Noble carry Audiobooks in the MP3 format. To download them though the Windows application OverDrive Media Console is required. Good news is that you can D/L the file and open it through the application so you don’t have to order it through Windows. Thankfully it’s a good program and does it’s job well.

Recently, I decided to get and audiobook to be able to listen to on my MP3 player. I had heard on TV the audible.com commercial that audiobooks could be downloaded and played on my computer or MP3 player. I went to Audible, found the book I wanted and downloaded it. When it started downloading, I noticed the extension was .aa. I hadn’t noticed but below the Download link was a mention of how to import the file to iTunes. The .aa extension is a specially created extension short for Audible Audio and it only works on several types of portable music players that support it. iPods are one, and newer Creative Zen, and SanDisks do too. Having already spent $30 dollars though, I was determined to get this to play on my slightly older MP3 player. Unfortunately, the only way to do this (without spending $20 to $30 on software that removes DRM illegally) is a time-consuming, and somewhat laborious process.

Burn, Burn, Burn… Rip, Rip, Rip

I was a bit thrown off of the MP3 mention:

Saying MP3 player (to me) seems a bit too generic to me and sadly it had me boot up my dusty Windows install :) to be able to start the process. I did bit of research and booting to Windows is necessary – there is no way to convert .aa files in Linux as of yet. I copied my .aa files to the Windows partition, rebooted to Windows, and then installed iTunes. To begin: in iTunes I had to create a new playlist ‘File > New Playlist’, and drag an .aa file to it. I had multiple .aa files so I had to do them separately, one at a time. After that, I did ‘File > Burn Playlist to Disc’, select ‘Gap Between Songs’ as ‘none’, and hit ‘Burn’. This is where the long part of the process takes. For my three part audiobook (three .aa files) the total ~15 hour audiobook spanned 13 discs. I did this for each .aa with a new playlist. I tested a CD after it was done and it played fine but oddly I noticed that iTunes had decided to break the audiobook up into 8 minute tracks – wish it didn’t do. When finished, I decided to rip in Linux. Reboot.

In Linux, Ripit is a good command line tool for ripping CDs.

Lame is required for encoding. Make a new directory for the audiobook. In my case:

mkdir -p ~/Audiobooks/Stephen\ King/Full\ Dark\,\ No\ Stars\ \(Unabridged\)
cd ~/Audiobooks/Stephen\ King/Full\ Dark\,\ No\ Stars\ \(Unabridged\)

And begin burning:

ripit --playlist 0 --bitrate 64 --quality 0 --loop 1 --outputdir ~/Audiobooks/Stephen\ King/Full\ Dark\,\ No\ Stars\ \(Unabridged\)

I did a bit of research on this and for most audiobooks the are encoded in 32bit mono but since some have sound effects, 64bit is the way to go. Also using 64bit helps because a bit of quality will be lost in the conversion. This unfortunately makes the MP3s slightly larger (the original files were about 75MB each, afterward they were around 150) but is really the best choice. The other commands here do: playlist 0 (don’t create a playlist), quality 0 (encode slower for slightly better MP3 quality), loop 1 (will eject disc after rip and prompt for a new one), and outputdir (to specify where to put the ripped folders). Ripit automatically queries the FreeDB database for MP3 tagging (there won’t be any valid entries likely) and there is no way to override it. So for each CD I had to enter into it: not to use a DB entry (0 none of the above); to label with the “Default Album…”; and for genre I just hit enter (none). Ripit burned the CDs into folders named ‘Unknown Artist – Unknown Album’ and was smart enough not to overwrite the folders of the same name and sequenced them. When it was done, I had a list like this:

ls -1
Unknown Artist - Unknown Album
Unknown Artist - Unknown Album 1
Unknown Artist - Unknown Album 10
Unknown Artist - Unknown Album 11
Unknown Artist - Unknown Album 12
Unknown Artist - Unknown Album 2
Unknown Artist - Unknown Album 3
Unknown Artist - Unknown Album 4
Unknown Artist - Unknown Album 5
Unknown Artist - Unknown Album 6
Unknown Artist - Unknown Album 7
Unknown Artist - Unknown Album 8
Unknown Artist - Unknown Album 9

Put it Together, Polish it Up

To be able to put the audiobook back together, I’d have to join the numerous MP3s back together. Here, I choose to use mp3cat. I was a bit unsure which way to go. The best source I could find to do this was this question at stack overflow. I decided to use mp3cat because here it is said that (later on in post by joelhardi) that mp3wrap “inserts its own custom data format in amongst the MP3 frames (the “wrap” part), which causes issues with playback, particularly on iTunes and iPods.” mp3cat pulls the tag (ID3) information out (which leaves only the binary part of the file) and then joins the MP3s together. To install:

wget http://tomclegg.net/software/mp3cat-0.4.tar.gz
tar xvf mp3cat-0.4.tar.gz
cd mp3cat-0.4/
make install
sudo cp mp3cat /usr/local/bin

For my audiobook, part 1 of my audiobook spanned the first folder (0) to folder 4, part 2 from 5-8, and part 3 from 9 to 12. To concatenate the files back together, I’d have to define the folder span of the MP3s to put together. However, because the folders will are not going to be recognized in the correct order (e.g. folder 10 will come after folder 1 [as recognized by the shell]) I had to zero pad them (e.g. …Album 000, …Album 001,…):

mv Unknown\ Artist\ -\ Unknown\ Album/ Unknown\ Artist\ -\ Unknown\ Album\ 0
rename 's/\d+/sprintf("%03d",$&)/e' *
ls -1
Unknown Artist - Unknown Album 000
Unknown Artist - Unknown Album 001
Unknown Artist - Unknown Album 002
...

The rename command here grabs any number and turns it into a it’s three digit equivalent. Since all my folders had numbering at the end of the name this solution worked good in this case. I created a script to concatenate the MP3s with for ease of use if I ever have to do this again. I had help from some people at the Arch Linux forums to help finish this, particularly rockin turtle. Thanks guys!

To use it for example:

mp3cat-multiplefolders 0 4 "01 Part1"

This did exactly as I wanted except for one thing: I learned that the track length information is also part of the binary file. This would cause some MP3 players to report the length incorrectly thinking that the MP3 was an eight minute track instead of the five or so hours that each actually was. To fix this, the only program I could find was MP3 Diags. This is a great tool to repair damaged MP3s with. Unfortunately, it a GUI utility only and I was hoping for a command line one. I just clicked on 4 to fix everything (which was just the track length issue (bc)).

Tag Line and Submit

I searched online for tag information of the audiobook on both the FreeDB and MusicBrainz databases but had no luck. At this point I knew I’d have to create the audiobook information tags (ID3) manually. Originally I used EasyTag but it created a couple issues afterward when I went back and checked it with MP3 Diags, particularly when adding cover art (problems with frames and such). So it looks like its best to use MP3 Diags tag editor as it had all the basic parts I needed. The tag editor was basic but worked nice and I found the only tricky thing was adding cover art (which I had to be copied to the clipboard and pasted in). The only way I could find to put an image to the clipboard was to find the image in Firefox and copy it from there. The only question I have now is if MP3 Diags correctly assigned it as CoverArt as it has no ability to specify it. However, when playing the files in Banshee the CoverArt is show correctly.

Since this audiobook hadn’t been listed in an ID3 database, I thought I’d put it up in case anyone else was crazy enough to do this :). After looking at FreeDB some more, I read in the forums that they didn’t think this was a place for audiobooks and that the FreeDB was geared toward audio CDs. However, MusicBrainz had audiobook listings so I decided to put it there. Originally I had tried to use MusicBrainz’s own application (Picard) to tag the MP3s with but to tag with Picard the original needs to be a CD (the DiscID creator feature requires a CD to be inserted). However, Picard does have a plugin available called “Add cluster as release” that works. I installed it following the instructions, put the audiobook into a cluster, right-clicked the ‘Album’ > Plugin > Add cluster as release, created an account (required to submit), and filled out the form as best as I could:

Finally, I found the audiobook on Amazon and did ‘Relate to URL’ to add coverart. When done I was told that MusicBrainz has a process that puts new entries into a queue for peer review.

Thoughts and Conclusion

All and all the process went smooth so I’m happily listening to my audiobook now. I’m happy with the quality for the MP3s except for one thing: when I reach the length in the track where the segments were joined I can hear a slight dip in volume. Barely noticeable so I’m not too worried. I also would have liked to be able to fix the track length error from the command line and enter ID3 information from there as well. If anyone knows of anything, I’d appreciate hearing from you. And finally, if anyone knows if it is possible to get audiobooks in MP3 format that would help me quite a bit.

Ecasound to mix sound

There are a good number of audio editors for Linux: Audacity, ReZound and Ardour, Sweep, glame, and ecasound (command-line) to name a few. I have limited disk space, and although Audacity seems to be the champ of Linux audio editing, I initially decided to try Sweep because my editing needs were very basic.

I installed Sweep and began mixing together. Sweep didn’t have an import option so I had to load two windows and copy and paste the track in. Doing this took an extraordinary long time. Also Sweep just seems unpolished. Sweep’s multi-taking is poor and rendered my system to a halt making doing any other activities while it processed the mp3s impossible. On top of these, Sweep takes an huge amount of temporary disk space so I decided to try ecasound.

ecasound

I looked a bit though portage and didn’t see a command line audio editor. Recently though, I learned there is one: ecasound.

ecasound has few dependencies and support for most major formats. Use of ecasound with mp3 will require mpg321 or mpg123 for input and lame for output.

I mixed two audio streams both 15 minutes with Sweep and ecasound. Sweep took several hours and ecasound did it in 15 minutes. ecasound does very well with multitasking allowing me to browse the web and do several other tasks.

Mixing tracks requires a simple command line. -a defines audio track and the number. Numerous tracks are possible not just to two listed here.

ecasound -a:1 -i audio1.mp3 -a:2 -i audio2.mp3 -a:all -o audio-mix.mp3

To Mixing tracks with an offset files will need to be made. Create .ewf-files like this:

vim part2.ewf
source = vocals.wav
offset = 5.000

vim part3.wav
source = vocals.wav
offset = 10.000

Then mix them:

ecasound -a:1 -i song.wav -a:2 -i vocals.wav -a:3 -i part2.ewf -a:4 -i part3.ewf ... -a:all -o out.wav

Cut a file (-t=seconds)

ecasound -i bigfile.wav -o part1.wav -t:370.0