gpt4 book ai didi

ios - 在Spotify iOS SDK中混合两个AUNode

转载 作者:行者123 更新时间:2023-12-03 01:44:17 26 4
gpt4 key购买 nike

我正在尝试使用动态处理器和一堆滤波器来压缩Spotify方法connectOutputBus中的特定频段,但是当我在kAudioUnitSubType_MultiChannelMixer中混合节点时,只会出现第一个添加节点的声音。

obs:我实际上在sourceNodeCopy上使用了过滤器,以删除将在souceNode上压缩的频率,但是为了简短起见,我省略了它们。

这是代码:

override func connectOutputBus(_ sourceOutputBusNumber: UInt32, ofNode  sourceNode: AUNode, toInputBus destinationInputBusNumber: UInt32, ofNode destinationNode: AUNode, in graph: AUGraph!) throws {

let sourceNodeCopy = sourceNode //original node without the harsh freq

//create a filter for the harsh frequencies
var filterDescription = AudioComponentDescription()
filterDescription.componentType = kAudioUnitType_Effect
filterDescription.componentSubType = kAudioUnitSubType_BandPassFilter
filterDescription.componentManufacturer = kAudioUnitManufacturer_Apple
filterDescription.componentFlags = 0
filterDescription.componentFlagsMask = 0

AUGraphAddNode(graph, &filterDescription, &filterNode!) // Add the filter node
AUGraphNodeInfo(graph, filterNode!, nil, &filterUnit!) // Get the Audio Unit from the node
AudioUnitInitialize(filterUnit!) // Initialize the audio unit
// Set filter params
AudioUnitSetParameter(filterUnit!, kBandpassParam_CenterFrequency, kAudioUnitScope_Global, 0, 10038, 0)

//create a processor to compress the frequency
var dynamicProcessorDescription = AudioComponentDescription()
dynamicProcessorDescription.componentType = kAudioUnitType_Effect
dynamicProcessorDescription.componentSubType = kAudioUnitSubType_DynamicsProcessor
dynamicProcessorDescription.componentManufacturer = kAudioUnitManufacturer_Apple
dynamicProcessorDescription.componentFlags = 0
dynamicProcessorDescription.componentFlagsMask = 0

// Add the dynamic processor node
AUGraphAddNode(graph, &dynamicProcessorDescription, &dynamicProcessorNode)
AUGraphNodeInfo(graph, dynamicProcessorNode, nil, &dynamicProcessorUnit)
AudioUnitInitialize(dynamicProcessorUnit!)

// Set compressor params
AudioUnitSetParameter(dynamicProcessorUnit!, kDynamicsProcessorParam_Threshold, kAudioUnitScope_Global, 0, -35, 0)
AudioUnitSetParameter(dynamicProcessorUnit!, kDynamicsProcessorParam_AttackTime, kAudioUnitScope_Global, 0, 0.02, 0)
AudioUnitSetParameter(dynamicProcessorUnit!, kDynamicsProcessorParam_ReleaseTime, kAudioUnitScope_Global, 0, 0.04, 0)
AudioUnitSetParameter(dynamicProcessorUnit!, kDynamicsProcessorParam_HeadRoom, kAudioUnitScope_Global, 0, 0, 0)

//mixer
var mixerDescription = AudioComponentDescription()
mixerDescription.componentType = kAudioUnitType_Mixer
mixerDescription.componentSubType = kAudioUnitSubType_MultiChannelMixer
mixerDescription.componentManufacturer = kAudioUnitManufacturer_Apple
mixerDescription.componentFlags = 0
mixerDescription.componentFlagsMask = 0

AUGraphAddNode(graph, &mixerDescription, &audioEffectsController.mixerNode)
AUGraphNodeInfo(graph, audioEffectsController.mixerNode, nil,
&audioEffectsController.mixerUnit)
AudioUnitInitialize(audioEffectsController.mixerUnit!)

AudioUnitSetParameter(mixerUnit!, kMultiChannelMixerParam_Volume, kAudioUnitScope_Input, 0, 1.0, 0);
AudioUnitSetParameter(mixerUnit!, kMultiChannelMixerParam_Volume, kAudioUnitScope_Output, 0, 1.0, 0);


//connect the nodes
AUGraphConnectNodeInput(graph, sourceNode, sourceOutputBusNumber, filterNode, 0)
AUGraphConnectNodeInput(graph, filterNode, sourceOutputBusNumber, dynamicProcessorNode, 0)

AUGraphConnectNodeInput(graph, sourceNodeCopy, sourceOutputBusNumber, mixerNode, 0)
AUGraphConnectNodeInput(graph, fiterNode, sourceOutputBusNumber, mixerNode, 0)

//connect the mixer to the output
AUGraphConnectNodeInput(graph, audioEffectsController.mixerNode, 0, destinationNode, destinationInputBusNumber)

最佳答案

在代码中,您像这样连接节点

AUGraphConnectNodeInput(graph, sourceNodeCopy, sourceOutputBusNumber, mixerNode, 0)
AUGraphConnectNodeInput(graph, fiterNode, sourceOutputBusNumber, mixerNode, 0)

如果这样做,则将 sourceNodeCopyfilterNode连接到 MixerNode的相同输入(0)。但是只能连接一个...

你应该试试这个
AUGraphConnectNodeInput(graph, sourceNodeCopy, sourceOutputBusNumber, mixerNode, 0)
AUGraphConnectNodeInput(graph, fiterNode, sourceOutputBusNumber, mixerNode, 1)

关于ios - 在Spotify iOS SDK中混合两个AUNode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44916020/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com