Reputation: 32134
I'm trying to write an audio application.
I can play a cin wave from a frequency of 20 to 20K to hear sounds. my question is how can i convert frequencies to keyboard notes in order to create a virtual keyboard (or piano) ? is there some kind of formula to achieve this ?
The programming language that I use is not important because I don't want to use other tools that calculate it for me. i want to write it myself so i need to understand the math behind it. thanks
i found the following url: http://www.reverse-engineering.info/Audio/bwl_eq_info.pdf
that contains the octave prequency chart. do i need to store that list or is there a formula that can be used instead ?
Upvotes: 3
Views: 4628
Reputation: 2346
full reference of P2F F2P conversion functions. i use 69 instead of 57 though. http://musicdsp.org/showone.php?id=125
Upvotes: 0
Reputation: 16753
There are a few different ways to tune instruments. The most commonly used for pianos is the 12 tone equal temperament, a formula for which can be found here. The idea is that each pair of adjacent notes has the same frequency ratio.
See also equal temperament on Wikipedia.
Upvotes: 5
Reputation: 223183
First, you need to know about A440. This is the "standard" pitch to tune everything else against.
Double the frequency to raise an octave; halve the frequency to drop an octave. It's clear from this that the tones are logarithmic relative to the frequencies.
There are multiple systems for deciding where on the logarithmic line the rest of the notes fall. A straightforward approach is to divide the semitones geometrically along the logarithmic scale (which is the approach xofon's answer uses), but there may be better ways.
Upvotes: 2
Reputation: 654
You can calculate frequency of a tone as
f = 440 * exp(x*ln(2)/12)
where x is number of semitones above A in the middle of the piano keyboard.
Upvotes: 5