是的,最好的方法是使用图表。
RemoteIO 输入实际上是拉式架构(不是推式)。渲染回调是您提供输入样本(sin wav 数据)的地方。它每 X 毫秒回调一次,并要求您将样本复制到 .所以它会提取你的数据。您没有按照自己的条件构建缓冲区并“推入”音频系统。相反,您在它请求更多数据时将其复制(拉取)。
因此,如果您想添加更多音频单元,则需要将它们与图表连接起来。 remoteIO 单元将是链中的最后一个。将在远程 IO 之前添加一个混响单元。所以它看起来像这样:
[ 混响 ] - [ RemoteIO(输出元素)]
您的混响输出进入远程 IO 输入。当远程 IO 需要采样时,它会从混响单元中拉取。图形连接负责将拉动传递给混响单元的远程 IO。这将自动触发您的混响单元的回调。所以你现在需要在混响输入回调中编写你的样本。
会发生什么:
- 硬件说给我一些样品。
- 它调用您的远程 IO 渲染
打回来。
- 您的远程 IO 调用您的混响输入回调
(通过图连接)
- 您为混响输入提供样本
回调。
图表很好,因为您可以将事物“连接”在一起并在信号链中添加/删除事物。它只是不断拉动整个链条,最终您将数据提供给链条中的第一个单元。
如果您以前从未制作过图表,请务必绝对检查每一步的返回码。
所有这些函数都有错误代码返回一个 OSStatus
AUGraphOpen, AUGraphNodeInfo, AUGraphConnectNodeInput, AUGraphInitialize, AudioUnitSetProperty, AUGraphStart, etc.
初始化图表后,您可以使用CAShow(_audioGraph) 将其显示到控制台并获得如下输出:
Member Nodes:
node 1: 'auou' 'rioc' 'appl', instance 0x7a141060 O I
node 2: 'aumx' 'mcmx' 'appl', instance 0x7a021810 O I
node 3: 'aufx' 'rvb2' 'appl', instance 0x7a0a84a0 O I
node 4: 'aufc' 'splt' 'appl', instance 0x7a025b90 O I
node 5: 'aufc' 'conv' 'appl', instance 0x7a24b9e0 O I
node 6: 'augn' 'afpl' 'appl', instance 0x7a22a220 O
Connections:
node 2 bus 0 => node 3 bus 0 [ 2 ch, 44100 Hz, 'lpcm' (0x00000029) 32-bit little-endian float, deinterleaved]
node 3 bus 0 => node 1 bus 0 [ 2 ch, 44100 Hz, 'lpcm' (0x00000029) 32-bit little-endian float, deinterleaved]
node 4 bus 0 => node 2 bus 0 [ 2 ch, 44100 Hz, 'lpcm' (0x00000029) 32-bit little-endian float, deinterleaved]
node 5 bus 0 => node 4 bus 0 [ 2 ch, 44100 Hz, 'lpcm' (0x00000029) 32-bit little-endian float, deinterleaved]
Input Callbacks:
{0x6ccf0, 0x7a13da00} => node 5 bus 0 [2 ch, 44100 Hz]
CurrentState:
mLastUpdateError=0, eventsToProcess=F, isInitialized=T, isRunning=F