基于傅里叶变换创建 iPhone 音乐可视化工具
我正在为 iPhone 设计一个音乐可视化应用程序。
我想通过 iPhone 的麦克风采集数据,对其运行傅里叶变换,然后创建可视化来实现这一点。
我能得到的最好的例子是 aurioTuch< /a> 它根据 FFT 数据生成完美的图表。然而,我一直在努力在自己的项目中理解/复制 aurioTouch。
我无法理解 aurioTouch 在执行 FFT 之前到底从麦克风中获取数据的位置?
还有其他代码示例可以用来在我的项目中执行此操作吗?或者还有其他提示吗?
I am designing a music visualiser application for the iPhone.
I was thinking of doing this by picking up data via the iPhone's mic, running a Fourier Transform on it and then creating visualisations.
The best example I have been able to get of this is aurioTuch which produces a perfect graph based on FFT data. However I have been struggling to understand / replicate aurioTouch in my own project.
I am unable to understand where exactly aurioTouch picks up the data from the microphone before it does the FFT?
Also is there any other examples of code that I could use to do this in my project? Or any other tips?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于我计划自己使用麦克风的输入,因此我认为您的问题是熟悉相关示例代码的好机会。
我将追溯阅读代码的步骤:
SpectrumAnalysis.cpp
开始(因为很明显音频必须以某种方式到达此类),您可以看到类方法SpectrumAnalysisProcess
有第二个输入参数const int32_t* inTimeSig
--- 听起来是一个有希望的起点,因为输入时间信号就是我们正在寻找的信号。Find in project
,可以看到除了明显的定义&声明,此方法仅在FFTBufferManager::ComputeFFT
方法内部使用,其中它获取mAudioBuffer
作为其第二个参数(步骤 1 中的inTimeSig
)。查找此类数据成员会给出超过 2 或 3 个结果,但其中大多数都只是定义/内存分配等。有趣的搜索结果是mAudioBuffer
用作memcopy 的参数
,在方法FFTBufferManager::GrabAudioData
内。FFTBufferManager::GrabAudioData
仅在名为PerformThru
的方法内调用一次。此方法有一个名为ioData
(听起来很有前途)的输入参数,其类型为AudioBufferList
。PerformThru
,我们看到它在下面一行中使用:inputProc.inputProc = PerformThru;
- 我们就快到了::它看起来像注册一个回调函数。寻找inputProc
的类型,我们确实看到它是AURenderCallbackStruct
- 就是这样。回调由音频框架调用,音频框架负责向其提供样本。您可能需要阅读
AURenderCallbackStruct
的文档(或者更好的是,音频单元托管)以获得更深入的了解,但我希望这给您一个良好的起点。Since I am planning myself to use the input of the mic, I thought your question is a good opportunity to get familiar with a relevant sample code.
I will trace back the steps of reading through the code:
SpectrumAnalysis.cpp
(since it is obvious the audio has to get to this class somehow), you can see that the class methodSpectrumAnalysisProcess
has a 2nd input argumentconst int32_t* inTimeSig
--- sounds a promising starting point, since the input time signal is what we are looking for.Find in project
on this method, you can see that except for the obvious definition & declaration, this method is used only inside theFFTBufferManager::ComputeFFT
method, where it getsmAudioBuffer
as its 2nd argument (theinTimeSig
from step 1). Looking for this class data member gives more then 2 or 3 results, but most of them are again just definitions/memory alloc etc. The interesting search result is wheremAudioBuffer
is used as argument tomemcopy
, inside the methodFFTBufferManager::GrabAudioData
.FFTBufferManager::GrabAudioData
is called only once, inside a method calledPerformThru
. This method has an input argument calledioData
(sounds promising) of typeAudioBufferList
.PerformThru
, we see it is used in the following line:inputProc.inputProc = PerformThru;
- we're almost there:: it looks like registering a callback function. Looking for the type ofinputProc
, we indeed see it isAURenderCallbackStruct
- that's it. The callback is called by the audio framework, who is responsible to feed it with samples.You will probably have to read the documentation for
AURenderCallbackStruct
(or better off, the Audio Unit Hosting) to get a deeper understanding, but I hope this gave you a good starting point.