ComponentResult karoke::Initialize() { // get the current numChannels for input and output. // a host may test various combinations of these // regardless of the outInfo returned by our SupportedNumChannels method SInt16 auNumInputs = (SInt16) GetInput(0)->GetStreamFormat().mChannelsPerFrame; SInt16 auNumOutputs = (SInt16) GetOutput(0)->GetStreamFormat().mChannelsPerFrame; if ((auNumInputs == NUM_INPUTS) && (auNumOutputs == NUM_OUTPUTS)) { MaintainKernels(); return noErr; } else return kAudioUnitErr_FormatNotSupported; }
//_____________________________________________________________________________ // OSStatus AUEffectBase::Initialize() { // get our current numChannels for input and output SInt16 auNumInputs = (SInt16) GetInput(0)->GetStreamFormat().mChannelsPerFrame; SInt16 auNumOutputs = (SInt16) GetOutput(0)->GetStreamFormat().mChannelsPerFrame; // does the unit publish specific information about channel configurations? const AUChannelInfo *auChannelConfigs = NULL; UInt32 numIOconfigs = SupportedNumChannels(&auChannelConfigs); if ((numIOconfigs > 0) && (auChannelConfigs != NULL)) { bool foundMatch = false; for (UInt32 i = 0; (i < numIOconfigs) && !foundMatch; ++i) { SInt16 configNumInputs = auChannelConfigs[i].inChannels; SInt16 configNumOutputs = auChannelConfigs[i].outChannels; if ((configNumInputs < 0) && (configNumOutputs < 0)) { // unit accepts any number of channels on input and output if (((configNumInputs == -1) && (configNumOutputs == -2)) || ((configNumInputs == -2) && (configNumOutputs == -1))) { foundMatch = true; // unit accepts any number of channels on input and output IFF they are the same number on both scopes } else if (((configNumInputs == -1) && (configNumOutputs == -1)) && (auNumInputs == auNumOutputs)) { foundMatch = true; // unit has specified a particular number of channels on both scopes } else continue; } else { // the -1 case on either scope is saying that the unit doesn't care about the // number of channels on that scope bool inputMatch = (auNumInputs == configNumInputs) || (configNumInputs == -1); bool outputMatch = (auNumOutputs == configNumOutputs) || (configNumOutputs == -1); if (inputMatch && outputMatch) foundMatch = true; } } if (!foundMatch) return kAudioUnitErr_FormatNotSupported; } else { // there is no specifically published channel info // so for those kinds of effects, the assumption is that the channels (whatever their number) // should match on both scopes if ((auNumOutputs != auNumInputs) || (auNumOutputs == 0)) { return kAudioUnitErr_FormatNotSupported; } } MaintainKernels(); mMainOutput = GetOutput(0); mMainInput = GetInput(0); const CAStreamBasicDescription& format = GetStreamFormat(kAudioUnitScope_Output, 0); format.IdentifyCommonPCMFormat(mCommonPCMFormat, NULL); mBytesPerFrame = format.mBytesPerFrame; return noErr; }