问题
UPDATE: I'm changing my code to illustrate the issue in a more streamlined way. Also I had a little bug which, while not deterring from the problem, did add some confusion.
I'm instantiating a Multi Channel Mixer AU in iOS (kAudioUnitSubType_MultiChannelMixer) and I do the following:
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);
And I get the following output:
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
I'd expect the bus count to not be 8 by default (since the Audio Unit documentation doesn't say there is a default value on instantiation) and I'd expect to be able to change the number of input elements to both less and more than 8 for that matter (since the docs say it can have "Any" number of inputs). However, from the output, attempting to set the input count to less than 8 does nothing; I can only set it to more than 8.
回答1:
I talked to an Apple engineer who is part of the CoreAudio team and showed him my code and he agreed it is most certainly a bug. He even tried it out himself and got the same results as me: the unit seems to be instantiated with 8 inputs by default and you can only set the number to more than 8 but not less (yes, my code originally showed 2 inputs cause I was messing up and dividing 8/4 -- thanks).
He told me to file a radar so I did. # 15214291.
回答2:
I think there is no need to divide the number of elements on UInt32 size.
UInt32 numElements = 0;
UInt32 size = sizeof(numElements);
AudioUnitGetProperty(_audioUnit, kAudioUnitProperty_ElementCount, kAudioUnitScope_Input, 0, &numElements, &size);
So, numElements
will contain number of elements.
来源:https://stackoverflow.com/questions/19213990/why-cant-i-change-the-number-of-elements-buses-in-the-input-scope-of-au-multi