带混音器的 NewTimePitch
NewTimePitch with Mixer
我的图表与 Apple 提供的示例应用程序非常相似。
我的 mixerNode 由自定义数据(而不是 guitar/beats)提供 - 但设置相似。两条总线在调音台上都是立体声的。
我正在尝试对内容进行时移,但到目前为止还没有成功。我尝试向图表中添加 kAudioUnitSubType_NewTimePitch,但无论何时添加图表都无法创建。有没有关于我如何使用混频器单元进行时移(移动所有总线)的源代码示例?
这是一些工作代码:
// Describe audio component
AudioComponentDescription output_desc;
bzero(&output_desc, sizeof(output_desc));
output_desc.componentType = kAudioUnitType_Output;
output_desc.componentSubType = self.componentSubType;
output_desc.componentFlags = 0;
output_desc.componentFlagsMask = 0;
output_desc.componentManufacturer = kAudioUnitManufacturer_Apple;
// multichannel mixer unit
AudioComponentDescription mixer_desc;
bzero(&mixer_desc, sizeof(mixer_desc));
mixer_desc.componentType = kAudioUnitType_Mixer;
mixer_desc.componentSubType = kAudioUnitSubType_MultiChannelMixer;
mixer_desc.componentFlags = 0;
mixer_desc.componentFlagsMask = 0;
mixer_desc.componentManufacturer = kAudioUnitManufacturer_Apple;
// Describe NewTimePitch component
AudioComponentDescription speed_desc;
bzero(&speed_desc, sizeof(speed_desc));
speed_desc.componentType = kAudioUnitType_FormatConverter;
speed_desc.componentSubType = kAudioUnitSubType_NewTimePitch;
speed_desc.componentFlags = 0;
speed_desc.componentFlagsMask = 0;
speed_desc.componentManufacturer = kAudioUnitManufacturer_Apple;
result = AUGraphAddNode(mGraph, &output_desc, &outputNode);
if (result) { printf("AUGraphNewNode 1 result %ld %4.4s\n", (long)result, (char*)&result); return; }
result = AUGraphAddNode(mGraph, &speed_desc, &timeNode );
if (result) { printf("AUGraphNewNode 2 result %ld %4.4s\n", (long)result, (char*)&result); return; }
result = AUGraphAddNode(mGraph, &mixer_desc, &mixerNode );
if (result) { printf("AUGraphNewNode 3 result %ld %4.4s\n", (long)result, (char*)&result); return; }
result = AUGraphConnectNodeInput(mGraph, mixerNode, 0, outputNode, 0);
if (result) { printf("AUGraphConnectNodeInput mixer-> time result %ld %4.4s\n", (long)result, (char*)&result); return; }
// open the graph AudioUnits are open but not initialized (no resource allocation occurs here)
result = AUGraphOpen(mGraph);
if (result) { printf("AUGraphOpen result %ld %08lX %4.4s\n", (long)result, (long)result, (char*)&result); return; }
result = AUGraphNodeInfo(mGraph, mixerNode, NULL, &mMixer);
if (result) { printf("AUGraphNodeInfo mixer result %ld %08lX %4.4s\n", (long)result, (long)result, (char*)&result); return; }
result = AUGraphNodeInfo(mGraph, timeNode, NULL, &mTime);
if (result) { printf("AUGraphNodeInfo time result %ld %08lX %4.4s\n", (long)result, (long)result, (char*)&result); return; }
result = AUGraphNodeInfo(mGraph, outputNode, NULL, &mOutput);
if (result) { printf("AUGraphNodeInfo output result %ld %08lX %4.4s\n", (long)result, (long)result, (char*)&result); return; }
UInt32 numbuses = 1;
result = AudioUnitSetProperty(mMixer, kAudioUnitProperty_ElementCount, kAudioUnitScope_Input, 0, &numbuses, sizeof(numbuses));
if (result) { printf("AudioUnitSetProperty bus result %ld %08lX %4.4s\n", (long)result, (long)result, (char*)&result); return; }
for (int i = 0; i < numbuses; ++i) {
// setup render callback struct
AURenderCallbackStruct rcbs;
rcbs.inputProc = &mixerInput;
rcbs.inputProcRefCon = (__bridge void *)(outputStream);
printf("set kAudioUnitProperty_SetRenderCallback for mixer input bus %d\n", i);
// Set a callback for the specified node's specified input
result = AUGraphSetNodeInputCallback(mGraph, mixerNode, i, &rcbs);
// equivalent to AudioUnitSetProperty(mMixer, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, i, &rcbs, sizeof(rcbs));
if (result) { printf("AUGraphSetNodeInputCallback result %ld %08lX %4.4s\n", (long)result, (long)result, (char*)&result); return; }
// set input stream format to what we want
printf("set mixer input kAudioUnitProperty_StreamFormat for bus %d\n", i);
result = AudioUnitSetProperty(mMixer, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, i, mAudioFormat.streamDescription, sizeof(AudioStreamBasicDescription));
if (result) { printf("AudioUnitSetProperty result %ld %08lX %4.4s\n", (long)result, (long)result, (char*)&result); return; }
}
result = AudioUnitSetProperty(mMixer, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &streamInAudioFormat, sizeof(streamInAudioFormat));
if (result) { printf("AudioUnitSetProperty mixer result %ld %08lX %4.4s\n", (long)result, (long)result, (char*)&result); return; }
result = AudioUnitSetProperty(mOutput, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &streamInAudioFormat, sizeof(streamInAudioFormat));
if (result) { printf("AudioUnitSetProperty output result %ld %08lX %4.4s\n", (long)result, (long)result, (char*)&result); return; }
CAShow(mGraph);
// now that we've set everything up we can initialize the graph, this will also validate the connections
result = AUGraphInitialize(mGraph);
if (result) { printf("AUGraphInitialize result %ld %08lX %4.4s\n", (long)result, (long)result, (char*)&result); return; }
此代码有效 - 我有一个混音器,我可以通过回调将数据泵入其中。你可以看到我创建了时间节点,但无论我将它插入到图中的哪个位置,它都会杀死它。我也无法设置流格式或其他任何内容。
理想情况下我想做这样的事情:
result = AUGraphConnectNodeInput(mGraph, mixerNode, 0, timeNode, 0);
result = AUGraphConnectNodeInput(mGraph, timeNode, 0, outputNode, 0);
但这不起作用。
这是该设置的输出:
AudioUnitGraph 0x385003:
Member Nodes:
node 1: 'auou' 'vpio' 'appl', instance 0x134f40b10 O
node 2: 'aufc' 'nutp' 'appl', instance 0x134e733b0 O
node 3: 'aumx' 'mcmx' 'appl', instance 0x134ea71d0 O
Connections:
node 3 bus 0 => node 2 bus 0 [ 2 ch, 44100 Hz, 'lpcm' (0x00000029) 32-bit little-endian float, deinterleaved]
node 2 bus 0 => node 1 bus 0 [ 1 ch, 0 Hz, 'lpcm' (0x00000029) 32-bit little-endian float, deinterleaved]
Input Callbacks:
{0x100038ea0, 0x134f7f900} => node 3 bus 0 [2 ch, 44100 Hz]
CurrentState:
mLastUpdateError=0, eventsToProcess=F, isInitialized=F, isRunning=F
2016-01-07 23:21:32.230 R5ProTestbed[901:503908] 23:21:32.229 ERROR: [0x19ff25000] 2776: ConnectAudioUnit failed with error -10868
2016-01-07 23:21:32.230 R5ProTestbed[901:503908] 23:21:32.230 ERROR: [0x19ff25000] 1682: Initialize failed with error -10868
根据CAShow,您当前的图表是这样的:
混音器 -> TimePitch -> VoiceProcess
(你的输出节点不在图中)
您无法将混音器输出额外连接到其他设备
在你的代码中,你有
result = AUGraphConnectNodeInput(mGraph, mixerNode, 0, timeNode, 0);
所以你不能同时添加
result = AUGraphConnectNodeInput(mGraph, mixerNode, 0, outputNode, 0);
以上两条线都会导致图表混乱,并且它不知道您希望混合器的输出去哪里。
同样,您将混音器输出连接到输出节点
result = AUGraphConnectNodeInput(mGraph, mixerNode, 0, outputNode, 0);
所以你不能同时将时间节点连接到输出节点
result = AUGraphConnectNodeInput(mGraph, timeNode, 0, outputNode, 0);
同时拥有这两个会混淆图形,因为输出节点有两个输入而且它只能有一个。
这就像你试图建立 "Y" 连接,而就连接而言,你无法做到这一点。
您可以将输出放在一个输入上,这样两行就会发生冲突。弄清楚你想要它在链中的什么位置,并将一个输出连接到一个输入。
然后将渲染回调设置为链中的第一个节点。
来自您的评论"I am trying to do mixer->newtimepitch->IO"
你需要制作三个节点,
- 将混音器输出连接到 Time Pitch
- 将 Time Pitch 连接到 RemoteIO
您需要 3 个节点。两次 AUGraphConnectNodeInput() 调用。
将渲染回调连接到混音器。像这样:
result = AUGraphConnectNodeInput(mGraph, mixerNode, 0, timeNode, 0);
result = AUGraphConnectNodeInput(mGraph, timeNode, 0, outputNode, 0);
和你一样。确保从您的代码中删除其他节点连接。我不知道您是删除了其他连接还是将它们留在原处并添加了更多连接。
如果不手动配置错误检查,默认音频格式可能不合适。您需要将混音器的输出格式设置为 time-pitch 单元的输入格式,并将您的输出节点(RemoteIO?)的输入格式设置为 time-pitch 单元的输出格式。在连接单元之前需要配置格式。
不要在时间间距单位上设置格式。获取时间间距单位的格式,并在时间间距连接的所有内容上设置这些格式。
hotpaw2 自己想通了就回答了。非常感谢。我在混音器和 IO 的输出上设置 StreamFormat,通过停止它,转换器能够运行。
// result = AudioUnitSetProperty(mMixer, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &streamInAudioFormat, sizeof(streamInAudioFormat));
// if (result) { printf("AudioUnitSetProperty mixer result %ld %08lX %4.4s\n", (long)result, (long)result, (char*)&result); return; }
// result = AudioUnitSetProperty(mOutput, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &streamInAudioFormat, sizeof(streamInAudioFormat));
// if (result) { printf("AudioUnitSetProperty output result %ld %08lX %4.4s\n", (long)result, (long)result, (char*)&result); return; }
我的图表与 Apple 提供的示例应用程序非常相似。
我的 mixerNode 由自定义数据(而不是 guitar/beats)提供 - 但设置相似。两条总线在调音台上都是立体声的。
我正在尝试对内容进行时移,但到目前为止还没有成功。我尝试向图表中添加 kAudioUnitSubType_NewTimePitch,但无论何时添加图表都无法创建。有没有关于我如何使用混频器单元进行时移(移动所有总线)的源代码示例?
这是一些工作代码:
// Describe audio component
AudioComponentDescription output_desc;
bzero(&output_desc, sizeof(output_desc));
output_desc.componentType = kAudioUnitType_Output;
output_desc.componentSubType = self.componentSubType;
output_desc.componentFlags = 0;
output_desc.componentFlagsMask = 0;
output_desc.componentManufacturer = kAudioUnitManufacturer_Apple;
// multichannel mixer unit
AudioComponentDescription mixer_desc;
bzero(&mixer_desc, sizeof(mixer_desc));
mixer_desc.componentType = kAudioUnitType_Mixer;
mixer_desc.componentSubType = kAudioUnitSubType_MultiChannelMixer;
mixer_desc.componentFlags = 0;
mixer_desc.componentFlagsMask = 0;
mixer_desc.componentManufacturer = kAudioUnitManufacturer_Apple;
// Describe NewTimePitch component
AudioComponentDescription speed_desc;
bzero(&speed_desc, sizeof(speed_desc));
speed_desc.componentType = kAudioUnitType_FormatConverter;
speed_desc.componentSubType = kAudioUnitSubType_NewTimePitch;
speed_desc.componentFlags = 0;
speed_desc.componentFlagsMask = 0;
speed_desc.componentManufacturer = kAudioUnitManufacturer_Apple;
result = AUGraphAddNode(mGraph, &output_desc, &outputNode);
if (result) { printf("AUGraphNewNode 1 result %ld %4.4s\n", (long)result, (char*)&result); return; }
result = AUGraphAddNode(mGraph, &speed_desc, &timeNode );
if (result) { printf("AUGraphNewNode 2 result %ld %4.4s\n", (long)result, (char*)&result); return; }
result = AUGraphAddNode(mGraph, &mixer_desc, &mixerNode );
if (result) { printf("AUGraphNewNode 3 result %ld %4.4s\n", (long)result, (char*)&result); return; }
result = AUGraphConnectNodeInput(mGraph, mixerNode, 0, outputNode, 0);
if (result) { printf("AUGraphConnectNodeInput mixer-> time result %ld %4.4s\n", (long)result, (char*)&result); return; }
// open the graph AudioUnits are open but not initialized (no resource allocation occurs here)
result = AUGraphOpen(mGraph);
if (result) { printf("AUGraphOpen result %ld %08lX %4.4s\n", (long)result, (long)result, (char*)&result); return; }
result = AUGraphNodeInfo(mGraph, mixerNode, NULL, &mMixer);
if (result) { printf("AUGraphNodeInfo mixer result %ld %08lX %4.4s\n", (long)result, (long)result, (char*)&result); return; }
result = AUGraphNodeInfo(mGraph, timeNode, NULL, &mTime);
if (result) { printf("AUGraphNodeInfo time result %ld %08lX %4.4s\n", (long)result, (long)result, (char*)&result); return; }
result = AUGraphNodeInfo(mGraph, outputNode, NULL, &mOutput);
if (result) { printf("AUGraphNodeInfo output result %ld %08lX %4.4s\n", (long)result, (long)result, (char*)&result); return; }
UInt32 numbuses = 1;
result = AudioUnitSetProperty(mMixer, kAudioUnitProperty_ElementCount, kAudioUnitScope_Input, 0, &numbuses, sizeof(numbuses));
if (result) { printf("AudioUnitSetProperty bus result %ld %08lX %4.4s\n", (long)result, (long)result, (char*)&result); return; }
for (int i = 0; i < numbuses; ++i) {
// setup render callback struct
AURenderCallbackStruct rcbs;
rcbs.inputProc = &mixerInput;
rcbs.inputProcRefCon = (__bridge void *)(outputStream);
printf("set kAudioUnitProperty_SetRenderCallback for mixer input bus %d\n", i);
// Set a callback for the specified node's specified input
result = AUGraphSetNodeInputCallback(mGraph, mixerNode, i, &rcbs);
// equivalent to AudioUnitSetProperty(mMixer, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, i, &rcbs, sizeof(rcbs));
if (result) { printf("AUGraphSetNodeInputCallback result %ld %08lX %4.4s\n", (long)result, (long)result, (char*)&result); return; }
// set input stream format to what we want
printf("set mixer input kAudioUnitProperty_StreamFormat for bus %d\n", i);
result = AudioUnitSetProperty(mMixer, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, i, mAudioFormat.streamDescription, sizeof(AudioStreamBasicDescription));
if (result) { printf("AudioUnitSetProperty result %ld %08lX %4.4s\n", (long)result, (long)result, (char*)&result); return; }
}
result = AudioUnitSetProperty(mMixer, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &streamInAudioFormat, sizeof(streamInAudioFormat));
if (result) { printf("AudioUnitSetProperty mixer result %ld %08lX %4.4s\n", (long)result, (long)result, (char*)&result); return; }
result = AudioUnitSetProperty(mOutput, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &streamInAudioFormat, sizeof(streamInAudioFormat));
if (result) { printf("AudioUnitSetProperty output result %ld %08lX %4.4s\n", (long)result, (long)result, (char*)&result); return; }
CAShow(mGraph);
// now that we've set everything up we can initialize the graph, this will also validate the connections
result = AUGraphInitialize(mGraph);
if (result) { printf("AUGraphInitialize result %ld %08lX %4.4s\n", (long)result, (long)result, (char*)&result); return; }
此代码有效 - 我有一个混音器,我可以通过回调将数据泵入其中。你可以看到我创建了时间节点,但无论我将它插入到图中的哪个位置,它都会杀死它。我也无法设置流格式或其他任何内容。
理想情况下我想做这样的事情:
result = AUGraphConnectNodeInput(mGraph, mixerNode, 0, timeNode, 0);
result = AUGraphConnectNodeInput(mGraph, timeNode, 0, outputNode, 0);
但这不起作用。
这是该设置的输出:
AudioUnitGraph 0x385003: Member Nodes: node 1: 'auou' 'vpio' 'appl', instance 0x134f40b10 O node 2: 'aufc' 'nutp' 'appl', instance 0x134e733b0 O node 3: 'aumx' 'mcmx' 'appl', instance 0x134ea71d0 O Connections: node 3 bus 0 => node 2 bus 0 [ 2 ch, 44100 Hz, 'lpcm' (0x00000029) 32-bit little-endian float, deinterleaved] node 2 bus 0 => node 1 bus 0 [ 1 ch, 0 Hz, 'lpcm' (0x00000029) 32-bit little-endian float, deinterleaved] Input Callbacks: {0x100038ea0, 0x134f7f900} => node 3 bus 0 [2 ch, 44100 Hz] CurrentState: mLastUpdateError=0, eventsToProcess=F, isInitialized=F, isRunning=F 2016-01-07 23:21:32.230 R5ProTestbed[901:503908] 23:21:32.229 ERROR: [0x19ff25000] 2776: ConnectAudioUnit failed with error -10868 2016-01-07 23:21:32.230 R5ProTestbed[901:503908] 23:21:32.230 ERROR: [0x19ff25000] 1682: Initialize failed with error -10868
根据CAShow,您当前的图表是这样的: 混音器 -> TimePitch -> VoiceProcess (你的输出节点不在图中)
您无法将混音器输出额外连接到其他设备 在你的代码中,你有
result = AUGraphConnectNodeInput(mGraph, mixerNode, 0, timeNode, 0);
所以你不能同时添加
result = AUGraphConnectNodeInput(mGraph, mixerNode, 0, outputNode, 0);
以上两条线都会导致图表混乱,并且它不知道您希望混合器的输出去哪里。
同样,您将混音器输出连接到输出节点
result = AUGraphConnectNodeInput(mGraph, mixerNode, 0, outputNode, 0);
所以你不能同时将时间节点连接到输出节点
result = AUGraphConnectNodeInput(mGraph, timeNode, 0, outputNode, 0);
同时拥有这两个会混淆图形,因为输出节点有两个输入而且它只能有一个。 这就像你试图建立 "Y" 连接,而就连接而言,你无法做到这一点。
您可以将输出放在一个输入上,这样两行就会发生冲突。弄清楚你想要它在链中的什么位置,并将一个输出连接到一个输入。
然后将渲染回调设置为链中的第一个节点。
来自您的评论"I am trying to do mixer->newtimepitch->IO" 你需要制作三个节点,
- 将混音器输出连接到 Time Pitch
- 将 Time Pitch 连接到 RemoteIO
您需要 3 个节点。两次 AUGraphConnectNodeInput() 调用。 将渲染回调连接到混音器。像这样:
result = AUGraphConnectNodeInput(mGraph, mixerNode, 0, timeNode, 0);
result = AUGraphConnectNodeInput(mGraph, timeNode, 0, outputNode, 0);
和你一样。确保从您的代码中删除其他节点连接。我不知道您是删除了其他连接还是将它们留在原处并添加了更多连接。
如果不手动配置错误检查,默认音频格式可能不合适。您需要将混音器的输出格式设置为 time-pitch 单元的输入格式,并将您的输出节点(RemoteIO?)的输入格式设置为 time-pitch 单元的输出格式。在连接单元之前需要配置格式。
不要在时间间距单位上设置格式。获取时间间距单位的格式,并在时间间距连接的所有内容上设置这些格式。
hotpaw2 自己想通了就回答了。非常感谢。我在混音器和 IO 的输出上设置 StreamFormat,通过停止它,转换器能够运行。
// result = AudioUnitSetProperty(mMixer, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &streamInAudioFormat, sizeof(streamInAudioFormat));
// if (result) { printf("AudioUnitSetProperty mixer result %ld %08lX %4.4s\n", (long)result, (long)result, (char*)&result); return; }
// result = AudioUnitSetProperty(mOutput, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &streamInAudioFormat, sizeof(streamInAudioFormat));
// if (result) { printf("AudioUnitSetProperty output result %ld %08lX %4.4s\n", (long)result, (long)result, (char*)&result); return; }