基于傅里叶变换创建 iPhone 音乐可视化工具

发布于 2024-10-08 20:41:03 字数 390 浏览 3 评论 0原文

我正在为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘味果▽酱 2024-10-15 20:41:03

由于我计划自己使用麦克风的输入,因此我认为您的问题是熟悉相关示例代码的好机会。

我将追溯阅读代码的步骤:

  1. SpectrumAnalysis.cpp 开始(因为很明显音频必须以某种方式到达此类),您可以看到类方法 SpectrumAnalysisProcess 有第二个输入参数 const int32_t* inTimeSig --- 听起来是一个有希望的起点,因为输入时间信号就是我们正在寻找的信号。
  2. 使用此方法上的右键菜单项Find in project,可以看到除了明显的定义&声明,此方法仅在 FFTBufferManager::ComputeFFT 方法内部使用,其中它获取 mAudioBuffer 作为其第二个参数(步骤 1 中的 inTimeSig )。查找此类数据成员会给出超过 2 或 3 个结果,但其中大多数都只是定义/内存分配等。有趣的搜索结果是 mAudioBuffer 用作 memcopy 的参数,在方法 FFTBufferManager::GrabAudioData 内。
  3. 再次使用搜索选项,我们看到 FFTBufferManager::GrabAudioData 仅在名为 PerformThru 的方法内调用一次。此方法有一个名为 ioData(听起来很有前途)的输入参数,其类型为 AudioBufferList
  4. 寻找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:

  1. Starting off in SpectrumAnalysis.cpp (since it is obvious the audio has to get to this class somehow), you can see that the class method SpectrumAnalysisProcess has a 2nd input argument const int32_t* inTimeSig --- sounds a promising starting point, since the input time signal is what we are looking for.
  2. 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 the FFTBufferManager::ComputeFFT method, where it gets mAudioBuffer as its 2nd argument (the inTimeSig 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 where mAudioBuffer is used as argument to memcopy, inside the method FFTBufferManager::GrabAudioData.
  3. Again using the search option, we see that FFTBufferManager::GrabAudioData is called only once, inside a method called PerformThru. This method has an input argument called ioData (sounds promising) of type AudioBufferList.
  4. 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 of inputProc, we indeed see it is AURenderCallbackStruct - 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文