Sunday, February 28, 2010

This makes me sad

My wife and I recently bought a Honda Civic Hybrid. Among other features, it has the ability to play music files off a USB mass storage device. Yay! Easy way to play the music on my Android phone through the car speakers, right?

Wrong. You see, about a year ago I upgraded the disk server to 1.5TB and re-ripped our 800+ CD music collection to FLAC. At the same time I also transcoded to AAC, because AAC turned out slightly better to my ears than MP3 in some comparative testing I did.

Now, the Civic's owner manual claims that the stereo can play AAC files, and even lists the bitrates, sampling rates, etc. that are supported. However when I actually tried to play these files, it gives the error "UNPLAYABLE FORMAT".

If you look more closely, you notice the disclaimer that says only iTunes AAC files are supported. As best I can tell, what's going on specifically is that iTunes doesn't support encoding AAC files with VBR, despite the fact that VBR is required by the AAC spec (according to WikiPedia, at least.)

Rather than support VBR, Honda's stereo vendor chose to simply implement AAC without VBR. I have to wonder why. There are plenty of spec-compliant AAC implementations out there, including some that are open source. Did Apple actually give them this code? The thing supports deeper integration with iPods so it's possible they got some code for that from Apple that included playback of Apple-forked AAC files, and are just reusing that same AAC-playback for USB mass storage playback too. This is just speculation of course -- I have no way of knowing, except that the manual says straight up that only Apple's non-standard fork is supported.

Regardless of what the technical reality is, the retail leader in digital audio forked a standard, and then used their market power (whether intentionally, or accidentally) to cause another vendor to propagate their fork. Shame on Apple for not supporting AAC properly, and shame on Honda for propagating the breakage.

Now please excuse me while I go transcode my FLACs to MP3, just so I can try to play them in my car. God help a regular person who tried to do this, without the know-how to write a Python script to do it...

Update: It was pointed out to me that iTunes does support VBR, and has an option for it in the UI. However, according to WikiPedia, it's not true VBR. Here's the quote from WikiPedia, to make things clear as mud:
iTunes supports a "Variable bit rate" (VBR) encoding option which encodes AAC tracks in an "Average bit rate" (ABR) scheme. As of September 2009, Apple has added support for HE-AAC (which is fully part of the MP4 standard) but iTunes still lacks support for true VBR encoding. The underlying QuickTime API does offer a true VBR encoding profile however.
So it could be that, or it could be one of the other changes Apple made to the AAC file format that I've read about. But as I said, I'm just speculating; all I know for sure is that my car only supports whatever hacked format Apple's introduced, and it makes me sad.

Saturday, February 27, 2010

Licensing is hard; let's go shopping!

While I was working on my recent Arduino project, I happened to end up looking at some of the code that's available. This was.... interesting? Scary? Depressing? I'm not sure exactly how to describe it, but I thought it was worth talking about.

I'm talking about licensing. Here's a header file from an optional, but common, Arduino add-on library. The copyright holder's (i.e. author's) name is elided, because my goal is not to call people out:

  Foo.h - Arduino library for XXXXXXXXXXXXXXXX
  Copyright (c) John Doe.  All right reserved.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of

With apologies to Inigo Montoya, "You keep using this license. I do not think it does what you think it does."

Obviously this developer's heart was in the right place, and he's properly protected himself by disclaiming warranty; so far so good. The problem, though, is three little words: "all right [sic] reserved".

By the brevity, I presume the author's goal was either to abdicate copyright to the public domain, or license it under a maximally permissive BSD-style license. However, that's not what's happened. This copyright actually isn't even a license at all, it's just a copyright header. This isn't a contract because the reader/user isn't agreeing to anything and there are no conditions. The author has reserved all rights to himself, and granted me none.

The bit about hoping it will be useful is nice I suppose, but since I have not actually been permitted to use it for anything, it's a moot point. Even if there were a grant of license in there somewhere, that clause is merely stating an unverifiable, irrelevant fact, and it is a total no-op as far as copyright and licensing is concerned.

