Scanning Record Sleeves

A CD Rippin’ Cupboard with an A3 Scanner

In the continuing story of bits and pieces related to my music playing Emacs@Home installation, here’s the sleeve scanning function.  It’s basically just a tiny data base of common CD/LP/tape sleeve sizes. There’s a lot of sizes, unfortunately.

But what I really wanted to have was something that could detect the image area automatically.  Why doesn’t that exist?  I mean, I couldn’t find it when I googled for it half a decade ago, so it can’t possibly exist now.

It should be pretty easy to detect the image area, you’d think.  Record sleeves are usually kinda square.  So you could use…  rectangle detection…  to find the image. On the other hand, I have CD sleeves that aren’t rectangular.  And I have sleeves that have a square border, and then blackness outside the border, so just detecting the square might over-crop stuff.

I thought about using green screen techniques.  If I painted the inside cover of the scanner cover a particular green colour, then I could probably whip up a technique to…  do something.  But I fear that there’d be colour leakage, with the reflected green light giving off a green tinge to paper sleeves that aren’t very thick.

So, I don’t know.  The result is that sleeves that are half a millimeter larger than the standard sizes I have tend to be slightly over-cropped.  It’s annoying, but not annoying enough that I ever bother to re-scan the offending sleeves.  And hand-editing a scan — you know, in Gimp or something — is so ridiculous that I have to laugh.  Just see:  “Ha ha.”

The ignomity of it all.

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.

Greylisting Considered Annoying

Nobody likes spam.  So to avoid spam they either inflict pain on others, like with challenge/response systems that send endless challenges to me since “I” have sent them spam (From headers are so hard to fake? (I know this guy who automatically responds to all challenge/response systems (evil, but understandable))), or they use “greylisting”, which is harmless, supposedly.

It just means that mail takes a bit longer to deliver, right? The first time you try (on a unique from/to pair), your MTA gets told that it has to wait for a while.

So when I do a Gmane subscription handling session, I first fire off a bunch of subscription requests.  Then, since so many list admins use greylisting now, I have to wait for fifteen minutes to complete the process.  Meanwhile, I’ve gone on to do other things, or I’ve left for a holiday in a differerent country, so the process stops in the middle, and the person who requested the list gets all sad and stuff.

See what you’re doing, greylisters?  You’re making Gmane users sad!  For shame!

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.