我在将混音器单元插入AUGraph时遇到问题,否则在Mac OS和iOS上都能正常工作.
我的工作图看起来像这样:
(My Audio render callback) <- [Format converter] <- [DefaultOutput]
另外,我能够成功插入这样的EQ单元:
(My Audio render callback) <- [Format converter] <- [GraphicEQ] <- [DefaultOutput]
我的目标是插入一个混音器单元,但没有EQ,所以我可以独立于iOS上的系统音量控制我的音量.但是,当我设置图表时,它看起来似乎没问题,但我得到的只是沉默.
这是图表的样子:
(My Audio render callback) <- [Format converter] <- [MultiChannelMixer] <- [DefaultOutput]
……以及CAShow的输出:
AudioUnitGraph 0x397000: Member Nodes: node 1: 'auou' 'def ' 'appl',instance 0x8039704d O I node 2: 'aumx' 'mcmx' 'appl',instance 0x8039704e O I node 3: 'aufc' 'conv' 'appl',instance 0x8039704f O I Connections: node 3 bus 0 => node 2 bus 0 [ 2 ch,44100 Hz,'lpcm' (0x00000029) 32-bit little-endian float,deinterleaved] node 2 bus 0 => node 1 bus 0 [ 2 ch,deinterleaved] Input Callbacks: {0x100035d90,0x10037cd60} => node 3 bus 0 [2 ch,44100 Hz] CurrentState: mLastUpdateError=0,eventsToProcess=F,isRunning=T (1)
// A description of the output device we're looking for. AudioComponentDescription outputDescription; outputDescription.componentType = kAudioUnitType_Output; outputDescription.componentSubType = kAudioUnitSubType_DefaultOutput; outputDescription.componentManufacturer = kAudioUnitManufacturer_Apple; outputDescription.componentFlags = 0; outputDescription.componentFlagsMask = 0; // A description of the mixer unit AudioComponentDescription mixerDescription; mixerDescription.componentType = kAudioUnitType_Mixer; mixerDescription.componentSubType = kAudioUnitSubType_MultiChannelMixer; mixerDescription.componentManufacturer = kAudioUnitManufacturer_Apple; mixerDescription.componentFlags = 0; mixerDescription.componentFlagsMask = 0; // A description for the libspotify -> standard PCM device AudioComponentDescription converterDescription; converterDescription.componentType = kAudioUnitType_FormatConverter; converterDescription.componentSubType = kAudioUnitSubType_AUConverter; converterDescription.componentManufacturer = kAudioUnitManufacturer_Apple; converterDescription.componentFlags = 0; converterDescription.componentFlagsMask = 0; // Create an AUGraph OSErr status = NewAUGraph(&audioProcessingGraph); // Open the graph. AudioUnits are open but not initialized (no resource allocation occurs here) AUGraphOpen(audioProcessingGraph); // Add audio output... status = AUGraphAddNode(audioProcessingGraph,&outputDescription,&outputNode); // Add mixer status = AUGraphAddNode(audioProcessingGraph,&mixerDescription,&mixerNode); // Get mixer unit so we can change volume etc status = AUGraphNodeInfo(audioProcessingGraph,mixerNode,NULL,&mixerUnit); // Set mixer bus count UInt32 busCount = 1; status = AudioUnitSetProperty(mixerUnit,kAudioUnitProperty_ElementCount,kAudioUnitScope_Input,&busCount,sizeof(busCount)); // Create PCM converter status = AUGraphAddNode(audioProcessingGraph,&converterDescription,&inputConverterNode); // Connect converter to mixer status = AUGraphConnectNodeInput(audioProcessingGraph,inputConverterNode,0); // Connect mixer to output status = AUGraphConnectNodeInput(audioProcessingGraph,outputNode,0); // Set render callback AURenderCallbackStruct rcbs; rcbs.inputProc = AudioUnitRenderDelegateCallback; rcbs.inputProcRefCon = (__bridge void *)(self); status = AUGraphSetNodeInputCallback(audioProcessingGraph,&rcbs); // Init Queue status = AUGraphInitialize(audioProcessingGraph); AUGraphUpdate(audioProcessingGraph,NULL); AUGraphStart(audioProcessingGraph);
解决方法
…当然,在这里发表我的问题之后,我偶然发现了答案.
看来,至少在Mac OS上,调音台上的输入音量默认为0.0.手动设置输入音量会立即修正:
status = AudioUnitSetParameter(mixerUnit,kMultiChannelMixerParam_Volume,1.0,0);