Posts

Post not yet marked as solved
1 Replies
781 Views
I have a graph of AVAudioNodePlayers connected to an AVAudioMixerNode. This works fine when I use my own AVAudioEngine instance.I'm trying to adapt this code to instead use SceneKit positional audio. So in place of my own AVAudioEngine instance, I'm using the one provided by the SCNView.audioEngine. Then I attach my mixer node to a SceneKit node: let audioMixerNode: AVAudioMixerNode = ... let player = SCNAudioPlayer(avAudioNode: audioMixerNode) sceneKitNode.addAudioPlayer(player)If I run it here, I hear no audio, presumably because I have not told my AVAudioPlayerNodes to play(), which is reasonable. If I do tell them to play, however, I get an exception: "player started when in a disconnected state". (All of this code is running after calling SCNView.play(_:) in viewDidAppear(_:), by the way.)From the exception I assume that I need to connect my audioMixerNode to the SCNView's audio engine's graph. So I connect it and then play: scnView.audioEngine.connect(audioMixerNode, to: scnView.audioEngine.mainMixerNode, format: nil) avPlayerNodes.forEach { $0.play() }Now I hear audio, but the volume does not change with the position of the listener, which makes me suspect that I have unwittingly circumvented whatever makes positional audio levels work. I've scoured the example code but none of it seems to use AVAudioNode-based audio sources, or if it does, it updates the audio levels manually based on the position of the SceneKit node. What am I missing?
Posted
by imtzo.
Last updated
.