我正在构建一款可以让用户重新混合歌曲的游戏。我已经构建了一个混音器(基于Apple示例代码MixerHost(使用混音器audioUnit创建audioGraph),但扩展为加载12个轨道。一切工作正常,但是当游戏玩家加载歌曲时,需要很长时间才能加载歌曲选择他们想要混音的歌曲。这是因为程序必须将 12 个单独的 mp4 文件加载到内存中,然后我才能开始播放音乐。
我认为我需要的是创建一个 AUFilePlayer 音频单元,负责将文件加载到混音器中。如果 AUFilePlayer 可以处理动态加载文件,那么用户将不必等待文件 100% 加载到内存中。我的两个问题是,1.AUFilePlayer可以这样使用吗? 2. AUFilePlayer 的文档非常非常薄。在哪里可以找到一些示例代码,演示如何在 IOS(而不是 MacOS)中正确实现 AUFilePlayer?
谢谢
最佳答案
我认为你是对的 - 在这种情况下,“直接从磁盘”缓冲方法可能就是你所需要的。我相信正确的 AudioUnit 子类型是 AudioFilePlayer。来自文档:
The unit reads and converts audio file data into its own internal buffers. It performs disk I/O on a high-priority thread shared among all instances of this unit within a process. Upon completion of a disk read, the unit internally schedules buffers for playback.
Chris Adamson's book Learning Core Audio 中给出了在 Mac OS X 上使用该装置的工作示例。 。 iOS 的代码没有太大不同,在 this thread 中进行了讨论。在 CoreAudio-API 邮件列表上。 Adamson 的工作代码示例可以找到 here 。您应该能够根据您的要求进行调整。
关于ios - 如何加快音频文件的加载速度,以便用户无需等待。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11434946/