Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calcute note based on frequency

I am creating a tuner on android, I get the audio from the device's microphone and proccess it to get the frequency. However, once I get to transforming the frequency on a note, I wonder if there's a way to do it without having to use a bunch of "IF's", is there a calculation the does this in a more efficient way?

like image 844
hsteffano Avatar asked Dec 03 '25 14:12

hsteffano


1 Answers

Yes, this can be done. First however you must know the key in which to work. Assuming plain C major you'd start with the note a1 being 440Hz. Every octave up doubles the frequency, every octave down halves it, so you've got a nice logarithmic scale, with base 2.

Within a logarithmic scale, multiplications turn into additions. So if you take the intervals of the notes _ with respect to a the ratio between the frequencies remains the same for all octaves. So all you've to find out, which octave you're in, subtract or add that number and the residual is the logarithm of the frequency interval. Finding the octave is simple as well, just evaluate floor(log2(f/440Hz)).

like image 123
datenwolf Avatar answered Dec 05 '25 03:12

datenwolf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!