Created
March 13, 2015 22:40
-
-
Save quimbs/e91f0ce6997514c967a3 to your computer and use it in GitHub Desktop.
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
var findCentsOffPitch = function(freq, refFreq) { | |
// We need to find how far freq is from baseFreq in cents | |
var log2 = 0.6931471805599453; // Math.log(2) | |
var multiplicativeFactor = freq / refFreq; | |
// We use Math.floor to get the integer part and ignore decimals | |
var cents = Math.floor(1200 * (Math.log(multiplicativeFactor) / log2)); | |
return cents; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment