Created
June 19, 2014 08:59
-
-
Save notthetup/19aace6e5ce2ee1f2027 to your computer and use it in GitHub Desktop.
moogvcf.js
This file contains hidden or 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 MoogVCF(){ | |
var y1, y2, y3, y4, oldx, oldy1, oldy2, oldy3; | |
y1 = y2 = y3 = y4 = oldx = oldy1 = oldy2 = oldy3 = 0; | |
var p, k, t1, t2, r, x; | |
return function(cutoff, res, input){ | |
cutoff = 2 * cutoff / sampleRate; | |
p = cutoff * (1.8 - (0.8 * cutoff)); | |
k = 2 * Math.sin(cutoff * Math.PI * 0.5) - 1; | |
t1 = (1 - p) * 1.386249; | |
t2 = 12 + t1 * t1; | |
r = res * (t2 + 6 * t1) / (t2 - 6 * t1); | |
x = input - r * y4; | |
// four cascaded one-pole filters (bilinear transform) | |
y1 = x * p + oldx * p - k * y1; | |
y2 = y1 * p + oldy1 * p - k * y2; | |
y3 = y2 * p + oldy2 * p - k * y3; | |
y4 = y3 * p + oldy3 * p - k * y4; | |
// clipper band limited sigmoid | |
y4 -= (y4 * y4 * y4) / 6; | |
oldx = x; oldy1 = y1; oldy2 = y2; oldy3 = y3; | |
return y4; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment