【问题标题】:Getting the SCNRenderer from an instantiated SCNScene从实例化的 SCNScene 获取 SCNRenderer
【发布时间】:2015-12-07 22:41:43
【问题描述】:

我想知道我应该如何从实例化的 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 实例上有一个空指针异常。

我哪里错了?

【问题讨论】:

    标签: swift scenekit


    【解决方案1】:

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

    编辑: 由于SCNView 符合SCNSceneRenderer,所以gameView.audioEngine 将起作用。

    【讨论】:

    • 好的,但是我实例化的场景没有audioEngine。
    • 那是SCNViewview.audioEngine,而不是scene
    猜你喜欢
    • 2017-03-18
    • 2018-10-05
    • 1970-01-01
    • 2017-03-29
    • 2015-02-11
    • 1970-01-01
    • 1970-01-01
    • 2021-05-17
    • 1970-01-01
    相关资源
    最近更新 更多