Loudness and Confidence filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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