HP Forums
(50g) Convert frequency into note - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (50g) Convert frequency into note (/thread-3806.html)



(50g) Convert frequency into note - Tugdual - 05-08-2015 06:02 PM

If you're into music, you'll possibly find a use for it.
Usage: enter a frequency (Hz), it will return the corresponding closest note and cents deviation.

Code:

%%HP: T(3)A(R)F(,);
\<< { "C" "C#" "D" "Eb" "E" "F" "F#" "G" "Ab" "A" "Bb" "B" } 0, \-> n p
  \<< 440, / LN 2, LN / 12, * DUP 0, RND DUP 3, ROLLD - 100, * 0, RND 'p' STO 57, + DUP 12, MOD 1, + n SWAP GET SWAP 12, / IP R\->I + " " + p R\->I + "ct" +
  \>>
\>>