NASA Space Sounds for EXS-24

I saw that NASA released a load of audio clips from various historic space missions – from Sputnik to the final flight of Atlantis, via the moon! Space sounds have long been used musical contexts – SpaceOddity, Telstar, Pulsar, Lemon Jelly’s “Space Walk” to name but a few. I felt I had to make these more musically useful that the ‘ringtone’ MP3s available on NASA’s site, so I wrapped them up as a library for the EXS-24 sampler (appears in Apple’s Logic and Logic Express DAWs). The sounds will work straight away in Logic, but the sounds are accessible in the archive as AIFF files so you can easily convert them to other formats. I split up the sounds into the same historical categories as on the NASA site so you’re not loading up all the samples at once. Keyboard mapping isn’t anything particular (white notes starting at C1), but I did clean up the samples a little and edited down some shorter clips of the more familiar or musical sounds (“Houston, we have a problem”, “The Eagle has landed”, “That’s one small step” etc).

The original sounds are mostly mono with low bandwidth, resolution and sample rate, but many are supplied as stereo 44.1KHz 16-bit files, so I’ve converted them all to that as EXS-24 doesn’t seem to like mixing sample rates in one instrument.

So, go ahead and download the NASA sample library! (70Mb zip)

Obviously I have no rights to these samples; NASA is encouraging people to download and use them at will, and I assume it’s being published under their open-source license.

I wrote this entry a while ago but forgot to post it, duh.

Subversion 1.7 to 1.6 downgrade with MacPorts

MacPorts told me that there had been a subversion update (1.7.1), which I went ahead and installed. Woo! Huge speed improvements for everything I tried with the CLI client, great stuff. A short time later my IDE (PHPStorm) fell over screaming. It doesn’t like 1.7 yet, and it’s a bit stuck until SVNKit supports it. I should have checked really.

So how to downgrade? Fortunately this post makes it very easy. So I just did:

sudo port deactivate subversion @1.7.0_1
sudo port activate subversion @1.6.17_1

But now I’m stuck with a working copy in 1.7 format with uncommitted changes, and there is no tool to convert it back to 1.6 format. This is easily worked around; check out a new working copy (using svn 1.6) and sync across the changes, ignoring the .svn folders, like this:


rsync -av --update --exclude=".svn/***" ~/Sites/myproject1.7/ ~/Sites/myproject1.6

All happy now.

PHP Base-62 encoding

There’s a really horrible bug (they won’t call it that, but I can’t think of any use case for the default broken behaviour!) in Apache’s mod_rewrite that means that urlencoded inputs in rewrites get unescaped in their transformation to output patterns. The underlying ‘bug’ remains unfixed even in 2.3, though a workaround in the form of the ‘B’ flag first appeared in Apache 2.2.7, but was broken until 2.2.12 (which wasn’t all that long ago). Put it like this: if you’re not using the B flag in your mod_rewrite rules, your site is probably only working due to blind luck.

With that in mind, several years ago I spent ages looking for a base-62 encoder/decoder for PHP to replace mod_rewrite’s broken urlencoding handling. Nobody seemed to have the slightest interest in writing one. Base-62 is interesting as it can be made safe for use in URLs, DNS, email addresses and pathnames, unlike any available encoding of base-64, as it only includes [0-9A-Za-z]. As a workaround for the above bug, I was interested in base-62 encoding URLs for embedding in redirects. At the time I wrote something using bc_math, but it was very slow (and weirdly got ripped off by some dickhead and passed off as his own, despite that fact that I said it was crap!). I eventually gave up on that and switched to base-64, which led to occasional URL corruption. If you include hashes in URLs, keeping them in the default hex representation is quite wasteful, and can contribute to issues with line length in email. Having hashes in base-62 is a nice way of reducing their size.

There are a few posts on base-62 in PHP, notably this one and this one, but they make the assumption that you’re talking about a numeric value, and while a hash is a numeric value, it’s way too big for PHP to handle as an integer. Others take the multiprecision artithmetic route, which treats the input binary as a single very large, and calculates its representation in another base; that works, but it’s horribly slow.

Since then, the gmp and bc_math extensions were improved in PHP 5.3.2, and now they handle (usefully) up to base-62. So here’s a simple function for getting a hash in base-62:

function base62hash($source) {
    return gmp_strval(gmp_init(md5($source), 16), 62);
}

and for converting to and from base-16 hashes:

function hash16to62($hash) {
    return gmp_strval(gmp_init($hash, 16), 62);
}

function hash62to16($hash) {
    return gmp_strval(gmp_init($hash, 62), 16);
}

I could still use a proper base-62 encoder for longer arbitrary strings, but at least now it should be simpler to write something iterative now that these extensions have (ahem) their bases covered.

Update: I’ve written a sufficiently usable PHP base-62 encoder for arbitrary-length binary strings that’s not too slow. You can find it on github in this gist. Let me know if you find it useful

Incidentally I discovered that the gmp functions use [0-9a-f] up to base 16, but [0-9A-Za-z] (i.e. upper case first) from bases 17 to 62. This differs from most of the base-62 implementations I’ve found that tend to use lower case first.

This is all slightly academic now as the apache B-flag workaround works, so standard urlencoding works properly and I don’t need to use a different encoding any more, however, there were so many examples of slow encoders, I thought the world could do with a usable one.

Update Something else worth mentioning is that if you use the apache B flag, you most likely need to turn the AllowEncodedSlashes directive on too, as otherwise you’ll get mysterious 404s. I posted a bug report against the apache docs to make this clearer.

Update Apache used my rewrite of the B-flag docs, yay!