创建基于傅立叶变换的iPhone音乐Visualiser [英] Creating an iPhone music Visualiser based on Fourier Transform
问题描述
我正在为iPhone设计音乐视觉化应用程序。
I am designing a music visualiser application for the iPhone.
我想通过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.
我得到的最好的例子是 aurioTuch ,它根据FFT数据生成完美的图形。但是我一直在努力在我自己的项目中理解/复制aurioTouch。
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.
我无法理解aurioTouch在执行FFT之前从麦克风中拾取哪些数据?
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?
推荐答案
由于我打算自己使用麦克风的输入,我认为你的问题是一个好机会熟悉相关示例代码。
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
开始(因为很明显音频必须得到这个类),你可以看到类方法SpectrumAnalysisProcess
有一个第二个输入参数const int32_t * inTimeSig
---听起来有希望的起点, c>使用右键菜单项在项目中查找
在此方法上,您可以看到除了明显的定义&声明,此方法仅在FFTBufferManager :: ComputeFFT
方法中使用,其中它获取mAudioBuffer
作为其第二个参数来自步骤1)的inTimeSig
。寻找这个类数据成员给出多于2或3个结果,但是大多数都是只是定义/内存分配等。有趣的搜索结果是mAudioBuffer
用作FFTBufferManager :: GrabAudioData
中的 - 寻找
PerformThru
,我们看到它用于以下行:inputProc.inputProc = PerformThru;
- 我们几乎有::看起来像注册一个回调函数。寻找inputProc
的类型,我们确实看到它是AURenderCallbackStruct
- 就是这样。
使用搜索选项,我们看到 FFTBufferManager :: GrabAudioData
只在一个名为 PerformThru
的方法内调用一次。此方法有一个名为 ioData
(听起来很有希望)类型 AudioBufferList
的输入参数。
- Starting off in
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. - Using the right-click menu item
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
. - Again using the search option, we see that
FFTBufferManager::GrabAudioData
is called only once, inside a method calledPerformThru
. This method has an input argument calledioData
(sounds promising) of typeAudioBufferList
. - Looking for
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.
您可能需要阅读文档 AURenderCallbackStruct
(或更好, Audio Unit Hosting )以获得更深入的了解,但我希望这为您提供了一个良好的起点。
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.
这篇关于创建基于傅立叶变换的iPhone音乐Visualiser的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!