How many notes in an octave? November 10, 2009
Posted by andrewgdotcom in Gadgets, Music.add a comment
Short answer? As many as you like. But some choices are better than others. The common “western” system is known as 12-TET (12-tone equal temperament), which is a modification of earlier geometrical tunings (such as the Pythagorean and quarter-comma meantone temperaments) where the frequency of each note is defined in terms of a simple ratio with respect to a reference note, usually C (the frequencies of C and G are in the ratio 2:3, for example). There are problems with such systems – frequency ratios between arbitrary notes are not simple in general, and any geometrical tuning system will have a wolf interval, whose dissonant sound must be avoided in musical composition.
By contrast, “equal temperament” systems define the frequency ratio between any two adjacent notes to be a constant, but this constant cannot be a rational number and note frequencies which were once simple ratios of each other are now very slightly detuned. Analogue instruments have a natural variability in their tuning, so this slight “error” usually goes unnoticed.
The division of the octave into twelve equal intervals is a natural progression of the 12-interval Pythagorean system, but is not the only one. The “ideal” tuning system is one where all intervals are based on simple frequency ratios, but this is impossible to realise in practise without either providing an infinite number of notes or severely limiting the musical range of one’s compositions. Many of these ideal intervals are very badly approximated by 12-TET, notably the minor third (the interval between C and E♭). 31-TET is a better match overall, however it more than doubles the number of notes required on an instrument, and many of these will not be used in the vast majority of compositions because they do not approximate a useful interval.
Compromise tunings which do not require so many redundant notes include the alien-sounding 22-TET and the more mellow 19-TET. The latter gives improved major (C-E) and minor (C-E♭) thirds compared to 12-TET, at the expense of a slightly less accurate fifth (C-G). It also has few enough notes that 19-TET instruments are quite practical to construct and play. I had to try.
I refretted this guitar two years ago and forgot to blog about it at the time. I was fully convinced that I had, up until the point when I tried to find the appropriate link to help spice up my entry into this competition. I’m addressing my earlier failing now.
I have three guitars, though technically one of them belongs to my brother. The cheapest and crappest of my two was duly sacrificed in the name of science. I bought a fretsaw and obtained a length of fretwire from a local instrument repair shop. The existing frets on the guitar were easy enough to prise out of their grooves, and new grooves in the appropriate places* were easy to cut. To cut down my workload, I only refretted one octave worth of the neck – this isn’t as big a sacrifice as it sounds, as the 19-TET fret spacing close to the body would be far too narrow to play comfortably. The biggest difficulty came in cutting and shaping the new frets – I ended up having to file off a few offending corners and in doing so scratched the edges of the fretboard. Overall I’m pleased with the result though – it plays easily and looks just like a “real” guitar until you get too close.
How do you adjust your playing style to a completely different fretboard? The pearl inlays from its 12-TET days are still present, and provide a useful visual clue for where the fingers should go. If that doesn’t work, I usually just fiddle with the chords until it sounds right. As a rule of thumb, anything requiring a one-fret interval should now use two, and a two-fret interval becomes three.
One advantage that 19-TET has over (say) 22-TET is that standard music terminology can be (ab)used. The white-note names are unchanged, black flats and sharps are now distinct notes (C♯ is not D♭), and B♯=C♭ and E♯=F♭ are now notes in their own right:
C C♯ D♭ D D♯ E♭ E (E♯=F♭) F F♯ G♭ G G♯ A♭ A A♯ B♭ B (B♯=C♭) C
If you are familiar with the piano, imagine that each black note has been replaced by two black notes, and the gaps between B-C and E-F are now filled by one black note each.
How does it sound, I hear you ask? Unfortunately I can’t make you a recording at the moment, as the bridge recently came apart (someone remind me to go to the repair shop this weekend please?). However, some fantastic examples of 19-TET music can be found on Jeff Harrington’s site – my favourite is this one. He’s a much better musician than me anyway.
* D(n) = D(0)/2^(n/19) where the distances D are measured from the bridge and D(0) is the distance to the nut.
Best 419 scam yet. September 23, 2009
Posted by andrewgdotcom in email.add a comment
我有新的電郵地址!
你現可電郵給我:thomasjoe3313@yahoo.com.hk
- As you are aware of the activities of terrorist attacked at our airport,during our daily routine on 100% inspection of incoming and our going flights, we arrested a man with a consignment that claiming to be yourpartner, after we scan thetrunk box, we discovered the trunk box contain liquid cash in [US] Note and other documents attached to the consignmentdid not carry the suspect name, but carry your name and address as the receivers of the trunk box and this is very SUSPICIOUS.Get back to me immediately to explain your intention; before I proceed to contact my superior and your embassyfor more investigation, hope you arenot sponsoring terrorism with this fund? be very sincere to me please.Yours in service,a Office of Thomas joe,Metropolitan police chief.Heathrow Airport UK.EMAIL mrallen92@hotmail.com
Insecure by design August 13, 2009
Posted by andrewgdotcom in Software.1 comment so far
I came across an article today that lifted my spirits:
100% Verifiable Bug-Free Code Is Possible (Dobbs Code)
The executive summary: ok-labs.com and nicta.com.au have developed a microkernel that is provably correct, in defiance of the conventional wisdom that formal methods are only practical for the simplest of projects. While I take my hat off to the developers for their heroic efforts, I firmly believe this is only the first step in a process that will revolutionise the industry. The ultimate goal should be a complete, provably correct computing platform. This will not come about quickly or easily, but there are practical things we can do in the meantime.
Recently, the SANS Institute published a list of the 25 most dangerous programming errors. Most of these, e.g. buffer overflows, are rookie mistakes that every apprentice programmer is warned about, yet even with better training and increased collective experience, the population of errors in the wild seems to increase daily. The reason is simple: as the number of programmers grows, and their productivity increases, the number of opportunities for errors to creep in grows faster than the ability of the human mind to be vigilant. Or to paraphrase Murphy’s Law: if a programmer can make mistakes, he will make mistakes.
The conventional wisdom is to accept that such errors will be made, and be vigilant in testing. But no amount of post-facto investigation can give us 100% confidence that a catastrophic error doesn’t lurk somewhere in the code. With software increasingly responsible for people’s lives (fly-by-wire aircraft, nuclear power), the potential consequences of code errors will become unmanageable. Let me demonstrate.
The standard equation of risk analysis is
risk = probability × severity
What this means in practice is that in order to maintain risk below a given maximum, any event that has N times more severe consequences (e.g. a plane crash that kills 10 times more people than a car crash) should happen N times less often. But going from 99.999% (five nines) certainty to 99.9999% (six nines) is a lot harder than going from 99% to 99.9%, due to diminishing returns. Throwing man-hours of testing at such a problem does not scale.
Formal methods give us a way around this impasse. But we do not even need the expense of formal testing to eliminate the most common errors – design choices in our programming languages can do a lot of the work for little cost. Consider the state of the art before the introduction of structured programming in Algol-60. Without nested loops or multi-line conditions, the GOTO statement was king. GOTO-based programming languages are Turing-complete, in that they can perform any conceivable algorithm, but they are too flexible. It is quite possible (and easy) to write nonsense algorithms where loops would start or end inside the ELSE block of an IF statement, for example*. No modern programmer would contemplate such absurdities – there was a very good reason why GOTO statements were banished from polite society. And yet programming languages without GOTO statements are still Turing-complete.
What the above history lesson shows us is that, given sufficiently intelligent design paradigms, we can remove once-thought-necessary features from our lexicon without sacrificing Turing completeness, and thereby eliminate entire classes of potential programming errors.**
Now consider buffer overflow – this can be generalised to all kinds of array bounds violation; a buffer being merely a 1D array. The array index is constrained between two values, typically 0 and some integer N. If the algorithm attempts to access the array with an index outside this range, we have an array bounds violation. If this is not tested for explicitly by the algorithm (easy for a stressed programmer to forget) or implicitly in the execution environment (inefficient and not always enabled) undesirable behaviour can easily result. We could laboriously check every subscription operation in our algorithm to ensure that sane values were being passed at all times; or we could change our programming paradigm so that it is impossible to write an invalid subscription operation.
This is not as outlandish as it sounds – we already have a commonly-used language feature that does most of the work for us: FOREACH. A FOREACH loop iterates over the elements of an array, and automatically stops when there are no more elements. We cannot pass an invalid value into the array subscription operation, because there is no such operation; subscription is handled implicitly by the FOREACH. If all buffer operations used FOREACH statements, there would never be an overflow.
Now say that at some point in the near future we find similar, implicit, methods for array subscription that cover all sensible use cases (in the same way we found alternatives for all sensible use cases of GOTO). We could then eliminate the explicit array subscription operation from our lexicon, and buffer overflows would be a historical curiosity.
I think such a development is within reach. Like many programming geeks I have been working, on and off, for some time on a pet language project which, amongst other things, features strict limitations on the array subscription operator, as well as a plethora of implicit alternatives to handle common use cases. I haven’t yet been able to eliminate subscription completely, but all ideas would be gratefully received.
* This is a real example from personal experience, which shockingly did work but was (unsuprisingly) impossible to understand.
** Of course, if the language is still Turing-complete, it will therefore still be possible to make the same error; but you will have to go out of your way to deliberately do so.
Windows Script Host error 800c0019 (VBScript) July 30, 2009
Posted by andrewgdotcom in Microsoft, Web.Tags: server 2008, vbscript, wsh
add a comment
Came across this gem today on a machine that had recently been upgraded to Server 2008:
Error: System error: -2146697191
Code: 800C0019
Source: msxml3.dll
Turns out that a custom VBScript was sending a form to one of our secure web servers and the certificate chain couldn’t be verified up to the root (even though we bought it from a reputable source). Adding the offending root certificate to the trusted root certificate authorities database fixed the problem.
This does not seem to be documented anywhere on the internet yet, so here it is.
Fresh linux install not booting? Don’t get mad, get googling. February 24, 2009
Posted by andrewgdotcom in Linux.1 comment so far
The main hard drive in my shitebox HP media centre PC died over the weekend, taking with it a significant collection of TV episodes. That didn’t bother me too much, as I rarely rewatch old TV, but it also meant that I couldn’t download any new TV, and that’s just intolerable when BSG, Dollhouse and Terminator are all airing in the States on the same night. My first reaction was to install Linux on a semi-spare USB-connected hard disk. One copy of the Lenny installer on a USB key later, and a base system was up and configured on an unclean partition.*
First problem: the bios won’t boot from USB hard drives, even though it boots from flash drives without a second thought. And no, it won’t boot from FireWire either. So, out with the screwdriver and the disk is transplanted into the main machine where the dead HD had been futilely spinning and radiating heat.
Second problem: the replacement drive is PATA, not SATA, and the mobo only has one PATA port. Not a problem, I wasn’t using the LightScribe DVDR for anything anyway…
Third problem (and this was the killer): GRUB hangs at
GRUB Loading stage 1.5
GRUB loading, please wait...
No amount of reinstalling or reconfiguring seemed to help, and I spent quite some time on google trying to track down possible reasons. I even installed grub on a USB key to see what happened; it got as far as the boot menu, but hung immediately afterwards.
Thinking it may have been something to do with installing on an unclean filesystem, I partitioned out some free space on the same drive and started from scratch. This ended up exactly the same way, but with an added “Error 22″. Much swearing was done, some of it on Twitter, and I went to bed really late and really angry two nights in a row, because I had two fresh yet broken installs of Linux and still no Galactica.
Maybe the disk wasn’t LBA? I didn’t think it was that old, but anything was worth a shot. Firing up parted, I tried to move the big partition out of the first 1024 cylinders to make space for a tiny boot partition. Parted gave me “Unable to satisfy all constraints on the partition”, which I had never seen before. When googling for this error, I stumbled across the following:
Error: Unable to satisfy all constraints on the pa: msg#00059 gnu.parted.bugs
The line about cylinder boundary alignment tickled something in the back of my brain. So, I booted up once more using the trusty usb key, ran fdisk and sure enough the old unclean partition didn’t end on a cylinder boundary. Deleting it and recreating it with the same parameters jiggled it a few kb larger and lo! both copies of Linux were magically fixed.
* Can’t be deleting the old photographs now, can we?
How to manage mailman list membership using LDAP or Active Directory February 20, 2009
Posted by andrewgdotcom in Linux, email.add a comment
Run this perl script on your mailman server once an hour using cron. Replace MY_LDAP_SERVER etc. with your own configuration. Also, depending on your LDAP implementation you may need to use group or groupOfNames instead of posixGroup.
For each list you wish to manage, create an LDAP/AD group with the email attribute set to the full address of the mailing list. The script scans all groups under the BASE_DN for any with an email address ending in @MY.LIST.SERVER. It overwrites each list’s membership with that of the corresponding LDAP group (if such a group exists, otherwise it does nothing). Make sure there is only one group for each mailing list! Multiple domain names are not supported, but could be with only a little hacking.
#!/usr/bin/perl -w
use Net::LDAP;
# Connect to LDAP proxy and authenticate
$ldap = Net::LDAP->new('ldaps://MY_LDAP_SERVER') || die "Can't connect to server\n";
$mesg = $ldap->bind(
'MY_DN',
password => 'MY_PASSWORD'
) || die "Connected to server, but couldn't bind\n";
# search for interesting AD groups
$mesg = $ldap->search(
base => "MY_BASE_DN",
filter => "(&(objectClass=posixGroup))"
);
die "Search returned no interesting security groups\n" unless $mesg;
foreach $group ($mesg->entries) {
$list_email = $group->get_value("mail");
# For groups with emails of the form "*@MY.LIST.SERVER"
# Try to chop off the name of our list server. If we fail, it wasn't meant to be.
if($list_email && $list_email=~s/\@MY\.LIST\.SERVER$//) {
# get the membership list
@member_list = $group->get_value("uniqueMember");
die "Security group for list $list_email looks empty - PANIC!\n" unless @member_list;
# make a list of emails to pass to mailman
$member_emails = "";
foreach $member_dn (@member_list) {
$mesg2 = $ldap->search(
base => $member_dn,
filter => "(&(cn=*))",
scope => "base"
);
die "Couldn't locate entry $member_dn - PANIC!\n" unless $mesg2;
$member = $mesg2->entry(0);
$member_emails .= $member->get_value("cn") . " get_value("mail") . ">\n";
};
# now update the mailman list membership
# be verbose!
print "\nchanging $list_email\n";
open( PIPE, "|/var/mailman/bin/sync_members -w=yes -g=yes -a=yes -f - $list_email" )
|| die "Couldn't fork process! $!\n";
print PIPE $member_emails;
close PIPE;
};
};
Vuze+feedmytorrents.com, a match made in…? February 7, 2009
Posted by andrewgdotcom in A/V, Software, Web.Tags: feedmytorrents, rss, vuze
3 comments
Despite having played with Democracy Miro, I’m still rather attached to Azureus Vuze for one or two of its useful features*.
Being an addict of US scifi TV, I was excited to discover feedmytorrents.com, which provides vodcast RSS feeds for most current popular US shows, such as my current favourites BSG and Lost. The killer advantage over other RSS sources (such as the excellent EZTV) is that one can subscribe to a particular feed in Miro or Vuze and get precisely one copy of every episode of that show. No more remembering to search mininova to see if the new episode was up yet! This was exactly what I had been waiting for since discovering Democracy Miro’s channels system.**
Of course, it didn’t take long for the system to break. Vuze’s RSS FeedScanner plugin would display a new episode in the list but not start downloading, instead giving a constantly shifting error message: “Init” > “Scanning 1/64…” >>> “Scanning 39/64…” > “Init” (it never seemed to get past 39). This would eventually time out saying “No data”. This affliction would only affect those particular episodes that feedmytorrents had sourced from mininova, but not those from the pirate bay (easily distinguished by the torrent URL). There was nothing wrong with the torrent file itself, as I could right-click > copy link URL and paste it into firefox, which would happily download the torrent and open it in Vuze, the default application. But of course this completely defeated the seamless experience.
I searched on the Vuze forums and found several similar problems reported but few solutions. One suggestion was that the setting “Use URL as referer” might need to be turned off. Sure enough, this worked. For whatever reason, it seems that mininova doesn’t like the HTTP referer field to be set to the “URL”, whichever URL that may be (itself?). Turning this option off (thus sending no referer) didn’t seem to break piratebay torrents (and why should it: this is the behaviour when one types in a URL by hand), so I disabled it on all my feeds. This makes me ask two questions. 1: why isn’t this option off by default and 2: what the hell does the HTTP referer field have to do with it anyway?
* coughcoughtorcoughcough! Interestingly, the latest version (4.1) of Vuze has reskinned itself to look almost exactly like Miro…
** sorry guys, I don’t watch Rocketboom…
Do what I mean, dammit. Or, why being silently “helpful” is evil. January 8, 2009
Posted by andrewgdotcom in Mac, Ranting.3 comments
For the last three years (i.e. before Time Machine), I have been using rsync to make incremental backups to an external FireWire disk from my trusty iBook. Now, rsync does this by backing up into a fresh location each time and referring to the previous backup to check if any data can be de-duplicated, which it does by creating hard links.
rsync -a --link-dest=$PREVIOUS_BACKUP $SOURCE $NEW_BACKUP
A wrapper script is needed because rsync doesn’t do any rotation of the backup paths (mine preserves six previous backups, which is quite enough), but overall the solution is elegant – restoration from any given backup is just a cp -pR away, due to the transparent nature of hard links. However (and this is the important bit) rsync only de-duplicates when the source file is identical to its previous backup in every way, including metadata.
As time went on and my laptop drive started getting full, I found that the backup window was getting suspiciously long for an 80GB disk. But it was the lack of space that finally drove me to buy a bigger external drive (admittedly, backups aren’t the only thing taking up GB on my FireWire farm).
Finally I ripped apart the wrapper script and dug through the previous backups. Turns out that rsync wasn’t preserving all the metadata, specifically file ownership. Google, as ever, gave me the answer:
Official Google Mac Blog: User 99, Unknown
By default, OS X silently maps all file ownership on external HFS+ disks to a special user “unknown”, while pretending to the user that he still owns the files. This is a “feature” to prevent weird permissions problems when swapping external drives between machines. It is so low-level that not even root can override it – if you try as root to chown a file on an external HFS+ filesystem, it will silently do nothing.
The upshot is that rsync didn’t believe that any backed-up files were identical to their originals, and so didn’t de-duplicate anything. Instead of six lean incrementals, I have six wasteful bulk backups, some of them incomplete because I ran out of backup window. And all the file ownerships have been lost, so a system restore would have failed spectacularly – if I had been foolish enough to try.
You can turn off this behaviour for any given disk (Finder>Drive>right-click>Get Info>uncheck “Ignore ownership…”), but it’s a bit late now.
The history meme April 16, 2008
Posted by andrewgdotcom in Linux, Mac, Software.add a comment
Spreading the meme…
serenity:~ andrewg$ history | awk ‘{a[$2]++} END {for(i in a)print a[i] ” ” i}’ | sort -rn | head -10
108 telnet
63 rscreen
43 ping
24 sudo
24 ssh
20 host
16 scp
16 more
14 ls
13 xdvi
Hm. I seem to be using the command line mainly as a gateway into remote systems – which reflects my average working day. The stray ‘xdvi’ is due to my recent heavy use of TextMate to write a paper in LaTeX. Not sure why I’ve been using sudo so much on my Mac though.
Similarly, on my work Linux laptop:
andgal@nbgal185:~$ history | awk ‘{a[$2]++} END {for(i in a)print a[i] ” ” i}’ | sort -rn | head -10
68 rscreen
52 ping
45 host
36 sudo
35 rdesktop
32 xrandr
21 startmenu
20 ssh
18 ifconfig
15 telnet
rscreen is merely a wrapper for ssh:
function rscreen() { /usr/bin/ssh -t $1 ’screen -dr || /usr/bin/screen || /bin/bash’; }
and startmenu is a cool but dodgy hack to get into my windows virtual machine:
alias startmenu=’nohup rdesktop -A -s “c:\program files\seamlessrdp\seamlessrdpshell.exe explorer.exe” 192.168.185.128 -u andgal -p xxxxxxxx&
xrandr reflects the fact that I have to configure my dual-screen setup by hand after each boot under Ubuntu 7.10, as the GUI configurator just Doesn’t Work. I had to test this many many times. Apparently the latest Ubuntu beta fixes most of these problems.
Widefox April 1, 2008
Posted by andrewgdotcom in Software, Web.Tags: google maps, mozilla, tabs
1 comment so far
I’m a Firefox user, but I used to like Opera back in the days before Firefox was available. I changed over once I discovered TabMixPlus and All-In-One Gestures, which collectively replicated most of Opera’s cool features – all except side-docked tabs, which doesn’t seem to be available in Opera any more either.
There are far too many things which like to dock with the top or bottom of my screen. Given that I use a Mac, I already have an extra menu bar to start with anyway. Computer screens are increasingly in widescreen aspect ratio, but documents read best in portrait mode. This is why most blog software (including this one) puts links and metadata at the side of the page rather than at the top, but there are still webapps out there (Google Maps being one of the worst offenders) that have a huge, wasteful banner across the top of the page.
So imagine my joy today when I found this Firefox chrome CSS hack:
The dropdown menu placement doesn’t match the tab bar location, but that’s a minor problem. I can now see Google Maps in a slightly less letterboxy format. Woohoo.

