I'm working on a musical composition tool and I need to figure out what the resulting frequency would be if I touched (created a harmonic node) some arbitrary pitched string in one or more locations.
These positions need to be given as Midi pitches. So if I needed to create a harmonic with a fundamental of middle C and touch it at the 5th above (G) that would be written like this;
Harmonic(60, 67) #3rd harmonic
which I'd expect to return 79, given:
def toFreq(m):
return pow(2, (m-69)/12)
def toMidi(f):
return 12 * math.log2( f/440 ) + 69
I have been able to implement this so far.
However, if I do:
Harmonic(60, 64) #5th harmonic
I get the wrong answer, this is because I want to 'round' the harmonic below -lets say- the 20th harmonic to reflect a real instrument. Which I have had some success getting to work by limiting the denominator of a Fraction. However this falls apart if I use a higher node from the same harmonic:
Harmonic(60, 69) # also the 5th harmonic, just a different node
The second issue I have, and I have had no success in getting this to work, is having multiple nodes like this.
Harmonic(60, [67, 65]) # where a 'C' string is touched at the 5th and 4th
# this is the 9th harmonic ( a compound major 2nd )
I was wondering if somebody could please help with the algorithm here? The actually classes and python stuff is no issue - this algorithm would go in the initaliser and set a member self.sounding -, and I'd happily have an answer is pseudo code! It also doesn't matter if the return is a midi pitch or frequency, it just needs to take a root pitch and one or more nodes (limited to two if that is easier).
Also, I hope I haven't over tagged this question!