我相信具有 kAudioUnitSubType_RemoteIO 的单个音频组件的简约低级方法将在低延迟和 Swift 支持。假设 interface(为方便起见,此处命名)myAudioController 已正确声明和初始化,以下代码 inside 已注册 渲染回调 应该进行实时 I/O 映射(虽然这里是用 C 编写的):
myAudioController *myController = (myAudioController *)inRefCon;
//this would render inNumberFrames of data from audio input...
AudioUnitRender(myController->audioUnit,
ioActionFlags,
inTimeStamp,
bus1,
inNumberFrames,
ioData);
//from here on, individual samples can be monitored and processed...
AudioBuffer buffer = ioData->mBuffers[0];
Swift 中的等效代码 sn-p 可能如下所示:
let myController = UnsafeMutablePointer<myAudioController>(inRefCon).memory
AudioUnitRender(myController.audioUnit,
ioActionFlags,
inTimeStamp,
bus1,
inNumberFrames,
ioData)
for buffer in UnsafeMutableAudioBufferListPointer(ioData) { ... }
有关详细信息,请随时查阅 Apple 的参考页面 - 文档非常详细:
https://developer.apple.com/library/ios/documentation/AudioUnit/Reference/AUComponentServicesReference/#//apple_ref/c/func/AudioUnitRender
这也可能是一个有价值的网站,其中包含用 Swift 重写的必读教科书中的 C 示例:https://github.com/AlesTsurko/LearningCoreAudioWithSwift2.0
重要的是了解你在做什么。其他一切都应该是不言自明的,不应该涉及太多的工作。希望这可以帮助...