Skip to content

Instantly share code, notes, and snippets.

@plamere
Created February 21, 2013 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plamere/5004349 to your computer and use it in GitHub Desktop.
Save plamere/5004349 to your computer and use it in GitHub Desktop.
Loudness and Confidence filter
function runLength(quanta, confidenceThreshold, loudnessThreshold, lookAhead, lookaheadMatch) {
var lastState = false;
for (var i = 0; i < quanta.length; i++) {
quanta[i].needsDrums = false;
}
for (var i = 0; i < quanta.length -1; i+=2) {
var newState = getState(quanta[i], confidenceThreshold, loudnessThreshold);
if (newState != lastState) {
// look ahead
var matchCount = 0
var curCount = 0;
for (var j = i + 1; j < quanta.length && j <= i + lookAhead; j++) {
var q = quanta[j];
var nstate = getState(q, confidenceThreshold, loudnessThreshold);
if (nstate == newState) {
matchCount++;
}
curCount++;
}
if (matchCount > lookaheadMatch) {
curState = newState;
} else {
curState = lastState;
}
} else {
curState = newState;
}
quanta[i].needsDrums = curState;
quanta[i+1].needsDrums = curState;
lastState = curState;
}
}
function getState(q, confidenceThreshold, loudnessThreshold) {
var conf = q.confidence;
var volume = q.oseg.loudness_max;
var nstate = conf >= confidenceThreshold && volume > loudnessThreshold;
return nstate;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment