tracktion_engine icon indicating copy to clipboard operation
tracktion_engine copied to clipboard

[FR]: Optimise LatencyNode -> SummingNode

Open drowaudio opened this issue 1 year ago • 2 comments

If you have a track with a single latency introducing plugin on it, all other tracks will need to be latency balanced (see image). image Most of these LatencyNodes will be introducing the same latency so could be replaced with a single SummingNode feeding a single LatencyNode.

drowaudio avatar Apr 15 '24 15:04 drowaudio

Idea for a general rule:

If a summing node is receiving data from N different latency nodes whose latencies are {L_1, ..., L_N} respectively, we could subtract m = min(L_1, ..., L_N) from all their latencies (allowing us to throw away all the ones whose latency value becomes 0) then insert a new one, with a value of m, right after the summing node. This works in this specific case (if all the latency values are the same, well, we got rid of all the latency nodes) but still allows us to squeeze out some memory/CPU in cases where the latencies aren't the same.

AquaEBM avatar May 03 '25 20:05 AquaEBM

That only works for cases where only LatencyNodes output to a SummingNode. In the above, The TrackMutingNode and SendNode would end up with the wrong latency.

I think you'd want to do several passes ideally:

  1. Consolidate multiple LatencyNodes feeding a SummingNode in to a new SummingNode with only LatencyNodes
  2. Find the minimum latency of these now there are only LatencyNodes. Add that difference as a new LatencyNode after the SummingNode, deleting any matching LatencyNodes or subtracting the greater LatencyNodes latency

In practice I think this is going to be hard to do and I'm a bit worried about continuity if there are too many ways LatencyNodes could get reconfigured.

drowaudio avatar May 07 '25 16:05 drowaudio