cookin/relaxin

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.

1 comments:

Brian Whitman said...

very nice!!! Thank you for posting this.