Need help turning key Hz into numbers
  • I'm sure it involves some log function...I need to separate out the 11 notes of each octave into numbers. C=1, C#=2, D=3, ... , B=11. Ideally, it would wrap around no matter what octave you're in, but that's not essential. Thoughts?

    (Also, C doesn't need to be the root note - if it's easier to do with A as the root, that's fine - I have something that *sorta* works in one octave, but it's not mapped perfectly - see pic)
    IMG_1913.PNG
    1136 x 640 - 72K
  • A bit ago I worked out an equation that does this, its:

    Base frequency (usually 440 hz) * 2^(x/12) with x being the number.

    It will not start at one = C though, 0 would be A and it will go up from there. If you go negative it will loop back around and go down an octave as you would expect.

    You can change this by changing the base frequency, but its best to use 440hz as it is the only exact base frequency I think.

    I think this is correct but this is off the top of my head, here is a link to a full table of notes vs frequencies for reference:
    http://www.seventhstring.com/resources/notefrequencies.html

    edit: oops, thought you meant the reverse, my bad
  • (12 * log2( freq * (32/440) ) + 9) = MIDI note number (A 440 = 69)
  • @JDRaoul - I KNEW there was a way to reverse that formula in the documentation - just had no idea how - thanks!
  • Here's a patch that'll do close to what you want. Only problem is that it doesn't round the note, it chops off the fractional part, and I don't know if that's what you want it to do.

    It gives you three values:
    - the integer note value relative to the base frequency, but inside the 12-note scale
    - the absolute note value relative to the base frequency, but inside the 12-note scale
    - the absolute note value relative to the base frequency. Could be negative.

    You can transform it to a MIDI note, like in JDRaoul's equation, by using 440 as the base frequency and then adding 69 to the Absolute Note number.
    IMG_0118.PNG
    2048 x 1536 - 161K
  • Hm. The patch didn't upload.

    @Taylor, the patch name had '->' in it. I changed it to 'to' and it worked, so apparently there are name restrictions in the upload.
    JJT Hz to Note.audulus
    32K
  • @jjthrash - nice! Thank you both. You should upload it as a subpatch as well (just so people in the future can find it more easily too).
  • @jjthrash, interesting. I had to hack the forum a bit to allow patch files as uploads. I'll take a look at that code and see if I can figure out why it doesn't like '->'.
  • Possibly overzealous HTML escaping, maybe? That would sound similar to @biminiroad's problem with &, since those have to be escaped too.
  • After just a bit of debugging, it looks like the upload works fine. So, I'm guessing the problem is with the followup JS code that turns the result into a preview icon.
    JJT Hz to Note.audulus
    32K
  • image.jpg
    986 x 268 - 25K