我正在尝试通过 iphone 上的麦克风计算给定声音过程的频率。
我已经阅读了有关 FFT 的所有帖子(包括所有苹果代码示例,例如 aurioTouch、SpeakHere),但没有解决这个问题。
我正在使用 AudioQueue,但是如何从 AudioQueue 回调函数 (MyInputBufferHandler) inBuffer->mAudioData 传递原始数据“AudioQueueBufferRef”。到实际 FFT "DSPSplitComplex" 数据类型,所以我可以计算它。所有这些都使用 Accelerate 框架。
// AudioQueue callback function, called when an input buffers has been filled.
void AQRecorder::MyInputBufferHandler( void * inUserData,
AudioQueueRef inAQ,
AudioQueueBufferRef inBuffer,
const AudioTimeStamp * inStartTime,
UInt32 inNumPackets,
const AudioStreamPacketDescription* inPacketDesc)
{
for(int i=0; i<inNumPackets; i++) {
printf("%d ",((int*)inBuffer->mAudioData)[i]);
}
}
FFT 函数。
RealFFTUsageAndTiming(){
COMPLEX_SPLIT A; //DSPSplitComplex datatype
FFTSetup setupReal;
uint32_t log2n;
uint32_t n, nOver2;
int32_t stride;
uint32_t i;
float *originalReal, *obtainedReal;
float scale;
/* Set the size of FFT. */
log2n = N;
n = 1 << log2n;
stride = 1;
nOver2 = n / 2;
/* Allocate memory for the input operands and check its availability,
* use the vector version to get 16-byte alignment. */
A.realp = (float *) malloc(nOver2 * sizeof(float));
A.imagp = (float *) malloc(nOver2 * sizeof(float));
originalReal = (float *) malloc(n * sizeof(float));
obtainedReal = (float *) malloc(n * sizeof(float));
//How do I pass the data from AudioQueue callback to function?
vDSP_fft_zrip(setupReal, &A, stride, log2n, FFT_FORWARD);
vDSP_fft_zrip(setupReal, &A, stride, log2n, FFT_INVERSE);
}
我还没有找到关于如何做到这一点的任何地方。请帮忙!