Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper way to disconnect nodes in AudioKit

Tags:

audiokit

The app I'm developing requires dynamically adding/removing/rearranging components in the sound chain.

So far, I have mostly been using the .disconnectOutput() method on most components, then reconnecting everything. This works most of the time, but occasionally it seems that a node is connected at multiple points in the sound chain, and I also get crashes if the node is connected to AudioKit.output.

AudioKit provides a number of public methods such as .detach(), .disconnectInput(), .disconnect() and I'm not really clear on what is cleanest or safest way to modify the sound chain. What is the best way to do this?

Also, is there some way to keep track of which nodes are connected to which?

like image 746
c_booth Avatar asked Feb 18 '18 01:02

c_booth


1 Answers

Use the detach() method on an AKNode to remove it from the chain.

The disconnect() and disconnect(nodes: ) methods of AKNode are deprecated. Use AKNode.detach() and AudioKit.detach(nodes: ) instead.

I agree this terminology is very unclear and not explained in the existing documentation. I am still struggling with the lifecycle and runtime chain dynamics as I learn the API, so I can't convey best practices. In general, you don't want to break your object graph. I'm using AKMixer objects and then dynamically attaching child nodes using the .connect(input:bus:) and .disconnectInput(bus:) methods and internal tracking of the associated busses, but I am still running into crashes with this approach :(

Apple's parent AVAudioEngine documentation page provides a couple rules of thumb for dynamic chaining practices: https://developer.apple.com/documentation/avfoundation/avaudioengine

like image 62
Steve D. Avatar answered Oct 06 '22 18:10

Steve D.