Last active
February 22, 2018 15:37
-
-
Save andialbrecht/e272abd6e320f6240f78d00b605478dc to your computer and use it in GitHub Desktop.
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
-- Calculates some kind of hammond tuning | |
-- See https://electricdruid.net/technical-aspects-of-the-hammond-organ/ | |
local Ratios = { | |
{85, 104}, | |
{71, 82}, | |
{67, 73}, | |
{105, 108}, | |
{103, 100}, | |
{84, 77}, | |
{74, 64}, | |
{98, 80}, | |
{96, 74}, | |
{88, 64}, | |
{67, 46}, | |
{108, 70} | |
} | |
local rotorSpeed = 20 | |
--- Calculates a "hammond" tuned MIDI pitch. | |
-- @param note A MIDI note pitch 0-127 | |
-- @returns Tuned MIDI note pitch (float) | |
function tune(note) | |
numTeeth = 2 ^ ((note // 12) - 1) | |
abRatios = Ratios[(note % 12) + 1] | |
freq = rotorSpeed * numTeeth * (abRatios[1] / abRatios[2]) | |
return freq2note(freq) | |
end | |
--- Converts a frequency to MIDI note. | |
-- @param freq A The frequency | |
-- @returns A MIDI pitch (something between 0 and 127). | |
local function freq2note(freq) | |
return 12 * math.log(freq / 440) + 69 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment