AK3DPanner and AVAudioEnvironmentNode

216 views
Skip to first unread message

Gustaf Kugelberg

unread,
Sep 21, 2016, 12:52:05 PM9/21/16
to AudioKit Users Group
Hello, thanks for an awesome audio engine!

I've been playing around with 3d audio for a project where this is central, and since the AK3DPanner only takes one input node (?) this is my setup:

-n sources, each connected to its own panner
-All the n panners feed into a common AKMixer, that is the output of the engine

This works, but looking at the WWDC 2014 video "502 - AVAudioEngine in practice" they seem to be using another setup. At 42:22 for example, they have:

-2 nodes feeding into an environment node
-the environment node then feeds into the main mixer

Since AK3DPanner is backed by an AVAudioEnvironmentNode, it seems like the same setups should be used. One drawback of using multiple AVAudioEnvironmentNodes, apart from potential inefficiency, is that I have to modify the listener position in each of them if I want to move the listener.

Could someone clarify this for me?

Many thanks,

Gustaf

Aurelius Prochazka Ph.D.

unread,
Sep 21, 2016, 1:21:23 PM9/21/16
to AudioKit Users Group
I think you are right, the 3D Panner isn't really set up to do more than one placement.   You could probably tweak the api to allow for a truer representation of what is capable using the environment node.  That or just write a new AKNode wrapping the functionality of the envinronment node and submit it back to the community through a pull request.  

Aure

Gustaf Kugelberg

unread,
Sep 21, 2016, 4:33:47 PM9/21/16
to AudioKit Users Group
I looked a bit closer at it and it actually does a hack, it has x, y and z-properties but they don't move the source, they move the listener, only they move him to (-x, -y, -z)!

I would definitely wrap it myself if I could figure out how to connect the avaudionodes. It's because I don't know how that part works that I'm using audiokit...

But I'll try, it's still simpler than using AVAudio straight.

Gustaf Kugelberg

unread,
Sep 21, 2016, 4:34:00 PM9/21/16
to AudioKit Users Group

It seems I figured it out. This seems to work:

        let a = AKOscillator()

        a.frequency = 440

        

        let b = AKOscillator()

        b.frequency = 660

        

        (a.avAudioNode as! AVAudioMixing).position = AVAudio3DPoint(x: 2, y: 1, z: 1)

        (b.avAudioNode as! AVAudioMixing).position = AVAudio3DPoint(x: -2, y: 1, z: 1)


        let panner = AK3DPanner(a)

        b.addConnectionPoint(panner)


        AudioKit.output = panner

        AudioKit.start()

        a.start()

        b.start()


I'm assuming that the addNode method on the new AK3DPanner should look more like:

        input.connectionPoints.append(AVAudioConnectionPoint(node: environmentNode, bus: environmentNode.numberOfInputs))

        

        let format = AVAudioFormat(standardFormatWithSampleRate: AKSettings.sampleRate, channels: 1)

        

        AudioKit.engine.connect(input.avAudioNode, toConnectionPoints: input.connectionPoints, fromBus: 0, format: format)


As soon as XCode 8 finishes downloading I'll make a pull request!

Aurelius Prochazka Ph.D.

unread,
Sep 21, 2016, 4:55:57 PM9/21/16
to AudioKit Users Group
Looks good Gustaf.  Really I had no good use case for the 3D stuff so my tests were pretty much limited to a basic playground.  It's great when someone who is actually using the features makes the updates to the toolkit!  

Aure
Reply all
Reply to author
Forward
0 new messages