<分区>
Possible Duplicate:
How to get Frequency from FFT result
我正在调查 aurioTouch2示例代码。 在绘图 View 函数中,总是调用一个函数来计算 fft 数据,因此我们可以计算不同频率的功率。
Boolean FFTBufferManager::ComputeFFT(int32_t *outFFTData)
{
if (HasNewAudioData())
{
//Generate a split complex vector from the real data
// real1 = -0.005138, real2 = -0.005010; r = -0.005138, im = -0.005010
vDSP_ctoz((COMPLEX *)mAudioBuffer, 2, &mDspSplitComplex, 1, mFFTLength);
//Take the fft and scale appropriately
// FFTSetup mSpectrumAnalysis - koefficients
vDSP_fft_zrip(mSpectrumAnalysis, &mDspSplitComplex, 1, mLog2N, kFFTDirection_Forward);
vDSP_vsmul(mDspSplitComplex.realp, 1, &mFFTNormFactor, mDspSplitComplex.realp, 1, mFFTLength);
vDSP_vsmul(mDspSplitComplex.imagp, 1, &mFFTNormFactor, mDspSplitComplex.imagp, 1, mFFTLength);
//Zero out the nyquist value
mDspSplitComplex.imagp[0] = 0.0;
//Convert the fft data to dB
// calculate complex number abs, write to tmpData
Float32 tmpData[mFFTLength];
vDSP_zvmags(&mDspSplitComplex, 1, tmpData, 1, mFFTLength);
//In order to avoid taking log10 of zero, an adjusting factor is added in to make the minimum value equal -128dB
vDSP_vsadd(tmpData, 1, &mAdjust0DB, tmpData, 1, mFFTLength);
Float32 one = 1;
vDSP_vdbcon(tmpData, 1, &one, tmpData, 1, mFFTLength, 0);
//Convert floating point data to integer (Q7.24)
vDSP_vsmul(tmpData, 1, &m24BitFracScale, tmpData, 1, mFFTLength);
for(UInt32 i=0; i<mFFTLength; ++i)
outFFTData[i] = (SInt32) tmpData[i];
OSAtomicDecrement32Barrier(&mHasAudioData);
OSAtomicIncrement32Barrier(&mNeedsAudioData);
mAudioBufferCurrentIndex = 0;
return true;
}
else if (mNeedsAudioData == 0)
OSAtomicIncrement32Barrier(&mNeedsAudioData);
return false;
}
问题是如何获取我在屏幕上显示的频率变化? 我的意思是,我有针对不同音频频率的电源阵列。我如何理解,例如,最低频率的值是多少?
更新以表达我的观点:
我知道,最低阈值(最低频率)是 outFFTData[0],最高阈值是 outFFTData[last]。但我不知道,例如,与 outFFTData[0] 有关的数字频率是多少。 outFFTData[0]是否与16Hz有关; outFFTData[last] 与 22 kHz 相关吗?
现在我认为,outFFTData[0] 与人能听到的最低音频频率有关; outFFTData[last] 与人能听到的最高音频频率有关。
我错了吗?
更新 2
我看了Paul R代码 here .它确实显示了几乎所有内容。 但是,如果我错了,请纠正我:
在这段代码中:
//Generate a split complex vector from the real data
// real1 = -0.005138, real2 = -0.005010; r = -0.005138, im = -0.005010
vDSP_ctoz((COMPLEX *)mAudioBuffer, 2, &mDspSplitComplex, 1, mFFTLength);
//Take the fft and scale appropriately
// FFTSetup mSpectrumAnalysis - koefficients
vDSP_fft_zrip(mSpectrumAnalysis, &mDspSplitComplex, 1, mLog2N, kFFTDirection_Forward);
vDSP_vsmul(mDspSplitComplex.realp, 1, &mFFTNormFactor, mDspSplitComplex.realp, 1, mFFTLength);
vDSP_vsmul(mDspSplitComplex.imagp, 1, &mFFTNormFactor, mDspSplitComplex.imagp, 1, mFFTLength);
在这段代码中,mFFTLength = mAudioBufferLen/2;
,所以我认为,频率的最大值将在 mDspSplitComplex 中,位于 index = mFFTLength - 1
或者可能是我错了,频率的最大值将在 index = mFFTLength/2 - 1
处的 mDspSplitComplex 中?
更新 3
我有非常相似的问题 Why do we use only the first buffer in aurioTouch project . 可能有人知道答案。