cookin/relaxin
Showing posts with label processing.org. Show all posts
Showing posts with label processing.org. Show all posts

Friday, April 11, 2008

A Processing library for EchoNest

I've just built my first Processing library. It's probably of no use to anybody but y'never know. It's just a parser for the EchoNest Analysis API - a music analysis tool that generates detailed descriptions of a song's structure and musical content. I've been playing with it recently to create visualisations in Processing.

Download the library

Just create a directory called "echonest" in your Processing/libraries folder. Inside that put the contents of the unzipped archive. The important bit is that you end up with another directory called "library" containing the "echonest.jar" file. Restart Processing and add "import echonest.*;" to the top of your sketch.

The library just parses the EchoNest XML format and provides easy access to that data. To do the actual analysis you need to go here and follow the instructions. The library is used like this...


echonest = new EchoNest(this); // Create an instance
echonest.parseXML(analysisFile); // Parse the EchoNest XML (it should be in the data directory)
println(echonest.tempo); // Print out the tempo
// Print out the start times for all the sections...
for (int ct=0; ct<echonest.sections.length; ct++) {
println(echonest.sections[ct].start);
}


...where "analysisFile" is the location of the XML file you got from the EchoNest API as described here and should be in the /data directory of your sketch.

You can then access all the attributes of the song with the following fields:

public String decoderName, decoderVersion;
public float trackDuration, trackUsableDuration;
public int trackVersion;
public float endOfFadeIn, startOfFadeOut;
public int sizeTimbre, sizePitches;
public int numBeats, numTatums, numSegments, numSections;
public float segmentDurationMean, segmentDurationVariance;
public float timeLoudnessMaxMean, loudMaxMean, loudnessMaxVariance;
public loudnessBeginMean, loudnessBeginVariance;
public loudnessDynamicsMean, loudnessDynamicsVariance, loudness;
public float tempo, tempoConfidence, beatVariance;
public float tatum, tatumConfidence, numTatumsPerBeat;
public int timeSignature;
public float timeSignatureStability;
public float[] timbreMean;
public float[] timbreVariance;
public float[] pitchMean;
public float[] pitchVariance;
public float[] tatums;
public Section[] sections = new Section[0];
public Segment[] segments = new Segment[0];


The Section class has the following fields:

public float start;
public float duration;


The Segment class has the following fields:

public float start;
public float duration;
public float loudnessBegin, loudnessMax, loudnessEnd, timeLoudnessMax;
public float[] pitches;
public float[] timbreCoeff;


These fields are all as described in the EchoNest documentation and the source code is included in the download if you get stuck.

That's about it. Let me know if you find it useful.

Wednesday, May 30, 2007

Hardware hacking at the BBC

Last week we ran a hardware hacking session at BBC Audio & Music Interactive. Two teams of three, formed from across discipines, came together on a Monday morning. At their disposal they had a Phidgets interface kit, a servo kit, a couple of RFID kits, a slightly handicapped Teleo board (the cleaners threw a load of sensors away on Thursday night!) and a Nabaztag wireless bunny.

We were aiming for something that would get people making stuff and having fun, as well as being a good team building exercise and providing a new perspective on interface design. We like the quote from the Arduino booklet...

Physical Computing is about prototyping with electronics, turning sensors, actuators and microcontrollers into materials for designers and artists. It involves the design of interactive objects that can communicate with humans using sensors and actuators controlled by a behaviour implemented as software running inside a microcontroller.


The brief we gave to the teams was to build something to do with discovering new music, but using a physical interface. And preferably involving data from the internet. 10 working hours later they had built an RFID-reading, profile creating, music recommending rabbit and a monster who rates your iTunes tracks.

The first team built Zoltar, the music predicting rabbit. This worked by swiping a number of RFID-enabled objects to build up a musical profile. These objects represented bands or genres of music; Oasis (the popular fruit drink), rock, cheese, a glitterball (disco) and a couple of red hot chilli peppers (kind of). Once the profile was complete, swiping the OK tag caused music recommendations to be generated (via last.fm) and read out by a Nabaztag rabbit.

RFID-tagged objects

RFID music recommender

The second team built iRate - a monster that is used to rate your tracks in iTunes. His LED teeth indicate the rating of the currently playing iTunes track and his arm can then be moved up and down to change the rating in real time. Poking the microswitch in his eye causes iTunes to skip to the next track. There was also a virtual interface showing iRate's current expression on-screen. I love the monster/box - apparently inspired by http://www.readymech.com/; free flat-pack toys to print and build.

Building the iRate

The iRate

Overall I was extremely impressed with what the teams built in such a short time. Particularly as they came to hardware hacking with little or no experience. Ideally we'd have had a day of just tinkering and hacking to get to know what the hardware and the software can do together, then we'd have a couple of days of actually building something. But, I think, everyone had fun and we had a packed demo session at the end of the second day. One of the remits of the R&D team here is to encourage innovation, in both thinking and doing, and I think this was pretty successful in getting people fired up, thinking differently and just doing stuff.