Skip to content

Instantly share code, notes, and snippets.

@joshstovall
Last active September 10, 2021 07:30
Show Gist options
  • Save joshstovall/3f74a34a57b94f10a128b28cb13741da to your computer and use it in GitHub Desktop.
Save joshstovall/3f74a34a57b94f10a128b28cb13741da to your computer and use it in GitHub Desktop.
pythagorean.js
function pythagorean(e){
var frequency = e;
var cents;
// multiply/divide frequency until between 440 & 880
for (let step = 0; step < 100; step++) {
if (frequency < tuningHz) { frequency = frequency * 2; }
else if (frequency > tuningHz * 2) { frequency = frequency / 2; }
else { break; }
}
midPoints.some(function(v, i) {
if (frequency < v) {
// calulate cents
cents = 1200 * Math.log2(frequency/targetFrequencies[i]);
return frequency < v;
}
});
return cents;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment