I'm developing a kind of guitar tuner.
我正在开发一种吉他调谐器。
I have a function that gives me the FFT, and the values of the FFt for each frequency.
我有一个函数给出FFT,以及每个频率的FFT值。
How do I get the musical note from there? Do I have to chose 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 a lot if you can help.
如果你能帮忙,非常感谢。
Julien.
朱利安。
1 个解决方案
#1
3
This is a non-trivial problem, for several reasons:
这是一个非常重要的问题,原因如下:
- The peak may not correspond to the fundamental harmonic (it may even be missing).
- 峰值可能与基本谐波不一致(它甚至可能缺失)。
- The fundamental harmonic will probably not land precisely on the centre of an FFT bin, so its energy will be spread across multiple bins. You would need to do interpolation to estimate the actual frequency.
- 基本谐波可能不会精确地落在FFT容器的中心,所以它的能量会分散在多个容器中。你需要做插值来估计实际的频率。
- Unless you perform some kind of windowing, you will get "spectral leakage" effects, which will smear your spectrum all over the place, making it hard to discern details.
- 除非你进行某种开窗,否则你会得到“光谱泄漏”效应,这会把你的光谱弄得到处都是,让你很难辨别细节。
I appreciate that this doesn't really answer your question, but it should highlight the fact that this is actually a pretty tricky thing to do well.
我很欣赏这并不能真正回答你的问题,但它应该强调这实际上是一件非常棘手的事情。
#1
3
This is a non-trivial problem, for several reasons:
这是一个非常重要的问题,原因如下:
- The peak may not correspond to the fundamental harmonic (it may even be missing).
- 峰值可能与基本谐波不一致(它甚至可能缺失)。
- The fundamental harmonic will probably not land precisely on the centre of an FFT bin, so its energy will be spread across multiple bins. You would need to do interpolation to estimate the actual frequency.
- 基本谐波可能不会精确地落在FFT容器的中心,所以它的能量会分散在多个容器中。你需要做插值来估计实际的频率。
- Unless you perform some kind of windowing, you will get "spectral leakage" effects, which will smear your spectrum all over the place, making it hard to discern details.
- 除非你进行某种开窗,否则你会得到“光谱泄漏”效应,这会把你的光谱弄得到处都是,让你很难辨别细节。
I appreciate that this doesn't really answer your question, but it should highlight the fact that this is actually a pretty tricky thing to do well.
我很欣赏这并不能真正回答你的问题,但它应该强调这实际上是一件非常棘手的事情。