Gecko to music conversion using 3 bit tuples

I was driving home from work recently after a particularly stressful day when some random synapses fired in my brain (or perhaps just burned out from stress) and an idea formed.

Standard diatonic musical scales have eight notes, a power of 2 that can be represented by a 3 bits. We’re used to thinking of our data primarily in terms of 8 bit bytes. But any file on your computer is just a stream of bits and could be processed in 3 bit chunks rather than 8 bit chunks. So, I thought, that means every file on my hard disk is potentially a piece of music.

I was up late playing with the Perl pack and unpack functions and eventually cranked out a simple byte to note converter that will take any arbitrary file as input and produces MIDI note data as output. After re-attaching a somewhat disused Yamaha keyboard to my Linux box, I picked a file to test the program with. I started small with a 1478 byte plain text file that contained a Backus Naur diagram of the Ring Tone Text Transfer Language. The result, while a bit odd, could be described as music of sorts. With seeming success at hand, I looked for more interesting data.

Next, I took a 24Kb JPEG photo of Nimon, one of our Geckos, and converted it. The resulting music had a Danny Elfman-like urgency to it and was a bit of an improvement over the RTTTL composition. However, the MIDI file was 500Kb and creating it consumed nearly all available memory on my box. It was at this point that I realized the MIDI::Simple module that I’d grabbed from CPAN wasn’t really designed for stream use or for large volumes of data. For some reason it wants to hold the entire collection of notes in memory before writing the output.

More interesting though, was that the real Nimon seemed to take an interest in the music created from her image. She came out from under the hollow log she usually sleeps under and stood on top of it holding her head up in the air as if listening. Who knows what a Gecko hears – maybe she was just feeling the vibrations from the sounds and thought an insect was around that needed eating.

No data is lost in the conversion and it should be trivial to convert the MIDI file back into the the original data. In fact, since the music uses only one timbre and is not polyphonic, it shouldn’t be too hard to convert from the music itself back to the original data. It’s not an efficient data transfer medium, however. Music usually plays at around 96 or so beats per minute, each beat is just 3 bits of the original data. So a 24Kb JPEG becomes an 11 hour musical work!

Despite the inefficiency of music as a data storage or transfer mechanism, tradition says that when a new way of encoding data is found, one has to encode the decss.c file. I present decss.mid, an illegal circumvention device in C Major, Opus 3.

Three Reptiles and a Gato

The weather has improved a bit here in TX. Now that the spring rains seem to have stopped, Susan and I have been able to resume our habitual late-night walks. The neighborhood wildlife count for last nights walk: three reptiles. A sleeping green anole in a tree, a mediterranean gecko out for a nocturnal snack, and a small rough earth snake that had been lying on the sidewalk to catch the last of the evening heat and must have gone to sleep. We woke it up and it slithered away into the grass.

Meanwhile, online, Advogato was host to a lengthy debate that started out being about what sort of community certification metrics were best and ended up being a flame war about politically correct labels for the certification levels. I posted my two cents on the certiciation issue. The end result? It looks like Advogato will stick with the existing certification system for now. And I got two more certifications – one Journeyor and one apprentice – apparently from people who read my article. Duff, one of the users who gave me a cert posted his reasons in his diary. This was kind of cool as it’s the first time I’ve actually known what motivated someone to certify me. (thanks duff!). My own certification system is that I only give certifications to people I know well (there aren’t any on advogato yet), people who have a well known reputation (like alan or miquel), and people who certify me, if there is enough information on their advogato page to make an educated guess at their level (like flaggz or kelly).

I noticed that ALSA 0.5.7 is out today. This should have the MIDI patches as well as a few other bug fixes. It will probably be late next week before I get a chance to try it out.

More on ALSA

The last couple of days have been mostly used in Perl coding on customer jobs but I managed to get some free time last night to play with ALSA some more. I had previously gotten all the internal functionality of ALSA + Sound Blaster Live! working great so currently I’m trying to get the external MIDI port working. After a few hours of tweaking the configuration and searching newsgroups and mailing lists for the obscure, undocumented secrets of how to install ALSA properly, I finally got MIDI out working reliably. MIDI in is another story. The first attempt to use the MIDI in port causes the requesting program to segfault. Any further attempts to use the port result in dead processes that cannot be killed except by a reboot. The ALSA driver itself seems to die as well and cannot be stopped or restarted without a reboot. It’s likely a bug in either the SB Live! driver or ALSA. I’ve noticed with interal or external MIDI port usage that the ALSA drivers will occasionally die for no apparent reason but they can usually be fixed just by stopping and restarting ALSA.

ALSA and Other Linux Audio Items

An entire week with no news updates! I think that’s the longest I’ve gone in nearly a year. I’ll try to do better. Last week was slow in terms of news anyhow. Lots of Perl coding, haggling over business deals, and the occasional break to watch the latest satellite photos of Antartica’s ice shelf breaking up (check it out if you’ve never seen an iceberg the size of Deleware).

I did take some time this weekend to upgrade the sound system on my box at home. I picked up a Sound Blaster Live! card as it appeared to be one of the few with driver support for all the cool stuff like wavetables, synth, and sequencers. A download and a few builds later, I had the ALSA 0.5.6 drivers working. It took a bit patience but I eventually got the sequencer and MIDI stuff working adequately too. (I didn’t realize for the longest time that MIDI wouldn’t work until you download a soundfont file with the MIDI instrument sounds to the wavetable, duh…) So, the next step was downloading all the Linux music stuff I could find. The best one-stop list of all Linux/Unix sound and music software is Dave Phillips’ Sound & MIDI Software for Linux site. I spent a good part of a day downloading, compiling, and trying various music software. What I discovered was that about 50% of it is total crap, 25% will be really cool someday when the development progresses a little more, and what remains is almost usable. One thing that I found particularly annoying was that none of the programs I tried had any reasonably easy way to enter musical data directly. Several programs indicated they’d be supporting MIDI capture in future versions, however.

My recommendation for stuff that looks almost useful at the moment is the Beast/BSE package for sound generation, the Melys MIDI sequencer, and Denemo (a LilyPond front-end) for notation.