将 AUConverter 添加到 AUGraph 时出现错误 -10877
我正在使用 Apple 的 MixerHost 示例项目,该项目设置了一个音频单元处理图,其中包含连接到远程 I/O 音频单元的多通道混音器音频单元。我试图在两者之间放置一个格式转换器音频单元,以便我可以转换混音器输出的格式。
复制两个现有音频单元的设置似乎很简单,当我输出图形设置时,它看起来是正确的:
Member Nodes:
node 1: 'auou' 'rioc' 'appl', instance 0x1cdf10 O
node 2: 'aufc' 'conv' 'appl', instance 0x1ce890 O
node 3: 'aumx' 'mcmx' 'appl', instance 0x1ceba0 O
Connections:
node 3 bus 0 => node 2 bus 1
node 2 bus 0 => node 1 bus 0 [ 2 ch, 0 Hz, 'lpcm' (0x0000000C) 16-bit little-endian signed integer]
但是,当我初始化图形时,我收到错误 -10877,无效元素,并且图形无法启动。谁能看出出了什么问题吗?这是完整的设置代码:
NSLog (@"Configuring and then initializing audio processing graph");
OSStatus result = noErr;
//............................................................................
// Create a new audio processing graph.
result = NewAUGraph (&processingGraph);
if (noErr != result) {[self printErrorMessage: @"NewAUGraph" withStatus: result]; return;}
//............................................................................
// Specify the audio unit component descriptions for the audio units to be
// added to the graph.
// I/O unit
AudioComponentDescription ioUnitDescription;
ioUnitDescription.componentType = kAudioUnitType_Output;
ioUnitDescription.componentSubType = kAudioUnitSubType_RemoteIO;
ioUnitDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
ioUnitDescription.componentFlags = 0;
ioUnitDescription.componentFlagsMask = 0;
// Converter unit
AudioComponentDescription ConverterUnitDescription;
ConverterUnitDescription.componentType = kAudioUnitType_FormatConverter;
ConverterUnitDescription.componentSubType = kAudioUnitSubType_AUConverter;
ConverterUnitDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
ConverterUnitDescription.componentFlags = 0;
ConverterUnitDescription.componentFlagsMask = 0;
// Multichannel mixer unit
AudioComponentDescription MixerUnitDescription;
MixerUnitDescription.componentType = kAudioUnitType_Mixer;
MixerUnitDescription.componentSubType = kAudioUnitSubType_MultiChannelMixer;
MixerUnitDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
MixerUnitDescription.componentFlags = 0;
MixerUnitDescription.componentFlagsMask = 0;
//............................................................................
// Add nodes to the audio processing graph.
NSLog (@"Adding nodes to audio processing graph");
AUNode mixerNode; // node for Multichannel Mixer unit
AUNode converterNode; // node for AU Converter unit
AUNode ioNode; // node for I/O unit
// Add the nodes to the audio processing graph
result = AUGraphAddNode (
processingGraph,
&ioUnitDescription,
&ioNode);
if (noErr != result) {[self printErrorMessage: @"AUGraphNewNode failed for I/O unit" withStatus: result]; return;}
result = AUGraphAddNode (
processingGraph,
&ConverterUnitDescription,
&converterNode
);
if (noErr != result) {[self printErrorMessage: @"AUGraphNewNode failed for Converter unit" withStatus: result]; return;}
result = AUGraphAddNode (
processingGraph,
&MixerUnitDescription,
&mixerNode
);
if (noErr != result) {[self printErrorMessage: @"AUGraphNewNode failed for Mixer unit" withStatus: result]; return;}
//............................................................................
// Open the audio processing graph
// Following this call, the audio units are instantiated but not initialized
// (no resource allocation occurs and the audio units are not in a state to
// process audio).
result = AUGraphOpen (processingGraph);
if (noErr != result) {[self printErrorMessage: @"AUGraphOpen" withStatus: result]; return;}
//............................................................................
// Obtain the audio unit instances from their corresponding nodes.
AudioUnit mixerUnit;
AudioUnit converterUnit;
AudioUnit ioUnit;
result = AUGraphNodeInfo (
processingGraph,
ioNode,
NULL,
&ioUnit
);
if (noErr != result) {[self printErrorMessage: @"AUGraphNodeInfo" withStatus: result]; return;}
result = AUGraphNodeInfo (
processingGraph,
converterNode,
NULL,
&converterUnit
);
if (noErr != result) {[self printErrorMessage: @"AUGraphNodeInfo" withStatus: result]; return;}
result = AUGraphNodeInfo (
processingGraph,
mixerNode,
NULL,
&mixerUnit
);
if (noErr != result) {[self printErrorMessage: @"AUGraphNodeInfo" withStatus: result]; return;}
//............................................................................
// Audio Unit Setup
// Set the mixer unit's output sample rate format. This is the only aspect of the output stream
// format that must be explicitly set.
NSLog (@"Setting sample rate for mixer unit output scope");
result = AudioUnitSetProperty (
mixerUnit,
kAudioUnitProperty_SampleRate,
kAudioUnitScope_Output,
0,
&graphSampleRate,
sizeof (graphSampleRate)
);
if (noErr != result) {[self printErrorMessage: @"AudioUnitSetProperty (set mixer unit output stream format)" withStatus: result]; return;}
//............................................................................
// Connect the nodes of the audio processing graph
NSLog (@"Connecting the mixer output to the input of the converter unit input element");
result = AUGraphConnectNodeInput (
processingGraph,
mixerNode, // source node
0, // source node output bus number
converterNode, // destination node
1 // destination node input bus number
);
if (noErr != result) {[self printErrorMessage: @"AUGraphConnectNodeInput" withStatus: result]; return;}
NSLog (@"Connecting the converter output to the input of the I/O unit output element");
result = AUGraphConnectNodeInput (
processingGraph,
converterNode, // source node
0, // source node output bus number
ioNode, // destination node
0 // destination node input bus number
);
if (noErr != result) {[self printErrorMessage: @"AUGraphConnectNodeInput" withStatus: result]; return;}
//............................................................................
// Initialize audio processing graph
// Diagnostic code
// Call CAShow if you want to look at the state of the audio processing
// graph.
NSLog (@"Audio processing graph state immediately before initializing it:");
CAShow (processingGraph);
NSLog (@"Initializing the audio processing graph");
// Initialize the audio processing graph, configure audio data stream formats for
// each input and output, and validate the connections between audio units.
result = AUGraphInitialize (processingGraph);
if (noErr != result) {[self printErrorMessage: @"AUGraphInitialize" withStatus: result]; return;}
I'm working with Apple's MixerHost sample project, which sets up an audio unit processing graph consisting of a multichannel mixer audio unit connected to a remote I/O audio unit. I'm trying to put a format converter audio unit between the two so I can convert the format of the mixer's output.
Copying the setup of the two existing audio units seems straightforward, and when I output the graph setup it looks right:
Member Nodes:
node 1: 'auou' 'rioc' 'appl', instance 0x1cdf10 O
node 2: 'aufc' 'conv' 'appl', instance 0x1ce890 O
node 3: 'aumx' 'mcmx' 'appl', instance 0x1ceba0 O
Connections:
node 3 bus 0 => node 2 bus 1
node 2 bus 0 => node 1 bus 0 [ 2 ch, 0 Hz, 'lpcm' (0x0000000C) 16-bit little-endian signed integer]
However, when I initialize the graph, I get error -10877, Invalid Element, and the graph doesn't start up. Can anyone see what's wrong? Here's the complete setup code:
NSLog (@"Configuring and then initializing audio processing graph");
OSStatus result = noErr;
//............................................................................
// Create a new audio processing graph.
result = NewAUGraph (&processingGraph);
if (noErr != result) {[self printErrorMessage: @"NewAUGraph" withStatus: result]; return;}
//............................................................................
// Specify the audio unit component descriptions for the audio units to be
// added to the graph.
// I/O unit
AudioComponentDescription ioUnitDescription;
ioUnitDescription.componentType = kAudioUnitType_Output;
ioUnitDescription.componentSubType = kAudioUnitSubType_RemoteIO;
ioUnitDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
ioUnitDescription.componentFlags = 0;
ioUnitDescription.componentFlagsMask = 0;
// Converter unit
AudioComponentDescription ConverterUnitDescription;
ConverterUnitDescription.componentType = kAudioUnitType_FormatConverter;
ConverterUnitDescription.componentSubType = kAudioUnitSubType_AUConverter;
ConverterUnitDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
ConverterUnitDescription.componentFlags = 0;
ConverterUnitDescription.componentFlagsMask = 0;
// Multichannel mixer unit
AudioComponentDescription MixerUnitDescription;
MixerUnitDescription.componentType = kAudioUnitType_Mixer;
MixerUnitDescription.componentSubType = kAudioUnitSubType_MultiChannelMixer;
MixerUnitDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
MixerUnitDescription.componentFlags = 0;
MixerUnitDescription.componentFlagsMask = 0;
//............................................................................
// Add nodes to the audio processing graph.
NSLog (@"Adding nodes to audio processing graph");
AUNode mixerNode; // node for Multichannel Mixer unit
AUNode converterNode; // node for AU Converter unit
AUNode ioNode; // node for I/O unit
// Add the nodes to the audio processing graph
result = AUGraphAddNode (
processingGraph,
&ioUnitDescription,
&ioNode);
if (noErr != result) {[self printErrorMessage: @"AUGraphNewNode failed for I/O unit" withStatus: result]; return;}
result = AUGraphAddNode (
processingGraph,
&ConverterUnitDescription,
&converterNode
);
if (noErr != result) {[self printErrorMessage: @"AUGraphNewNode failed for Converter unit" withStatus: result]; return;}
result = AUGraphAddNode (
processingGraph,
&MixerUnitDescription,
&mixerNode
);
if (noErr != result) {[self printErrorMessage: @"AUGraphNewNode failed for Mixer unit" withStatus: result]; return;}
//............................................................................
// Open the audio processing graph
// Following this call, the audio units are instantiated but not initialized
// (no resource allocation occurs and the audio units are not in a state to
// process audio).
result = AUGraphOpen (processingGraph);
if (noErr != result) {[self printErrorMessage: @"AUGraphOpen" withStatus: result]; return;}
//............................................................................
// Obtain the audio unit instances from their corresponding nodes.
AudioUnit mixerUnit;
AudioUnit converterUnit;
AudioUnit ioUnit;
result = AUGraphNodeInfo (
processingGraph,
ioNode,
NULL,
&ioUnit
);
if (noErr != result) {[self printErrorMessage: @"AUGraphNodeInfo" withStatus: result]; return;}
result = AUGraphNodeInfo (
processingGraph,
converterNode,
NULL,
&converterUnit
);
if (noErr != result) {[self printErrorMessage: @"AUGraphNodeInfo" withStatus: result]; return;}
result = AUGraphNodeInfo (
processingGraph,
mixerNode,
NULL,
&mixerUnit
);
if (noErr != result) {[self printErrorMessage: @"AUGraphNodeInfo" withStatus: result]; return;}
//............................................................................
// Audio Unit Setup
// Set the mixer unit's output sample rate format. This is the only aspect of the output stream
// format that must be explicitly set.
NSLog (@"Setting sample rate for mixer unit output scope");
result = AudioUnitSetProperty (
mixerUnit,
kAudioUnitProperty_SampleRate,
kAudioUnitScope_Output,
0,
&graphSampleRate,
sizeof (graphSampleRate)
);
if (noErr != result) {[self printErrorMessage: @"AudioUnitSetProperty (set mixer unit output stream format)" withStatus: result]; return;}
//............................................................................
// Connect the nodes of the audio processing graph
NSLog (@"Connecting the mixer output to the input of the converter unit input element");
result = AUGraphConnectNodeInput (
processingGraph,
mixerNode, // source node
0, // source node output bus number
converterNode, // destination node
1 // destination node input bus number
);
if (noErr != result) {[self printErrorMessage: @"AUGraphConnectNodeInput" withStatus: result]; return;}
NSLog (@"Connecting the converter output to the input of the I/O unit output element");
result = AUGraphConnectNodeInput (
processingGraph,
converterNode, // source node
0, // source node output bus number
ioNode, // destination node
0 // destination node input bus number
);
if (noErr != result) {[self printErrorMessage: @"AUGraphConnectNodeInput" withStatus: result]; return;}
//............................................................................
// Initialize audio processing graph
// Diagnostic code
// Call CAShow if you want to look at the state of the audio processing
// graph.
NSLog (@"Audio processing graph state immediately before initializing it:");
CAShow (processingGraph);
NSLog (@"Initializing the audio processing graph");
// Initialize the audio processing graph, configure audio data stream formats for
// each input and output, and validate the connections between audio units.
result = AUGraphInitialize (processingGraph);
if (noErr != result) {[self printErrorMessage: @"AUGraphInitialize" withStatus: result]; return;}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚找到了答案!问题是:
流格式未定义,因此出现了问题。
我还没有在 AUConverter 设备上对此进行测试,但对于 iPodEQ 设备,您只使用一个元素。然后,将混音器输出连接到输出总线的输入范围,即
HTH。 :)
I just found an answer! Here's the problem:
The stream format isn't defined, so something is wrong.
I haven't tested this on the AUConverter unit, but with the iPodEQ unit you use only one element. Then, you connect the mixer output to the input scope of the output bus, i.e.
HTH. :)