如何让定位音频在 SceneKit 中工作?

How do you get positional audio to work in SceneKit?

我在让定位音频在 SceneKit 中工作时遇到问题。从 Xcode 生成的 SceneKit 游戏模板开始,我在 handleTap 方法的末尾添加了以下代码:

let ship = scnView.scene!.rootNode.childNode(withName: "ship", recursively: true)!  
if let source = SCNAudioSource(fileNamed: "art.scnassets/monoAudioTest.wav")  
{  
    source.volume = 1  
    source.isPositional = true  
    source.shouldStream = true  
    source.loops = true  
    source.load()  
    let player = SCNAudioPlayer(source: source)  
    ship.addAudioPlayer(player)  
}  

ship.runAction(SCNAction.move(to: SCNVector3(0, 0, -10000), duration: 8)) 

音频会播放,但音量不会随着喷气机远离相机而降低。我是不是遗漏了一些步骤或做了一些错误的假设?

交叉发布到 Apple Developer Forums

您应该能够通过 source.shouldStream = false 获得定位音频。

正如 Jed Soane 所提到的,并由 Apple 在 Radar 中确认,问题是我的音频文件是立体声而不是单声道。只有单声道音频文件适用于定位音频。