gpt4 book ai didi

macos - OS X 环境中的音频文件 FFT

转载 作者:行者123 更新时间:2023-12-04 22:52:47 27 4
gpt4 key购买 nike

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

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

最佳答案

这大概是你想要做的。填写自己的输入输出函数。

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

希望有帮助。

关于macos - OS X 环境中的音频文件 FFT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1964955/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com