更新: 我正在更改我的代码以更简化的方式说明问题。我还有一个小错误,虽然没有阻止这个问题,但确实增加了一些混乱。
我在 iOS (kAudioUnitSubType_MultiChannelMixer) 中实例化一个多通道混音器 AU,我执行以下操作:
OSStatus status = noErr;
// Set component type:
AudioComponentDescription cd = {0};
cd.componentType = kAudioUnitType_Mixer;
cd.componentSubType = kAudioUnitSubType_MultiChannelMixer;
cd.componentManufacturer = kAudioUnitManufacturer_Apple;
// Alloc unit:
AudioComponent defaultOutput = AudioComponentFindNext(NULL, &cd);
AudioUnit mixer;
status = AudioComponentInstanceNew(defaultOutput, &mixer);
NSLog(@"AU init status: %li", status);
// You can try initializing the unit before or after the attempt to set its input bus count.
// It doesn't matter; it won't work either way.
AudioUnitInitialize(mixer);
// Get number of inputs
UInt32 busSize = sizeof(UInt32);
UInt32 busCount = 0;
status = AudioUnitGetProperty(mixer,
kAudioUnitProperty_ElementCount,
kAudioUnitScope_Input,
0,
&busCount,
&busSize);
NSLog(@"AU get input bus count | status: %li | count: %lu", status, busCount);
// Try setting number of inputs
busCount = 3;
status = AudioUnitSetProperty(mixer,
kAudioUnitProperty_ElementCount,
kAudioUnitScope_Input,
0,
&busCount,
busSize);
NSLog(@"AU set input status: %li", status);
// Get number of inputs
busCount = 0;
status = AudioUnitGetProperty(mixer,
kAudioUnitProperty_ElementCount,
kAudioUnitScope_Input,
0,
&busCount,
&busSize);
NSLog(@"AU get input bus count | status: %li | count: %lu", status, busCount);
// Try setting number of inputs
busCount = 10;
status = AudioUnitSetProperty(mixer,
kAudioUnitProperty_ElementCount,
kAudioUnitScope_Input,
0,
&busCount,
busSize);
NSLog(@"AU set input status: %li", status);
// Get number of inputs
busCount = 0;
status = AudioUnitGetProperty(mixer,
kAudioUnitProperty_ElementCount,
kAudioUnitScope_Input,
0,
&busCount,
&busSize);
NSLog(@"AU get input bus count | status: %li | count: %lu", status, busCount);
我得到以下输出:
2013-10-11 19:54:32.248 AUMultiChannelRadar[3996:a0b] AU init status: 0
2013-10-11 19:54:32.249 AUMultiChannelRadar[3996:a0b] AU get input bus count | status: 0 | count: 8
2013-10-11 19:54:32.250 AUMultiChannelRadar[3996:a0b] AU set input status: 0
2013-10-11 19:54:32.250 AUMultiChannelRadar[3996:a0b] AU get input bus count | status: 0 | count: 8
2013-10-11 19:54:32.250 AUMultiChannelRadar[3996:a0b] AU set input status: 0
2013-10-11 19:54:32.251 AUMultiChannelRadar[3996:a0b] AU get input bus count | status: 0 | count: 10
我希望总线数默认不是 8(因为音频单元文档没有说实例化有默认值),我希望能够将输入元素的数量更改为更少和超过 8 个(因为文档说它可以有“任何”数量的输入)。但是,从输出中,尝试将输入计数设置为小于 8 无济于事;我只能设置为8以上。