OS X环境中的音频文件FFT

Ano*_*ous 4 audio macos fft pcm

我想在OS X上对线性PCM音频文件(可能有多个音频通道)执行FFT.最好的方法是什么?

一些消息来源表明,Apple的Accelerate Framework正是我所需要的.如果是这样,我应该如何提取并正确准备浮点数据以用于那些FFT函数?

ale*_*xbw 7

这大致是你想要做的.填写您自己的输入和输出功能.

    // Stick new data into inData, a (float*) array
    fetchFreshData(inData); 

    // (You might want to window the signal here... )
    doSomeWindowing(inData);

    // Convert the data into a DSPSplitComplex 
    // Pardon the C++ here. Also, you should pre-allocate this, and NOT
    // make a fresh one each time you do an FFT. 
    mComplexData = new DSPSplitComplex;
    float *realpart = (float *)calloc(mNumFrequencies, sizeof(float));
    float *imagpart = (float *)calloc(mNumFrequencies, sizeof(float));
    mComplexData->realp = realpart;
    mComplexData->imagp = imagpart;

    vDSP_ctoz((DSPComplex *)inData, 2, mComplexData, 1, mNumFrequencies);

    // Calculate the FFT
    // ( I'm assuming here you've already called vDSP_create_fftsetup() )
    vDSP_fft_zrip(mFFTSetup, mComplexData, 1, log2f(mNumFrequencies), FFT_FORWARD);

    // Don't need that frequency
    mComplexData->imagp[0] = 0.0;

    // Scale the data
    float scale = (float) 1.0 / (2 * (float)mSignalLength);
    vDSP_vsmul(mComplexData->realp, 1, &scale, mComplexData->realp, 1, mNumFrequencies);
    vDSP_vsmul(mComplexData->imagp, 1, &scale, mComplexData->imagp, 1, mNumFrequencies);

    // Convert the complex data into something usable
    // spectrumData is also a (float*) of size mNumFrequencies
    vDSP_zvabs(mComplexData, 1, spectrumData, 1, mNumFrequencies);

    // All done!
    doSomethingWithYourSpectrumData(spectrumData);
Run Code Online (Sandbox Code Playgroud)

希望有所帮助.