Skip to content

Instantly share code, notes, and snippets.

@andialbrecht
Last active February 22, 2018 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andialbrecht/e272abd6e320f6240f78d00b605478dc to your computer and use it in GitHub Desktop.
Save andialbrecht/e272abd6e320f6240f78d00b605478dc to your computer and use it in GitHub Desktop.
-- 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