So, okay, having made my point -- does it matter? This is an interesting question. The code itself is fairly simple, even trivial. What's more, the culture of the Arduino project is that a lot of... uh, let's call them "makers" (since many of them aren't professional software engineers) make various kinds of contributions. So the author of this particular piece of code manifestly knows how to write basic C++ but just as manifestly does not understand software licensing. From this I conclude he's more or less an amateur software developer, and that he probably doesn't attach a particularly high intrinsic value to the code he's contributed. And of course, he did contribute it knowing full well it would be publicly visible, after all. All of which is to say, it's almost certain he intended this to be open-source, in some form.

So there's very little practical legal risk of using this code. The likelihood that I would get sued for using this software in my personal little Arduino project is vanishingly small. If that were my only concern, then I wouldn't worry about it and carry on.

Unfortunately, that's definitely not the only concern.

Suppose I contacted the author of this software, with a polite message: "Hey, I don't think this header in this file is doing what you think it is; you might want to consider changing it." Let's assume the author is willing to fix it. In that case... fix it how?

If he fixes it by making it public domain or using a BSD-style license, then this story ends, and we all go about our business. However, most of the rest of the core Arduino software appears to be LGPLv2, so it would be quite reasonable for the author to also choose LGPL for his contributed code. If he were to do that, he actually would screw me.

See, my preferred license is Apache 2.0. I prefer this license because it's basically BSD-style with some anti-patent-burn language. Or to put it another way, it's essentially the maximally-permissive BSD license updated to address the various IP realities of our modern times. Unfortunately the patent clause also happens to make it incompatible with GPLv2, and (I'm pretty sure), LGPLv2. This means that if the author of this code chooses to license it under LGPLv2 -- a very fair and reasonable decision -- it means I either have to alter my own license choice, or else find or write some other software to use.  (Unless of course he chooses LGPLv3, which introduces a whole new set of complexities.)

My point here isn't to start a flame war about open-source licenses, by the way. I'm not saying that I'm right and the other guy's wrong, just that our license preferences conflict (at least in the hypothetical scenario I just described). Backing away from hypotheticals, what I can say concretely is that there's too much ambiguity here for me to be comfortable.

To put it another way, even though I might be comfortable taking the legal risk of getting sued because I feel it's obvious that the author meant his code to be open source, I nonetheless can't be comfortable using the code anyway because I don't know how the author meant it to be open-source. He might very well have meant it to be open-source in a way incompatible with my actual usage, and so in the absence of surety it's ethically wrong (as well as technically legally wrong) for me to use it.  Plus, Google Code Project Hosting has a policy that you may not use it to host non-open-source code, and so I couldn't include that software in my chosen SCM site, anyway. (N.B. - I actually did have it included for a day or two, until I noticed this problem and removed it.)

In this case, I did not attempt to locate and contact the author to clarify because it was easier for me to just write the code out of my app. In other cases it might not be so easy. And by the way, this isn't the only Arduino code that does this: there's a sample Makefile intended to be copied and customized for building projects from the command line. That actually is included in the core Arduino distribution, and it has no copyright heading at all, let alone a license.

Perhaps it sucks that the world we live and code in makes this stuff important. But, like it or not, it is important. I'm not trying to pick on the Arduino project; it's a fabulous project that has done awesome work. But this kind of thing is one reason why my day job is sometimes so hard: license compliance is often not easy, and with a project of the scope of Android, it gets to be damned hard.

So I guess I wrote all this to make a plea: please please developers, if you release source code, think carefully about what you are releasing, and make sure you choose your license carefully so that it reflects not only your principles, but also how you hope and expect it to be actually used by others. But most of all, PLEASE take the time to get the details right.

Garduino Redux

A while back I made a "Garduino", based on an article Luke Iseman wrote for Make Magazine #18. It's an Arduino-controlled plant growing rig.

Luke's original version monitors moisture and automatically waters the plants when they need it, and it monitors light level via a photoresistor and turns on a supplementary grow light as necessary. My version includes the light monitoring, but I omitted the moisture sensors and water pump in favor of an Earthbox self-watering planter. I figured that since Luke's version involved dumping water into a large bucket, manual refill is manual refill and I might as well just refill an Earthbox. I'm stupid, so I need to keep it simple, you see.

Anyway that's all old news. A while back, I put up some videos on YouTube, documenting the growing process:
Since recording those videos, I moved the circuitry from my breadboard to a permanent home on an Arduino protoshield, but until fairly recently that was about it. It's been running great for months now. It turns out that even with the grow light I don't get a terrible lot of light over there, so the basil's growing slowly enough that I only just now have enough of it to make some pesto. But alas, this is the best I can do unless we move somewhere with better lighting. I credit the Garduino with this being possible at all.

However there's been an annoyance: periodically the thing will just reset itself. I think this was because the host would occasionally brownout the USB voltage, making the Arduino reset. But whatever the cause, this has 2 problems: it means that I need to reset the Arduino's onboard time (since it doesn't have battery backup or even a clock), which in turn means I need to hook it up to a computer to access the serial port. For various reasons I have only one computer which can program the thing, which means I have to haul out a laptop to do this, and then physically sit next to the thing, tethered, to do the reset.

I resolved to solve this.

The lightbulb went on when Brian Jepson told me about the Sparkfun BlueSMiRF, which is a Bluetooth RFCOMM-to-serial-TTL bridge. In practice, it takes your "Serial.print" output from an Arduino program and makes it available over Bluetooth to a PC..... or a phone. Android, meanwhile, added an API for Bluetooth RFCOMM in version 2.0. My wife got me a BlueSMiRF for my birthday, and it was off to the races.

I rewrote the Arduino code into a simple finite state machine, and added the ability to accept commands over serial. It's a very simple project, so there are only 2 commands: reset, and set current time. I encountered some interesting open-source related issues in doing this, but that's another post.

I then wrote a spiffy little Android app that pairs up to the BlueSMiRF, reads the state dumped from the Arduino every 3 seconds, and then makes a pretty little Android UI. It shows me a Sun, Moon, or Clock depending on which state the Arduino is in (daytime, nighttime, or waiting for clock data), and reports the other status fields like light intensity and status.

All told, it's working pretty well! There are a couple minor bugs I need to fix, but it's doing what I need it to do, and it's pretty fun to whip out my phone to see how my grow lights are doing. A little pointless maybe, but fun.

My source is up on Google Code, if anyone cares.

Monday, February 22, 2010

Call me the GIT-arr man

I'll start the revivifying with the cigar box guitar I built.

First, know that despite appearances this is not a remarkable thing; after all: And I will cut the suspense as well, by revealing the output of this procedure:

I generally just followed the instructions in Make Magazine, which I will neither repeat nor paraphrase. What I do want to do is just describe some of the ways in which my experience compared to the article.

I shall begin where I began: at the cigar store. I started out with a search in Google Maps (where else? heh heh) for "cigar". This revealed some Maps place spam which it was my privilege and duty to report to the Maps folks, but I shall not digress.

I ended up at Grant's Tobacconist up on Market St. I wandered in on a Saturday afternoon, whereupon I discovered two things. First, that the guy who runs the place may or may not know what these people are doing with all these empty cigar boxes, but he does know enough to make us pay for them. $10 got me 3, of which I don't mind saying that one may well be the platonic Form of a cigar box, at least from a guitar point of view. More on this later.

Second, I learned that, wow, it's smoky in there. It was almost funny: I was in a race against time, I had to check out quickly and escape before I busted out coughing and offended everyone in there. I mean, you don't walk into a cigar shop and then start coughing ostentatiously and glancing around to see if people take your hint. But I survived, and hopefully without spreading offense.

Building a CBG requires a modest variety of handtools, of which to my shame I was not already an owner. I went to Lowes, that magnificent Store of Stores, vast savannah of tooling. There, I found only FAIL. They had like 1/3 of what I needed, so I bought the oak stick I needed and left it otherwise as I found it.

Then I went to tiny-ass Cole Hardware, clown-car of retailers, wedged all Harry Potter style into a 47-inch gap between buildings on 4th St. They had everything I needed. Go fig.

Having procured my tools, the construction went pretty much as the Make guys described. I will say that I wished more than once for my dear Father's table saw. By my rough calculations, a table saw would have reduced my prep time on the neck from about 97 and a half fortnights down approximately 0.0000000 seconds, for a percentage improvement of roughly INFINITY. Alas.

Honestly though half my problem was that I didn't know how to use a coping saw and I wasn't sure of the best way to proceed, since you have to basically slice the oak stick in half the long way, twice, to carve out a couple chunks. On one end, I ended up using chisels to hack out the wood and then sanded the bejesus out of it. This worked but was time (and kilocalorie) consuming. The other end I used the coping saw on, which worked pretty well. With practice or a steadier hand, one might even call the results good.

Yeah, I screwed some things up. But some were not my fault, I swear! Behold my shame, in no particular order.

For one thing, it turns out that cigar boxes smell like cigars. And I don't like cigars. Wanting to not have to deal with a Pigpen-like cloud of cigar odor every time I picked up my guitar, I wanted to deodorize it a bit. To do this I just dumped a couple ounces of baking soda inside the box and let it sit for two or three days, then dumped it out. The odor's not gone, but now it's a gentle musk instead of a heinous stank. Problem: SOLVED!

As for the neck, well... I wasn't really thinking when I drilled the holes for the tuning pegs. Normal people arrange the pegs with 2 on one side and 1 on the other. I thought it would be hilarious (absolutely. hilarious! Seriously, I thought this would be totally funny) to put the 3rd peg on -- get this -- on the TOP of the headstock!!! So I drilled the hole up there only to realize that I drilled it too far away from the end of the headstock for the actual thumbscrew to clear the wood. I actually had to use the coping saw again to cut off a slice of the headstock at a jaunty angle to make room for the tuning peg. I wasn't laughing anymore, although in the end I think it lends the finished product a certain ghetto je ne sais quoi.

Now, you have to understand: I had never seen a guitar string before. Ever. I had no idea how the little barrel plug thing on the end was supposed to work, and I was like, "do you just tie the string onto the hinge through the screw holes? Or what?" Then I got them in the mail and I was like, "Ah. Uh. Hmm." Apparently the hinge that Mark Frauenfelder used in the Make article had tiny little holes, or else he had weird strings because there was no way those strings were staying attached to MY hinge through geometry alone. I ended up just punching 3 holes in the hinge that were smaller than the barrel plugs. This worked, but makes me wonder if I shouldn't have just used something other than a hinge, but whatever. Fun factoid though: a faux gold/brass hinge that would look decidedly low-budget on actual cabinetry looks surprisingly kickass on a cigar box guitar.

And now, I have to talk about the frets. Dear Make Magazine photographers: you guys know I love you, but YOU LIE! The article clearly depicts the fret slots being cut with the coping saw. Now, maybe it was just my particular saw, but this ended up cutting a slot too wide for the fretwire to take grip. When I used the Xacto hobbyist saw that came with my miter box, which has a significantly narrower kerf, the fretwire stuck fine. Thing is, I couldn't find replacement coping saw blades that vary in kerf, so I think this might have just been a photo staging error. Fortunately I (wisely) only cut the first slot with the too-wide slaw, and all the others turned out fine. I still need to glue that first fret in, but I think I may leave it as-is. As a reminder. Never forget! Anyway, "Measure Twice, Cut Once" paid off -- thank you, Norm Abram!

Though this reminds me of my only real gripe about the article, which is that it was insufficiently precise in some of the parts list. And yes I realize that there are variable widths of fretwire, but I also ordered the wire that the article advised, as far as I could tell. I think. Maybe? I tried anyway. Point being, the article just sort of said "hey go to and buy some fretwire. Or maybe if you like." A little more guidance on specific strings and fretwire to buy would have helped us hapless n00bz.

Another minor issue I encountered was that the screws securing the cigar box to the neck really wanted to dig right through the cigar box's wood, because it was pretty lightweight. (Okay fine, technically the platonic Form of a cigar box from a guitar point of view would be made of wood that sounds great but is hard enough to hold a screw well. So maybe it's not quite the platonic Form. But more on this later.) Fortunately I have screwed enough screws in my day to expect this, and I didn't let the screws bite straight through the cigar box entire.

Finally, Cigar Box Guitar protip: remember that shipping things (such as, hypothetically, guitar strings and tuning pegs) thousands of miles takes time. And also that if you don't order everything you need at once, you have to make another order. And then wait for the second order to arrive. Yeah. Keep that in mind...

Ultimately, battle was joined, and a hard-fought victory was won. Which is actually a lie, the victory came quite easily. My opponent was made of wood after all. Aside from the quibbles above, the whole thing went remarkably like the Make article, except for the preparation of the cigar box itself.

The box I chose was not a typical box where the lid closes flat and flush. I chose one that actually was like a chest with a shallow lid with a lip that closes onto the bottom. The result is that it has a nice hollow reverb just by itself, when you knock it with a knuckle. The edges are also nicely beveled, giving it a great appearance and feel in the hands. And finally, the branding is actually branded into the wood, as opposed to printed on paper glued to the outside of the box. All in all, it is a Cadillac among cigar boxes. It ought to have been though, since it cost me the princely sum of $4 -- American!!

Anyway this box structure complicated the process of making the neck flush with the box top. The trickiest part was that ultimately I only needed to remove about 3mm of material from the portion of the next that goes into the box, which is why I tried the chisels I mentioned earlier. But whatever, I soldiered on, and all is well.

I'm extremely satisfied with how it came out. That cigar box was all I could have hoped for, and it sounds pretty freakin' awesome. I expected kind of a course, ragged, thin sound, at least compared to a real guitar. I strummed this sucker and I was completely shocked -- it actually sounds like a guitar!! A real honest to gods guitar!

Then I tuned it. With my Google™ Nexus One™, powered by Android™, using an app named "G-strings" I obtained from Android Market™, the leading mobile applications marketplace. *cough*

The only other issue I had was that while tuning it, the high G string was twanging. I poked around at this and realized this was because the g-string wasn't pulled tight across the nut. (What?? Get your mind out of the gutter.) So I restrung that thread onto the peg's lower hole, and boy howdy, does it sound awesome now.

So that's it! It went pretty much according to plan, and I truly can't believe how well it turned out. It sounds awesome, was fun to build, and required only hand tools, except for a cordless drill.

Now I just need to learn to play guitar.


I stopped blogging more or less when I started tweeting. This, frankly, was the easy way out. Better to be pithy but without substance in 140 characters, than to be dull at novel length.

But, lately I've been doing some projects, so I'm going to use this blog as a build log for stuff I'm fooling around with.

You've been warned.