是否可以将压缩的音频文件直接加载到缓冲区中而不进行转换?

发布于 2024-12-02 12:50:39 字数 558 浏览 3 评论 0 原文

我正在开发一个 iOS 应用程序,它必须同时处理多个立体声音频文件(持续时间从几秒到四分钟不等),同时播放最多三个音频文件,并通过基于多通道混合器的 AUGraph 进行同步。我的音频文件被压缩 - 无论是 MP3、AAC 或 CAF - 但当它们加载到缓冲区中时,它们会转换为 32 位 AudioUnitSampleType 格式(我的代码基于 Apple 的 iPhoneMultichannelMixerTest)。不用说,有了如此大的缓冲区,应用程序内存很快就会成为一个问题。

Apple 文档指出,iOS 设备一次只能在硬件中解码一个 MP3/AAC 文件,对于需要在软件中解码的其他文件,建议使用 CAF (IMA4) 格式。在开发一个在播放期间动态加载音频的系统之前,我想知道是否可以将压缩文件直接加载到缓冲区中(从而显着减少内存需求)并让我的 AUGraph 即时转换它们?

I am developing an iOS app that must handle several stereo audio files (ranging from a few seconds to four minutes in duration) at once, playing up to three back simultaneously, synched through a Multi-Channel-Mixer-based AUGraph. My audio files are compressed – either as MP3, AAC or CAF – but when they are loaded into buffers are converted into the 32-bit AudioUnitSampleType format (my code is based on Apple's iPhoneMultichannelMixerTest). Needless to say, with such large buffers, app memory very quickly becomes an issue.

Apple's documentation states that iOS devices can decode one MP3/AAC file in hardware at a time, recommending CAF (IMA4) format for other files needing decoding in software. Before I develop a system for dynamically loading audio during playback I want to know if it is possible to load the compressed files into buffers directly (thereby significantly reducing memory requirements) and having my AUGraph convert them on the fly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

牛↙奶布丁 2024-12-09 12:50:39

为了回答我自己的问题,如果需要的只是音频的精确播放同步,而无需使用音频单元处理进行自定义处理,那么一定要看看 AVFoundation 的 AVPlayer, AVAssetAVComposition 类。

虽然这种方法看起来更适合视频播放,但它仅使用音频资源效果非常好。这些类处理媒体资产(包括 CAF、AAC 和 MP3)的所有加载和缓冲,仅使用少量内存,并且可以使用 AVURLAssetPreferPreciseDurationAndTimingKey 紧密同步。此外,它还具有有用的回调方法,可以设置为在播放期间的特定时间调用(用于更新 UI 等)。最后,当它在 Mac(10.7+)上可用时,它是通用 Cocoa 开发的一个很好的解决方案。

To answer my own question, if all one needs is precise playback-synchronisation of audio, without the custom processing possible using Audio Unit processing, then definitely look at AVFoundation's AVPlayer, AVAsset and AVComposition classes.

Whilst this method looks more suited to video playback, it works perfectly well using only audio assets. These classes handle all the loading and buffering of media assets (including CAF, AAC and MP3), using a tiny amount of memory in doing so, and can be tightly synchronised using the AVURLAssetPreferPreciseDurationAndTimingKey. Also, it has useful callback methods that can be set to invoke at specific times during playback (for updating the UI, amongst other things). Finally, as it became available on Mac (10.7+) it is a good solution for universal Cocoa development.

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