gpt4 book ai didi

swift - 从实例化的 SCNScene 获取 SCNRenderer

转载 作者:搜寻专家 更新时间:2023-11-01 05:38:26 27 4
gpt4 key购买 nike

我想知道我应该如何从实例化的 SceneKit 场景中提取 SCNRenderer。我正在尝试获取位于 SCNRenderer 中的 AVAudioEngine,以便我可以将音频过滤器应用于我的节点。

这里是覆盖 didFinishLaunching 部分缩减为相关代码:

override func awakeFromNib() {
// create a new scene
let scene = SCNScene()
// create and add a camera to the scene
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
scene.rootNode.addChildNode(cameraNode)
// place the camera
cameraNode.position = SCNVector3(x: 0, y: 0, z: 15)
// set the scene to the view
self.gameView!.scene = scene
gameView.delegate = self
}

如果有人能给我指点,我将不胜感激,因为我能够在位置上运行声音,但现在我坚持使用 AVEngine 图来做类似的事情:

AVAudioInput > AVAudioUnitDistortion > AVAudioOutput 并开始做一些有趣的混音。

编辑:

这就是我对引擎的想法:

    distortion = AVAudioUnitDistortion()

let URL = NSURL(fileURLWithPath: dataPath+"/welcome.aiff")
if(NSFileManager.defaultManager().fileExistsAtPath(dataPath+"/welcome.aiff")){
let source = SCNAudioSource(URL: URL)!
source.volume = 30.0
source.reverbBlend = 50.0
source.rate = 0.9
let clip = SCNAudioPlayer(source: source)
engine = clip.audioNode!.engine
distortion.loadFactoryPreset(AVAudioUnitDistortionPreset.SpeechRadioTower)
engine.attachNode(distortion)
engine.connect(clip.audioNode!, to: distortion, format: nil)
engine.connect(self.distortion, to: engine.outputNode, format: nil)
return clip

但是我现在有一个关于失真 AVAudioUnitDistortion 实例的空指针异常。

我哪里错了?

最佳答案

audioEngineSCNSceneRenderer 协议(protocol)的属性,而不是 SCNRenderer 类的属性。 由于 SCNScene 符合 SCNSceneRendererscene.audioEngine 将起作用。

编辑:由于 SCNView 符合 SCNSceneRenderergameView.audioEngine 将工作。

关于swift - 从实例化的 SCNScene 获取 SCNRenderer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34017921/

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