在过去的几天里,我一直在努力寻找一种动态改变(在播放过程中)“平移”的方法。通过HLS流传输的视频中的立体声音频流的值。我想要的最终结果是能够在视频播放期间将右声道或左声道静音。我觉得这很简单。
我尝试了几个选项,这些选项都没有给我带来任何乐趣,并且非常感谢任何可能解决我问题的指针。我将概述我的尝试 - 希望有人能够提供帮助。
尝试第一次
我尝试过使用Apple的MTAudioProcessingTap
。我读过各种各样的评论,认为在HLS上使用它是不可能的 - 但是认为值得一试。以下是我的代码示例:
if let playerItem = player?.currentItem, let audioTrack = getAudioTrack(playerItem: playerItem) {
let inputParams = AVMutableAudioMixInputParameters(track: audioTrack)
let callbacks = MTAudioProcessingTapCallbacks(version: kMTAudioProcessingTapCallbacksVersion_0,
clientInfo: UnsafeMutableRawPointer(Unmanaged.passUnretained(self).toOpaque()),
init: tapInit,
finalize: tapFinalize,
prepare: tapPrepare,
unprepare: tapUnprepare,
process: tapProcess)
let err = MTAudioProcessingTapCreate(kCFAllocatorDefault, &callbacks!, kMTAudioProcessingTapCreationFlag_PostEffects, &tap)
assert(tap != nil)
inputParams.audioTapProcessor = tap!.takeunRetainedValue()
let audioMix = AVMutableAudioMix()
audioMix.inputParameters = [inputParams]
playerItem.audioMix = audioMix
}
我注意到tapInit回调确实被调用,但是在tapFinalize之前没有调用其他回调。在本地加载文件时,所有回调都会如我所料,包括进程回调。因此,我没有尝试实际改变平移值。
尝试第二次 我试图使用CoreAudio API。尽管按照我的预期设置了所有内容,但在通过HLS或本地加载内容时,我从未发现对音频输出有任何影响。这是我的设置:
var processingGraph: AUGraph? = nil
var status = OSStatus(noErr)
var mixerUnit: AudioUnit? = nil
var outputUnit: AudioUnit? = nil
status = NewAUGraph(&processingGraph)
var mixerNode = AUNode()
var mixerUnitDescription = AudioComponentDescription(
componentType: OSType(kAudioUnitType_Mixer),
componentSubType: OSType(kAudioUnitSubType_MultiChannelMixer),
componentManufacturer: OSType(kAudioUnitManufacturer_Apple),
componentFlags: 0,
componentFlagsMask: 0)
var outputNode = AUNode()
var outputUnitDescription = AudioComponentDescription(
componentType: OSType(kAudioUnitType_Output),
componentSubType: OSType(kAudioUnitSubType_RemoteIO),
componentManufacturer: OSType(kAudioUnitManufacturer_Apple),
componentFlags: 0,
componentFlagsMask: 0)
status = AUGraphAddNode(processingGraph!, &outputUnitDescription, &outputNode)
status = AUGraphAddNode(processingGraph!, &mixerUnitDescription, &mixerNode)
let outputElement = AudioUnitElement(0)
let mixerElement = AudioUnitElement(0)
status = AUGraphConnectNodeInput(processingGraph!, mixerNode, mixerElement, outputNode, outputElement)
status = AUGraphNodeInfo(processingGraph!, mixerNode, nil, &mixerUnit)
status = AUGraphNodeInfo(processingGraph!, outputNode, nil, &outputUnit)
status = AUGraphOpen(processingGraph!)
var outIsInited: DarwinBoolean = false
status = AUGraphIsInitialized(processingGraph!, &outIsInited)
if outIsInited == false {
print("Need to init graph")
status = AUGraphInitialize(processingGraph!)
}
var isRunning: DarwinBoolean = false
status = AUGraphIsRunning(processingGraph!, &isRunning)
if isRunning == false {
print("Need to start graph")
status = AUGraphStart(processingGraph!)
}
然后我设置pan值:
status = AudioUnitSetParameter(mixerUnit!, kMultiChannelMixerParam_Pan, kAudioUnitScope_Input, 0, panValue, 0)
我不知道我是否错过了上述设置的步骤,因为即使在本地文件上也没有发生任何变化,这让我感到困惑。
尝试第三次 这真的没有走得太远,但我遇到了Superpowered SDK,我注意到它包含一个名为SuperpoweredStereoMixer的类,这表明它应该可以控制泛:
单独的输入通道电平(适用于增益和声像),单独的输出通道电平(主增益和声像)
但是,文档很少,我正在努力开始并且仍然担心这个库可能无法解决调整泛化值超过HLS的问题。