Archive
Music hack roundup
Disclaimer: the opinions expressed are my own and do not represent that of my employer, Google
I love music. And programming. I really like pieces of technology that either create new or modify existing pieces of music. Here I detail some of my favorite projects I’ve found in the past few years.
Songsmith
Songsmith is a project from Microsoft Research. From the project description page:
Songsmith generates musical accompaniment to match a singer’s voice. Just choose a musical style, sing into your PC’s microphone, and Songsmith will create backing music for you. Then share your songs with your friends and family, post your songs online, or create your own music videos.
There was a commercial that detailed how the project worked, but what I found really great was what the community did with it. They fed the vocals of famous songs through the software to see what sort of music came out. The results are, ahem, mixed.
First, one that I think sounds pretty interesting – a swing version of Katy Perry’s I Kissed a Girl
Then going into the realm of hilarious:
We Will Rock You – Queen Vs Songsmith
Mortorhead’s Ace of Spades
Nirvana’s In Bloom
Enter Sandman
Roxanne
The Beatle’s A Day in the Life
The Swinger
According to musicmachinery.com’s writeup,
The Swinger is a bit of python code that takes any song and makes it swing.
If you’re not into music theory (or old music) you might not know what constitutes swing. The following video (only need to watch the first 30 seconds or so) is a great example of the difference of straight vs swing styles:
As you can hear, it sounds very different. The first half of each beat is stretched out, and the second half is shrunk down. It sounds even more different when you start listening to familiar songs converted from straight to swing, or vice versa. While most of the links have died, Daft Punk’s Around The World still plays, as does Jefferson Airplane’s White Rabbit.
The source code is available at https://github.com/echonest/remix/blob/master/examples/swinger/swinger.py.
Autocanonizer
From musicmachinery.com’s writeup of The Autocanonizer:
It takes any song and tries to make a canon out of it. A canon is a song that can be played against a copy of itself.
Wikipedia has a bit more information on what exactly a Canon is:
In music, a canon is a contrapuntal compositional technique that employs a melody with one or more imitations of the melody played after a given duration (e.g., quarter rest, one measure, etc.). The initial melody is called the leader (or dux), while the imitative melody, which is played in a different voice, is called the follower (or comes). The follower must imitate the leader, either as an exact replication of its rhythms and intervals or some transformation thereof (see “Types of canon”, below). Repeating canons in which all voices are musically identical are called rounds – “Row, Row, Row Your Boat” and “Frère Jacques” being widely known examples. An example of a classical strict canon is the Minuet of Haydn’s String Quartet in D Minor, Op. 76, No. 2 (White 1976, 66).
With that in mind, here are some example.
My favorite is Adele’s Someone Like You. This one sounds close to a round.
- Over The Rainbow – starts rough but 30 seconds in it sounds good
- The Fox – I like it. Lots of self harmonizing. The doubled up chorus actually works. It gets out of sync with itself at some points
- Take Five – demonstrates that the technique works with odd meter too. Not perfectly lined up at some points
See all the examples available at http://static.echonest.com/autocanonizer/loader.html
Source code available at: https://github.com/plamere/autocanonizer
Hat tip to Greg Linden whose Google+ post alerted me to this, and reminded me of these other projects I’d seen before.
MajorVsMinor
MajorVsMinor is a slight departure from the others I’ve listed because there is a human in the loop – it’s not all algorithmic. From Oleg Berg’s description from olegberg.com
Hello! I am Oleg Berg, a musician from Donetsk, Ukraine. I digitally re-edit famous compositions altering harmonic scale, and I call this experimental music project «Major versus Minor». It may sound surprising and unusual, but it is always interesting. Listen to the music videos below. And please donate to keep the project going
[…]
I by no means intend to enhance the famous music hits as I rework them; they are perfect already. I simply imagine what would it sound like, had the author written it in another mood. And it appears, I succeed in my imaginations.
Again, if you’re not a music nerd you might not know what the difference between major key and minor is. In general picture minor = sad, major = happy. You’ll instantly hear the difference in these versions.
First, a must if you’re an Arrested Development fan.
“Final Countdown in Major key”
My favorite comment from MYxxLxxCHIBI1:
I was literally coming down here to say that myself. GOB finally got accepted to the Alliance of Magicians
Maybe my favorite one –
“Be Worry, Don’t Happy”: Minor Key
I like this one too.
Jingle Bells
“Hey Jude” in minor key
See the whole channel at https://www.youtube.com/user/MajorVsMinor
Since this isn’t a software project per se, there is no link to the source code. According to Asshat8182’s comment on Smells Like Teen Spirit in Major key (with a name like that, he must be a reliable source of information), the way it’s accomplished is
The ‘somehow’ is called Celemony Melodyne. Specifically the DNA function
According to Wikipedia:
Celemony Software GmbH is a German musical software company that specializes in digital audio pitch correction software. It produces Melodyne, an industry standard audio pitch modification tool similar to Auto-Tune
Conclusion
I hope you’ve found this short roundup of music hacks interesting. There are some very creative people out there. If you find what they’re doing interesting, please let them know and/or donate so they’ll keep making great stuff.
Why Code4Cheap is destined for failure

