简体   繁体   English

iPhone AudioStreamer AudioQueue实时FFT

[英]iPhone AudioStreamer AudioQueue Realtime FFT

I'm using Matt Gallagher's AudioStreamer to play a mp3 audio stream. 我正在使用Matt Gallagher的AudioStreamer播放mp3音频流。 Now I want to do FFT in realtime and visualize the frequencies using OpenGL ES on the iPhone. 现在我想实时进行FFT并使用iPhone上的OpenGL ES可视化频率。

I'm wondering where to catch the audio data and pass it to my "Super-Fancy-FFT-Computing-3D-Visualization-Method". 我想知道在哪里捕获音频数据并将其传递给我的“Super-Fancy-FFT-Computing-3D-Visualization-Method”。 Matt is using the AudioQueue Framework and there is a Callback function that is set with: Matt正在使用AudioQueue Framework,并且有一个回调函数设置为:

err = AudioQueueNewOutput(&asbd, ASAudioQueueOutputCallback, self, NULL, NULL, 0, &audioQueue);

The Callback looks like this: 回调看起来像这样:

static void ASAudioQueueOutputCallback(void*                inClientData, 
                                AudioQueueRef           inAQ, 
                                AudioQueueBufferRef     inBuffer){...}

In the moment I'm passing the data from the AudioQueueBufferRef and the result looks very weird. 在我从AudioQueueBufferRef传递数据的那一刻,结果看起来很奇怪。 But with FFT and visualizations there are so many points where you can screw it up that I wanted to be sure to pass at least the right data to the FFT. 但是通过FFT和可视化,你可以搞砸了很多点我想确保将至少正确的数据传递给FFT。 I'm reading the data from the Buffer this way ignoring every second value because I only want to analyze one channel: 我正在以缓慢的方式读取缓冲区中的数据,因为我只想分析一个通道:

SInt32* buffPointer = (SInt32*)inBuffer->mAudioData;
int count = 0;
for (int i = 0; i < inBuffer->mAudioDataByteSize/2; i++) {
    myBuffer[i] = buffPointer[count];
    count += 2;
}

Then follows FFT computing with myBuffer containing 512 values. 然后使用包含512个值的myBuffer进行FFT计算。

Instead of sending the data you receive from the audio file stream callback directly to the audio queue, you could convert it to PCM, run your analysis, and then feed it to the audio queue (as PCM) if you still need to play it. 您可以将其转换为PCM,运行分析,然后将其提供给音频队列(如PCM),而不是将从音频文件流回收的数据直接发送回音频队列,如果您仍需要播放它。 To do the conversion, you could use Audio Converter Services (which will be a screaming nightmare without end), or an offline audio queue. 要进行转换,您可以使用音频转换器服务(这将是一个无端的尖叫噩梦)或离线音频队列。

Option 3: look into the new Audio Queue "tap" on iOS 6, which lets you look at data inside a queue. 选项3:查看iOS 6上的新音频队列“点击”,它可以让您查看队列中的数据。 I still need to check this out… it looks cool (and I'm giving a talk on it three weeks at CocoaConf, so, yeah…) 我仍然需要检查一下......它看起来很酷(我在CocoaConf上发表了三个星期的谈话,所以,是的......)

(repost from: http://lists.apple.com/archives/coreaudio-api/2012/Oct/msg00034.html ) (转发自: http//lists.apple.com/archives/coreaudio-api/2012/Oct/msg00034.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM