Reputation: 56
I'm implementing a polyphonic synth in Web Audio, with dynamic voice allocation.
Performance-wise, is it better to modify the graph (add oscillator node, filter node, etc.) for the new voice each time a key is pressed, or pre-create the entire graph for the maximum polyphony desired, and then just change gains / envelopes for pressed keys?
i.e. - what has a bigger performance impact: Changing the graph dynamically all the time, or leaving (mostly unused) nodes running all the time?
Upvotes: 2
Views: 209
Reputation: 3070
Unless latency is a problem, I cannot see any advantage to creating a fixed number of patch-graphs up front.
Ideally, your synth would have a Polyphony Level setting that could be set to dynamic (with each graph initialized on demand) or fixed to a given number of graphs (all preinitialized). It would be dynamic by default, with the option of fixing the level only provided as a fallback for when latency becomes an issue.
Upvotes: 0
Reputation: 6048
I think the only way to know for sure is to try it both ways and see.
But if your synth has, say, 50 oscillators at most and you create them all up front, you'll have 50 oscillators always running, even if you only need a couple most of the time. This could also cause all downstream nodes to be needlessly processing as well.
But if you really need to 50 oscillators (with effects chain) to work, then your machine needs to be powerful enough to support this, so I think either approach will work. Your average power consumption will probably be higher if you create all the nodes up front instead of creating just the needed number of nodes.
Upvotes: 1