Digital Audio Extraction from Emacs

Triple Threat
SATA Multilane Connector

So my CD ripping situation is that I put a CD into the CD reading thing there (more about that in a thrilling later blog article), hit a key in Emacs, slap a CD cover onto the scanner, hit another key in Emacs to say that the format is (usually RET), and then inspect the CDDB data that Emacs presents me with, and then I `C-c C-c’, and then I repeat. Since I have three CD players, I can do three CDs in parallel.  The time to process one CD is about two minutes, but with the parallelism going on, I can usually process about twenty CDs in ten minutes.  (Unless the CDDB info is missing and I have to type stuff in.)

I started on this journey in 1997, when mp3s first became viable.  So over the years, I’ve ripped CDs as I bought them.  The earliest mp3-encoded albums started sounding pretty crappy to me, since the early mp3 encoders were pretty crappy.  By 2007, disks had gotten so cheap that it was viable to store the music in a lossless format, so I decided to re-rip them all and store the music in flac.

Now, I have around 4K CDs.  Ripping them all in the traditional, sequential way would just take too long.  I don’t really deal well with repetetive, boring, manual tasks.  And since I had ripped all these CDs before, all the data was already in freedb, so it would be a totally mindless manual job.

So I bought the Addonics cabinet seen above, which has a SATA multilane connector, and put three DVD readers into it.  The only problem in getting it to work reliably was that since all the readers were identical (I mean totally), and the SATA cabinet would bring them up in random order, the poor Linux udev system would name them /dev/scdX at random.  So I would never know how to address the top one until after trying 0, 1, 2.

Until I came up with the brilliant idea of uploading different versions of the available Optiarc firmware on each DVD reader.  They worked just as well with any firmware, but the firmware versions allowed me to create udev rules to differentiate.

scsi 7:0:0:0: CD-ROM            Optiarc  DVD RW AD-7170S  1.02 PQ: 0 ANSI: 5
scsi 5:0:0:0: CD-ROM            Optiarc  DVD RW AD-7170S  1.00 PQ: 0 ANSI: 5
scsi 6:0:0:0: CD-ROM            Optiarc  DVD RW AD-7170S  1.03 PQ: 0 ANSI: 5

With the 3-way parallel ripping setup I think I did all 4K over four nights, if I remember correctly.  While listening to music very loudly, and watching some tv series on DVD (Smallville?), and being totally shit-faced drunk.

Ah, fun times.  At least I think it was fun.  I can’t really remember, for some reason or other.

Anyway, here’s the source code for the Emacs parallel DAE interface.

Editing Sound Files in Emacs

Emacs PCM Editing

I buy quite a lot of vinyl still.  And the hipsterish hipsters have started releasing things on tape, since vinyl is obviously too mainstream.  (I’m wondering when 78s will be making a comeback.)  So to listen to this music I need to sample it and then convert it to flac.

That’s trivial enough since I have a very nice DA, but the main issue is editing the music after sampling it.  I have, perhaps needless to say at this point, written an Emacs mode to do this.

As you can see, the mode is pretty self-explanatory.  It shows the wave forms, and you can zoom and set break points, and split the file up into pieces.  (Then name the files after querying freedb, possibly.)

The mode consist of one Emacs Lisp file and two C programs.  The first, summarize, goes through the PCM file and outputs the “energy level” in each section.  The second, bsplit, is just a fast file splitter. Oh, and there’s a patch to aplay to allow –-seeking to an arbitrary place so that you can skip around in the file and start playing sound at point.  (I see that I’ve forgotten to submit the patch to the ALSA people, so I did that just now.)

The interesting bit about wave.el is that it provides auto-splitting capabilities.  Or at least, it tries to.  It originally had a command for trying to put splitting marks at all points where the sound was “silent” for more than four seconds.  This worked somewhat OK, but what’s “silent” varies from sound source to sound source.  Some tapes are quite hissy.  And when I got a new record player, the background noise level dropped to almost nothing, so calibrating “silence” is boring.

Then I thought of a new approach: I know how many tracks there are in each file.  Say it’s a record album side with five sounds.  Then I could tell wave.el “this is five tracks, try to find a likely partition”.  It should snip away the initual “stylus hits the album” bump, and trim away the silence at the end, but otherwise put four sectional marks in the sound where it separates the tracks optimally.

However, I just wasn’t able to implement that in a satisfactory way.  The current wave.el isn’t really usable in automatic mode.

When you look at the sound files visually, it’s pretty obvious to a human bean where the tracks are, usually.  But I’m just not able to figure out a nice algorithm.  (I mean, I haven’t really tried a lot.  I think I spent a day on it last summer, if I remember correctly.)

If anybody has any ideas, I’m all ears.

Emacs Can Haz Brainz?

Adam mentioned MusicBrainz in the comments of the last article.  I took that as a challenge, of course.

I only implemented the query bits, though.  I’m selfish.

(Oh, OK, the only reason I didn’t do the submission part, too, is that I can’t make up my mind whether cddb.el and musicbrainz.el should share the same editing mode or not.  I think perhaps.)

[Update: That felt like a cop-out, so I’ve started implementing MusicBrainz submitting.  I needed some way to get a MusicBrainz-compatible CD Table-Of-Contents listing, so I hacked up cd-discid to do that.]

Editing freedb/cddb entries

The new album New Album from the folk band Boris

When ripping large quantities of CDs, you really have to have an efficient way to query and edit CDDB entries.  So here’s an Emacs library for doing that. It includes a bunch of convenience functions for fixing up other people’s bad entries, and you also have all the standard Emacs editing commands at your, er, command, so it’s rather nice.

I also download the entire database from freedb now and then.  It’s useful mainly when sampling (old) vinyl.  By using an approximate match for the albums, I can usually find the album in question, which means less typing for me.

However, the DISCID collisions these days are just ridiculous.  I’ve written about this before, but the situation is as ridiculous today as ever.  I mean, even more so.  It’s now impossible to submit any new album on the “rock” category, so everything I submit now is apparently “folk” or “data”.

As demonstrated.

Musical Beats & Pieces

The music player

The last hoard of Emacs-related code I’ve written over the years is part of my Emacs-based music player.  It started off (in 1997) as a way to rip my CDs and play mp3s (as well as swap out the mp3s to CD since I didn’t have enough disc space to store all the mp3s).

It’s grown over the years and changed focus somewhat.

Most of the stuff has been written pretty monolithically, with all the code stashed in jukebox.el.  So I’ll be attempting to disentangle parts that could have some reuse value over the next weeks, as time permits.

last.fm web interface

But if you want a system that you can use yourself, the EMMS system is probably a better bet.

The first result from the disentanglement process is scrobble.el. It’s a library for interfacing with the last.fm web site.  I like last.fm.  It’s the only “social networking” site I use — I find it genuinely useful for finding concerts and stuff.

Following will be a cddb library, a DAE (i.e. cd-ripping interface), a sampling-and-splitting interface, and probably other bits and bobs.  As well as the jukebox itself.

Sennheiser HDR 180

Headphones cradled on the charging cradle

Most hardware seems to have been created in a “will this do?” mind set.  They have a bit of technology, and they have some economic restraints, and then they rush it to market.  It makes perfect sense, and I can’t envision that it’ll ever change, but it’s somewhat depressing.

The hardware in question this week are the Sennheiser HDR 180 wireless headphones.  They use Klear wireless technology, and they sound really good.  There are no drop-outs, there is no buzzing — they just work, even if I walk to the far side of the apartment.  They’re, technically speaking, what you would call “ace”.

Cradle on/off button

But then there’s the User Experience details.

The headphones usually rest on the charger thingie you see up there.  It’s nice.  So when I start watching something on the “TV” and I want to use the headphones, I pick up the headphones and put them on my head?

Nope.

I pick up the headphones.  Then I hit the “on” button on the base station.  Then I hit the “on” button on the headphones themselves.  Then I put them on my head.

Headphone UX

Because, I mean, why would you assume that just because I’m picking them off the charging station, I want to use them?  Perhaps I want to do something completely different.  Perhaps I picked them off the charging station to hang them out to dry on the balcony?  Or perhaps I wanted to dance around with them, fondling them inappropriately?  I mean, that’s so much more likely than wanting to use them.

This is why I hate all hardware.  Hardware never works the way it should.

And I didn’t even want to go into the UX of the headphones themselves.  You see those five buttons on the headphones?  Yes, there’s volume up, on/off, and volume down buttons.  Fine.  But then, next to them, there’s two balance buttons.  So when I have the headphones on my head, which is usually where they are when I’m using them, I have to feel around, tentatively, for the volume buttons, because once you hit the balance buttons, you’ll never get the right balance back again.  There’s no “return the balance to the, er, balanced position” button. It’s like FAIL!!!1! And who the fuck wants to change the balance, anyway?

Oh, by Emacs.  I hate hardware.