2

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.

SaldaVonSchwartz
  • 3,769
  • 2
  • 41
  • 78
  • Have you already invoked AUGraphConnectNodeInput for the nodes you intend to hook up to the Mixer? Separately, an element/bus is not the same as a channel. Each input element can have 1 channel (mono) or 2 (stereo). Apple's Audio Unit Hosting Guide talks about the Mixer unit's behavior with channels and how you need to set ASBD depending on how each input node is configured. AudioGraph is based on MixerHost and has some nice comments for why things are done as they are: https://github.com/tkzic/audiograph – William Power Oct 11 '13 at 01:49
  • AUGraph shouldn't have anything to do with this. This is about setting up properties of an AU, regardless of using it in a graph or not (which I'm not btw). See my answer. – SaldaVonSchwartz Oct 12 '13 at 03:20

2 Answers2

2

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.

SaldaVonSchwartz
  • 3,769
  • 2
  • 41
  • 78
1

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.

  • I tried that too, but still it looks confusing. For instance, without dividing, the kAudioUnitScope_Input of a generic output unit is 1, for a Remote I/O is 2 (which makes sense if compared to the usual diagram for an AU that shows 2 elements 0,1 but makes no sense if following the documentation which says: "one input element (1), one output element (0)) and a MultiChannel Mixer has 8 by default and can't go down from 8 (which also makes no sense since in theory it can have "any" number of inputs). – SaldaVonSchwartz Oct 08 '13 at 01:03
  • https://developer.apple.com/library/ios/documentation/MusicAudio/Conceptual/AudioUnitHostingGuide_iOS/AudioUnitHostingFundamentals/AudioUnitHostingFundamentals.html You'll see under **Use Properties to Configure Audio Units** it mentions `kAudioUnitProperty_ElementCount` for configuring ins/outs. Also, you'll notice a **Using Specific Audio Units** section that implies the multichannel mixer can have "any" number of in elements and last, https://developer.apple.com/library/ios/samplecode/MixerHost/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010210, where they set the ins in a multi mixer – SaldaVonSchwartz Oct 09 '13 at 01:22