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.

2 comments:

Brian Whitman 00:46  

very nice!!! Thank you for posting this.

Anonymous 01:56  

Great!, it would be perfect if you add support for requests and fetching directly to the server.

I'm going to try your library :).

blog archive

labels

recent bookmarks

recent music

recent photos

www.flickr.com

about this blog

I'm Tristan Ferne and I'm a coder/producer/manager in thePrototyping team of BBC R&D and also look after BBC Radio Labs. I'm interested in lots of things, but here I write about the web, media, music and books. You can contact me at tristanferne at yahoo[dot]co[dot]uk

Why is it called cookin'/relaxin'? They're the titles of two of a series of Miles Davis albums which also describe some of my favourite things.

View my complete profile

other blogs

food at cookin'/relaxin' My food blog

  © Blogger template 'Photoblog' by Ourblogtemplates.com 2008

Back to TOP