在OS X环境的音频文件FFT [英] Audio File FFT in an OS X environment

查看:199
本文介绍了在OS X环境的音频文件FFT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在OS X上寻找一个线性PCM音频文件执行FFT(具有潜在的多个音频频道)什么是去最好的方法?

I'm looking to perform an FFT on a linear PCM audio file (with potentially more than one audio channel) on OS X. What is the best way to go about this?

一些消息人士表示,苹果的加速框架正是我需要的。如果是这样,我应该如何提取和妥善prepare浮点数据在这些FFT功能使用?

Several sources have indicated that Apple's Accelerate Framework is what I need. If so, how should I extract and properly prepare the floating point data for use in those FFT functions?

推荐答案

下面是大致你想要做什么。填你自己的输入和输出功能。

Here's roughly what you want to do. Fill in your own input and output functions.

    // 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);

希望有所帮助。

这篇关于在OS X环境的音频文件FFT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