I was intrigued by the premise, but I’ve come to the conclusion that it is destined for failure. The first reason is that the title contains the word ‘Cheap’. Cheap has very negative connotations, including “of shoddy quality”. Even the literal definition, “purchasable below the going price or the real value” , presents real problems for the site. Why?
The blog post Pay Enough or Don’t Pay at All by Panos Ipeirotis sums it up perfectly:
There are the social norms and the market norms. When no money is involved, the exchanges operate using social norms. Once you put a price on a task, it becomes part of a market norm. It can be measured and compared. … Instead of offering their priceless help, they were being valued as unskilled workers, like every other worker in the market. Money and altruism do not mix.
A central tenet of the seminal book about the open source movement, “The Cathedral and the Bazaar“, is that the hacker culture thrives as a “gift culture” as opposed to an “exchange culture”. (This chapter of the book is available online if you’re interested in more). Thus we see every day thousands of highly skilled people give away their time and programming effort, both in the open source community and in Q&A sites like StackOverflow. In these instances, the currency consists of reputation and goodwill rather than money.
One must pay a reasonable rate for programming expertise if he is to pay at all, and the current questions on the site are laughably complex for the amount of money that the posters are offering. On top of that, the site takes a 30% cut out of any bounty that a buyer offers for a solution, further disincentivizing prospective programmers (i.e. a $50 bounty actually becomes $35).
I applaud the creator for launching a product, but I’m afraid this one will not last, without some sweeping changes to the business model.
Synergy – free mouse/keyboard sharing across operating systems
Any sufficiently advanced technology is indistinguishable from magic
-Arthur Clarke
I love technology. I especially love discovering and using technology that makes me more productive. I’m writing about a piece of software called Synergy that allows you to use one mouse and keyboard to control multiple computers, each of which may be running different operating systems. In my case, my primary display is for my Mac, and a secondary display off to the right is connected to a Windows PC. Previously, any time I needed to use the Windows machine I had to unplug the USB cable powering the keyboard/mouse combo and physically plug it into the windows machine. (Alternatively I could have bought an extra keyboard and mouse and had to juggle with the physical hardware.) If I needed to transfer text (e.g. a sourcecode snippet) from one machine to the other, I would have to resort to shuttling files or e-mailing it to myself.
By using Synergy, the mouse no longer stops at the right edge of my Mac display. Instead, the cursor continues to move to the right, onto the Windows desktop. Suddenly both your mouse and keyboard control the PC. If you copy text from a file on Windows and revert to controlling the Mac by moving the cursor back to the left, the text is in your Mac clipboard.
That’s not to say that Synergy is perfect. The main problem is that certain key combinations on the Windows side do not transfer correctly. For instance, Ctrl + Alt + Delete is pretty necessary in Windows land, but pressing those keys does not trigger the corresponding action. The Synergy FAQ page has this issue at the very top, but none of the workarounds work for me. I’ve noticed the following keys do not get sent over correctly:
Key combo | Description |
Ctrl Alt Delete | Bring up task manager |
Print screen | Take a screen shot of desktop |
Windows + Any other key | (Windows L = Lock, Windows D = show desktop/hide all windows) |
Other limitations I’ve seen are as follows:
- Pasting is limited to plain text (e.g. you can’t copy an image from one computer to the other).
- You can’t drag and drop files between the screens (this would be awesome); instead best workaround I can find is to have a networked folder accessible to both computers and use it as a dropbox to ferry around files. It’s a bit kludgy but it works.
Each computer will need to install the software and be accessible on the same network. The computer into which the mouse and keyboard are plugged should be the Server. Each of the computers that you wish to control via the mouse and keyboard need to be running the Client software and connect to the server, and the server needs a configuration file which tells it how the screens are physically located (which computer is to the left of which, which is above, etc.)
Finally, there’s a bit of work you need to do to get it to work on windows vista/ 7 – see here for the details.
This is a really great piece of free software, and it allows me to do my job more effectively. I hope you find it useful as well.
XStream introduction and Java Collections serialization problem workaround
XStream is an open-source Java library for converting objects to and from XML. I’ll introduce how to use the library, show a problem I ran into that was a bit difficult to track down, as well as a workaround.
Library example
Imagine we are modeling a library in XML. This will be much simplified for the purposes of illustration. A sample XML library document might look like the following:
<library> <books> <book> <title>The Talent Code: Greatness Isn't Born. It's Grown. Here's How.</title> <author>Daniel Coyle</author> </book> </books> </library>
Let’s write some Java classes to represent this hierarchy.
public class Library { public List<Book> books; public Library(List<Book> books) { this.books = books; } @Override public String toString() { StringBuilder b = new StringBuilder(); b.append("Library with " + books.size() + " books:\n"); for (Book book : books) { b.append(book.toString()); // Skip a line b.append("\n"); } return b.toString(); } public static class Book { private String title; private String author; public Book(String title, String author) { this.title = title; this.author = author; } @Override public String toString() { return "\"" + title + "\" by " + author; } } public static void main(String[] args) { List<Book> books = new ArrayList<Book>(); books.add(new Book("The Talent Code: Greatness Isn't Born. It's Grown. Here's How", "Daniel Coyle")); Library lib = new Library(books); // Handles conversion of our objects into XML XStream stream = new XStream(new DomDriver()); String xml = stream.toXML(lib); // fromXML returns a general Object; need to cast it into a Library Library lib2 = (Library) stream.fromXML(xml); System.out.println(xml); System.out.println(lib); System.out.println(lib2); System.out.println("Libraries equal: " + lib.toString().equals(lib2.toString())); } }
This is not production worthy by any means; in general comparing the string representations of objects to test for equality is a very bad idea. But writing a foolproof equals method is very difficult and irrelevant to the point of this post. Here is the output produced by running the program:
<Library> <books> <Library_-Book> <title>The Talent Code: Greatness Isn't Born. It's Grown. Here's How</title> <author>Daniel Coyle</author> </Library_-Book> </books> </Library> Library with 1 books: "The Talent Code: Greatness Isn't Born. It's Grown. Here's How" by Daniel Coyle Library with 1 books: "The Talent Code: Greatness Isn't Born. It's Grown. Here's How" by Daniel Coyle Libraries equal: true
This is somewhat close to what we want, but not exactly. (Note that the ' stuff in the middle of the title is not a mistake; I was imprecise by including apostrophes in the original XML example. See here for an explanation of why apostrophes are treated specially in XML). Let’s start by aliasing some of the tag names. The relevant change is as follows:
XStream stream = new XStream(new DomDriver()); stream.alias("library", Library.class); stream.alias("book", Book.class);
Output:
<library> <books> <book> <title>The Talent Code: Greatness Isn't Born. It's Grown. Here's How</title> <author>Daniel Coyle</author> </book> </books> </library>
Initial success
OK, looks like things are working! But the way of constructing the list is not how I normally create lists. Let’s make sure the serialization works for alternative means of List construction.
Book talentCode = new Book("The Talent Code: Greatness Isn't Born. It's Grown. Here's How", "Daniel Coyle"); Library lib = new Library(Arrays.asList(talentCode));
For you who haven’t seen the use of Arrays.asList, it’s a method to convert an array (or varargs) into a List. It’s important for compatibility between array based and collection based frameworks. The corresponding method in the opposite direction, from Collections to arrays is the Collections.toArray. For the truly nerdy, here’s an interesting discussion of possible implications of calling toArray in a multithreaded environment.
Anyways, here’s the output.
<library> <books class="java.util.Arrays$ArrayList"> <a class="book-array"> <book> <title>The Talent Code: Greatness Isn't Born. It's Grown. Here's How</title> <author>Daniel Coyle</author> </book> </a> </books> </library> Library with 1 books: "The Talent Code: Greatness Isn't Born. It's Grown. Here's How" by Daniel Coyle Library with 1 books: "The Talent Code: Greatness Isn't Born. It's Grown. Here's How" by Daniel Coyle Libraries equal: true
Hmmm. The XML serialization/deserialization still works but it’s sure not pretty. What’s going on here? Why did it print “books” earlier but now it throws in all that ugly stuff about “java.util.Arrays$ArrayList”?
The answer is that XStream has a powerful set of converters that handle mapping Java constructs to and from XML. The relevant converter is the CollectionConverter. Here is the JavaDoc description, and the solution to the mystery:
Converts most common Collections (Lists and Sets) to XML, specifying a nested element for each item.
Supports java.util.ArrayList, java.util.HashSet, java.util.LinkedList, java.util.Vector and java.util.LinkedHashSet.
The problem is that creating a List via the Arrays.toList method does not create an instance of any of these classes. Instead, it returns an instance of an inner class named ArrayList (not to be confused with the java.util.ArrayList). Read the source of the java.util.Arrays class if you are interested in the implementation details.
What’s the workaround? Don’t blindly accept the list of books that is passed into the constructor. Instead, make a defensive copy.
public List<Book> books = new ArrayList<Book>(); public Library(List<Book> books) { this.books.addAll(books); }
Sure enough, this fixes the problem, as the actual class of the list of books is now one that the converter supports. Alternatively we could change the implementation of CollectionConverter to support the Arrays$ArrayList class, but it’s probably not worth it.
Conclusion
I introduced the XStream library for Java which handles the conversion of objects to and from XML. I presented a very simple Java example of a Library and its collection of books, as well as a problem that arises from the way XStream converts collections into XML.
My ten essential Mac programs
Firefox is my browser of choice. No big surprise there. Not much to say except tabbed browsing is great.
Quicksilver, if you are unfamiliar, is an application launcher for Mac OSX. If you’re a fan of analogies:
Spotlight : Documents :: Quicksilver : Applications
That’s a bit simplistic, as Quicksilver can do more than just launch applications, but that’s 99% of what I use it for, so the analogy stands.
TinyGrab is an amazingly simple screen shot app for both Windows and Mac OS X (I use it on both platforms and it works better on Mac). After registering for an account, you keep the app running in the background. Any time you take a screenshot via Command Shift 3 (full screen capture) or Command Shift 4 (area of screen or window capture), the picture is automatically uploaded to the service, and a small url to the picture is copied to your clipboard. All of the icons you see here are hosted on TinyGrab’s servers and were uploaded near instantaneously. I say it works better on Mac than Windows because the Mac one merely hooks onto the act of capturing a screenshot using the already excellent Mac tools; when you press the hotkey to take a picture on Windows, it has to use its own “clip this area of the screen” feature, and it doesn’t work quite as seamlessly as on the Mac.
You may have already seen my previous R posts; R is a programming language intended for statistics. It has dozens of high-quality open source code modules from mathematicians and scientists from around the world. It is a great tool for doing exploratory data analysis.
R can be used both interactively through the R Console program, as well as through scripts.
If you’re programming in Java and you’re not using an IDE, you are wasting your time. Netbeans and Eclipse are the two biggies in the Java world; I prefer Netbeans due to its great built-in keyboard macros. By memorizing a few keyboard shortcuts, you can save dozens of keystrokes from commonly typed phrases. For instance, declaring constants is usually quite verbose in Java:
public static final int BUFFER_SIZE = 1024;
With netbeans you can shorten the 24 characters before the variable name to five: Psfi -> TAB. There are a whole raft of such shortcuts, and they are indispensable for easing the pain of Java’s verbosity.
Other great and essential features include the ability to automatically determine which modules need to be imported; this feature alone makes an IDE superior to a dumb text editor. The other feature that immediately springs to mind is the ability to easily refactor code; you can change the name of a variable in one file and have it propagate to all files that reference it, rather than having to find and replace the string in all the files.
Unlike the other tools in this post, MacPorts is a command line utility. I use it when I need to install some open source library or project and there is no installer available for my platform. If there’s a port version of the software available, it handles all the dependency management, installs the libraries where they need to go, and updates all the necessary environment variables.
Textmate is my text editor of choice for all things non-Java. It makes it very easy to open a directory as a project and then jump around between files within it (with a very smart, intuitive search feature). Just as netbeans has tab code completions, so does Textmate. Common shortcuts (“snippets”) are bundled up and distributed with the software; it is also easy to add your own. It seems to be the de facto standard for web development (every Ruby on Rails developer I’ve ever met uses it).
Two main complaints:
- Some strange default behavior: If I select a bunch of text and hit tab, I would expect that to indent the text rather than delete the contents of it. Similarly for shift tab. Instead, you must hit option tab and option shift tab (that’s a bit of a finger stretcher)
- You cannot split a window and look at two sections of it at the same time.
WriteRoom is the antithesis of Microsoft Word, or any modern text editor. Whereas most programs throw feature after feature at you, WriteRoom strips it down to the barest of feature sets. The minimalist nature extends to the presentation as well; when you boot it up you begin by staring at a full screen blank picture. Text is monochrome green by default, though both the background and foreground colors can be changed. By stripping all user interface elements out of the view, you are free to focus on the task of writing without any distractions.
Obviously this is not well suited to all tasks; if you are doing any sort of work in which you need to simultaneously reference other materials (e.g. look at a website or excel spreadsheet at the same time), this is not for you. But if you need to brainstorm something and get some thoughts down onto paper, this is a great choice.
There is a free Windows clone called Dark Room, and there is a similar product for the Mac in beta called Ommwriter.
LaTeX (unfortunately named for Google searching) is a typesetting language/program. It’s used extensively by college professors and others looking for beautifully typeset text and equations. Unlike Microsoft Word, composing a document using LaTeX is most certainly not WYSIWYG, but its creators see that as a feature and not a bug. They claim that people waste an inordinate time fiddling with fonts and presentation rather than content. By formatting your work as a Latex document, you can render it in multiple different ways just by changing a template.
The MacTeX package includes LaTeXIt, TeXShop, and BibDesk, as well as a few other programs I never touch.
LaTeXiT is a small program for creating equations and other snippets to embed in other sources.
TeXShop is a full fledged editor of LaTeX documents; if you’re doing any sort of serious document creation, you’re probably going to do it in TeXShop. There’s nothing stopping you from composing your documents in any plaintext editor, but you will have to manually run the scripts that convert your text into PDF; TeXShop automates some of that hassle.
BibDesk is a program for managing bibliographic entries.
An excellent chat/IM client for Mac that supports all the big formats. Recognize your favorite protocol from the icons it supports?
Why install a chat program on a work computer? IM and chat is a big part of collaborative software development.
Conclusion
Some of these programs are fairly well known (Firefox, Adium, Netbeans), but I hope I have exposed you to some new programs.