如何为双耳混合设置 AVAudio3DMixingRenderingAlgorithm

How to set an AVAudio3DMixingRenderingAlgorithm for binaural mixing

我正在制作一个 iOS 应用程序并尝试将声音混合到双耳混音中。 我有

var engine = AVAudioEngine()
var environmentMixer = AVAudioEnvironmentNode()

func initSound() {
    let player = AVAudioPlayerNode()
    let url = NSBundle.mainBundle().URLForResource("sound", withExtension: "wav")!
    let f = try! AVAudioFile(forReading: url)
    engine.attachNode(environmentMixer)
    let format =  AVAudioFormat(standardFormatWithSampleRate: engine.outputNode.outputFormatForBus(0).sampleRate, channels: 2)
    engine.connect(environmentMixer, to: engine.outputNode, format: format)

    engine.attachNode(player)
    engine.connect(player, to: environmentMixer, format: f.processingFormat)

    //
    // somewhere here I guess I should set the rendering algorithm...
    //

    player.scheduleFile(f, atTime: nil, completionHandler: {print("done")})

    player.position = AVAudio3DPoint (x: 0.5, y: 0.25, z: 0)

    engine.prepare()
    do {
        try engine.start()
        player.play()
    } catch {}
}

但是如何将 environmentMixer 设置为不同的渲染算法?

不是这个:

environmentMixer.renderingAlgorithm = AVAudio3DMixingRenderingAlgorithmHRTF

Xcode报错: "Use of unresolved identifier 'AVAudio3DMixingRenderingAlgorithmHRTF'"

但是什么是? (上面的代码片段确实播放声音并将其放置在立体声场中的某个位置......但可以清楚地听到它使用默认的 AVAudio3DMixingRenderingAlgorithmEqualPowerPanning)

我不确定该算法听起来应该是什么样的,但您可以这样设置:

environmentMixer.renderingAlgorithm = .HRTF