This is a frequency to MIDI note converter, but I can't seem to get the math to work properly. Specifically, with the math.log()
function. This will produce an output of 69.0 most of the time, but it usually outputs "ValueError: math domain error", if I input any number below 440. How should I fix it?
#d=69+12*log(2)*(f/440)
#f=2^((d-69)/12)*440
#d is midi, f is frequency
import math
f=raw_input("Type the frequency to be converted to midi: ")
d=69+(12*math.log(int(f)/440))/(math.log(2))
print d`