Music Distribution

The main issue when I moved to the new flat, oh, three-ish years ago? I think, was how to listen to music.

I want to be able to walk between rooms, listening to the same music.  This means that there has to be some kind of way to distribute music between the rooms.

I looked into various ready-made wireless systems like Sonos, but these all made The System the central point.  I don’t want that.  I want to be able to control the music in any way that I want to, which means from Emacs.

So I wanted (sort of) passive systems that would allow me to say “the volume in room X is Y”, and that would allow me to pause and skip the music from any room, while still tying into my own Emacs-based playing system.

The first element is the sound card.  I settled on a RME Multiface box.  It’s really a semiprofessional music routing card. It has a lot of inputs and a lot of outputs, and you can route any combinations of any inputs to any outputs, while controlling the volume.  You see how this would work for me: I’d just play a flac file, while having each room be one stereo output, and I’d set the volume per output.

RME Outputs

I now had all these outputs, but how would I get the music to the various rooms?  I first tried a couple of wireless systems.  They both had two problems: 1) There was a half-second latency, so if you heard sounds from different rooms, it sounded kinda psychadelic.  2) They didn’t work.  That is, they had frequent drop-outs, and made beastly noises while doing so.  I know, I know — nothing that’s wireless actually works.

My second idea was to try a powerline audio thing.  The bandwidth requirements for audio are pretty minuscule, so I thought there might be a chance that something like this would work.  But, as with the wireless systems, it 1) had a beastly latency and 2) didn’t work.  The drop-outs were even more brutal.

So: Wires it is.  I’d have to install wires between all the rooms to get music to them.  But what kind of wires?

That’s when I learned the magical word: balun. It means “balanced/unbalanced”, or something like that.  Basically, a balun is a device that takes an unbalanced signal (like RCA audio) and makes is balanced (or what we computer people call differential). 

Doing research over the intertubes I found a few companies selling this stuff.  The baluns are generally non-powered, and use cat5 cabling.  Like these babies:

Two Baluns
Cat5 Port

They are just perfect!  You just hook them up to your audio outputs, string some cat5 to a different room, plug another one in there, and plug the audio output into whatever amplifier/speakers you have there.

The sound quality is totally fine, too.  That is, I can’t hear anything obviously bad.  There’s bass, and there’s treble, and there’s the middle part.  Perfect!

The main problem is, of course, all the cabling.  That means a lot of these:

And some stretches off wall that look like this:

Cat5.  Wouldn’t bet on the e

Ok, some of those are Ethernet.

That’s a lot of hammering and drilling, but it’s totally worth it.  It just works 100%.  No drop-outs, no odd noises, no latency.  And the fi is so hi.

Wired is the new black.

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.]