问题描述
我已经搜索了一下,但是没有找到任何好的示例或教程来将音频保存到RemoteIO音频单元中。
I've searched around but haven't found any good examples or tutorials of saving audio out of a RemoteIO Audio Unit.
我的设置:使用MusicPlayer API ,我有几个AUSamplers-> MixerUnit-> RemoteIO
My setup: Using the MusicPlayer API, I have several AUSamplers -> MixerUnit -> RemoteIO
音频播放效果很好。我想添加功能以将音频输出保存到文件。我会在RemoteIO上的渲染回调中执行此操作吗?
Audio playback works great. I would like to add functionality to save the audio output to a file. Would I do this in a render callback on the RemoteIO?
任何示例代码的提示或指针都值得赞赏!
Any tips or pointers to example code much appreciated!
推荐答案
由于音频单元回调的严格延迟要求,因此不应进行任何同步文件访问(或可能阻塞的任何其他调用,涉及内存管理或操作系统锁定操作)在RemoteIO回调中。取而代之的是,只需将音频数据复制到另一个缓冲区(例如,较大的循环缓冲区)中,并设置某种状态以指示已复制了多少数据。然后,在另一个线程中,当数据量足够时,将该缓冲区的内容写出到文件中。这可能是原始的PCM文件,以后可以由AVAssetReader / Writer转换为另一种音频文件类型。
Due to the tight latency requirements of Audio Unit callbacks, one should not to do any synchronous file access (or any other calls that could potentially block, involve memory management or OS locking actions) inside the RemoteIO callback. Instead, just copy the audio data out to another buffer (a larger circular buffer for example), and set some state indicating how much data has been copied. Then, in another thread, when the amount of data is sufficient, write the contents of that buffer out to a file. This could be a raw PCM file, which can later be converted by AVAssetReader/Writer into another audio file type.
这篇关于从RemoteIO保存音频的示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!