I think what you want is a tonegenerator that is triggered.
https://onlinetonegenerator.com/
I think for anything more advance you would have to read up on Nyqvist sampling theorem to make sampled instruments tuned into "notes".
I once i wrote an algorithm to overcome the donald duck effect produced by upsampling a note into higher frequensy.
It was just a statistical approach keeping the sampling length the same "sort of a bitwig", long before sampletank existed.
Yeah i just pushed in bits.
So you should Google for howto build a HTML5 tonegenerator.
Just relearned that an octave in hz is just a double of the basefrequency A note 440 so next 880? But lower is just half 220 so multiples, so two ocaves above must be 1760`?
And then it is just divide respective octave into semitones using same philosophy?
I guess it is when Nyqvist theorem come into play it get alot more confusing...
"By international agreement (adopted by the International Standards Organization (the ISO) in 1939 in London), the reference frequency for tuning instruments is 440 Hz. An octave higher than 440 Hz is 880 Hz. An octave lower than 440 Hz is 220 Hz. A perfect fifth higher than 440 Hz is 660 Hz."