在花了很多时间遍历广泛的Core Audio文档迷宫之后,我仍然不确定应该使用C API的哪一部分来在OS X中创建基本的音频样本I / O流。
当我说“ I / O流”时,是指为特定音频设备生成的低延迟流(具有诸如采样率,通道数,位深等参数)并接收/请求交错音频样本的缓冲区由设备播放。
如果有人可以指出我需要的标头和相关功能(甚至是一个示例),我将非常感激:)谢谢!
PS:通常,我会使用PortAudio来实现此目的,但是在这种情况下,我有兴趣直接访问Core Audio框架,以便帮助朋友创建纯Rust便携式音频平台。另外,我已将此问题发布到Apple开发人员论坛,但尚未收到答复,因此我想在这里尝试。如果有更合适的交易所/论坛要问,请告诉我。
完成此操作的最简单方法是使用实例化输出音频单元AudioComponentInstanceNew
。创建实例后,安装将提供音频数据(实时)的渲染回调。Apple有两个可能有用的技术说明:TN2097和TN2091。这样做的代码涉及到一些样板,最终变得有点长。这是如何为默认输出设备创建输出音频单元的示例:
AudioComponent comp;
AudioComponentDescription desc;
AudioComponentInstance auHAL;
//There are several different types of Audio Units.
//Some audio units serve as Outputs, Mixers, or DSP
//units. See AUComponent.h for listing
desc.componentType = kAudioUnitType_Output;
//Every Component has a subType, which will give a clearer picture
//of what this components function will be.
desc.componentSubType = kAudioUnitSubType_HALOutput;
//all Audio Units in AUComponent.h must use
//"kAudioUnitManufacturer_Apple" as the Manufacturer
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
//Finds a component that meets the desc spec's
comp = AudioComponentFindNext(NULL, &desc);
if (comp == NULL) exit (-1);
//gains access to the services provided by the component
AudioComponentInstanceNew(comp, &auHAL);
有第三方库可用来简化该过程。似乎最受欢迎的一种是Novocaine,尽管我个人还没有使用过它。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句