Auriotouch, get a musical note from the FFT frequency

I am developing a kind of guitar tuner.

I have a function that gives me the FFT and FFt values ​​for each frequency.

How do I get a musical note? Should I choose the highest peak?

for(y=0; y<maxY; y++){ CGFloat yFract = (CGFloat)y / (CGFloat)(maxY - 1); CGFloat fftIdx = yFract * ((CGFloat)fftLength); double fftIdx_i,fftIdx_f; fftIdx_f = modf(fftIdx, &fftIdx_i); SInt8 fft_l, fft_r; CGFloat fft_l_fl, fft_r_fl; CGFloat interpVal; fft_l = (fftData[(int)fftIdx_i] & 0xFF000000) >> 24; fft_r = (fftData[(int)fftIdx_i + 1] & 0xFF000000) >> 24; fft_l_fl = (CGFloat)(fft_l + 80) / 64.; fft_r_fl = (CGFloat)(fft_r + 80) / 64.; interpVal = fft_l_fl * (1. - fftIdx_f) + fft_r_fl * fftIdx_f; interpVal = CLAMP(0., interpVal, 1.); drawBuffers[0][y] = (interpVal * 120); //NSLog(@"The magnitude for %f Hz is %f.", (yFract * hwSampleRate * .5), (interpVal * 120)); 

}

Thanks so much if you can help.

Julien.

+4
source share
1 answer

This is a non-trivial problem for several reasons:

  • The peak may not correspond to the fundamental harmonic (it may even be absent).
  • The fundamental harmonic will probably not be located exactly in the center of the FFT, so its energy will be distributed over several cells. To estimate the actual frequency, you will need interpolation.
  • If you don’t run a window, you will get a “spectral leakage” effect that will damage your spectrum everywhere, making it difficult to recognize details.

I appreciate that this does not really answer your question, but it should emphasize the fact that it is actually quite a difficult thing to succeed.

+3
source

Source: https://habr.com/ru/post/1343915/


All Articles