按频道而不是按输入更改音频音量需要矩阵混音器。avaudioEngine主混频器不是矩阵混频器(mxmx),而是多通道混频器(mcmx)。
要使用矩阵混频器,请使用以下代码:
AudioComponentDescription mixerUnitDescription;
mixerUnitDescription.componentType = kAudioUnitType_Mixer;
mixerUnitDescription.componentSubType = kAudioUnitSubType_MatrixMixer;
mixerUnitDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
mixerUnitDescription.componentFlags = 0;
mixerUnitDescription.componentFlagsMask = 0;
[AVAudioUnit instantiateWithComponentDescription:mixerUnitDescription options:0 completionHandler:^(__kindof AVAudioUnit * _Nullable mixer, NSError * _Nullable error) {
};
并使用更改音频级别
AudioUnitSetParameter([_mixer audioUnit], kMatrixMixerParam_Volume, kAudioUnitScope_Input, i, volume, 0);