iphone - 如何检测 aurioTouch 项目中最低和最高频率的值

标签 iphone ios audio frequency frequency-analysis

<分区>

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 . 可能有人知道答案。

最佳答案

所有 的 FFT 输出箱中都会有一定程度的能量 - 您需要确定一个阈值,然后找到幅度超过该阈值的箱。

至于解释每个输出 bin 的相应频率,请参阅 this excellent answer .

关于iphone - 如何检测 aurioTouch 项目中最低和最高频率的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11499171/

相关文章:

iphone - UIButtons 事件 Touch up 里面不能正常使用?

ios - 单击 DatePicker 时 UITapGestureRecognizer 不工作

ios - 关闭 UITableViewController 时保留选定的行 - Swift,UITableView

ios - 为什么 removeFromSuperview() 不折叠 tableview 的 subview ?

javascript - 如何将音频文件像流一样加载到 AudioContext 中?

audio - 复用到 MPEG-TS : wrong parameters for audio stream

audio - 在播放中播放声音的问题

ios - 在 ScrollView iOS sdk 中缩放图像

objective-c - 我的心理障碍——努力学习 Objective C

ios - 在应用商店或 Paypal 或其他地方?