From bc1be2fc24ca99b9ee6ff1a8eaba3eb7e4623e9d Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 4 Mar 2022 01:37:12 +0100 Subject: [PATCH] Fix stem export alignment When a track's output is not connected, but the track feeds other tracks via sends (common case in Mixbus) the stem export of the track was not correctly aligned. The track is correctly latency compensated (due to sends), but the unconnected port's latency is not set. However stem-export uses the private latency of the port as alignment. --- libs/ardour/route.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc index 7c716dbb78..7eeb4322d5 100644 --- a/libs/ardour/route.cc +++ b/libs/ardour/route.cc @@ -4939,6 +4939,7 @@ Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, samplec */ LatencyRange all_connections; + bool connected = false; if (from.empty()) { all_connections.min = 0; @@ -4963,6 +4964,7 @@ Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, samplec all_connections.min = min (all_connections.min, range.min); all_connections.max = max (all_connections.max, range.max); + connected = true; } if (all_connections.min == ~((pframes_t) 0)) { @@ -4970,10 +4972,23 @@ Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, samplec } } + /* if the output is not connected, its latency is not relevant, + * however stem-export uses the private latency of the port as alignment. + * see PortExportChannel::common_port_playback_latency() + * and PortExportChannel::prepare_export() + * + * So for correct alignment we use the Delivery's playback latency. + */ + LatencyRange outport_latency = all_connections; + if (playback && _main_outs && !connected) { + outport_latency.min = _main_outs->playback_offset () - _main_outs->input_latency (); + outport_latency.max = _main_outs->playback_offset () - _main_outs->input_latency (); + } + /* set the "from" port latencies to the max/min range of all their connections */ for (PortSet::iterator p = from.begin(); p != from.end(); ++p) { - p->set_private_latency_range (all_connections, playback); + p->set_private_latency_range (outport_latency, playback); } DEBUG_TRACE (DEBUG::LatencyRoute, string_compose ("%1: priv. port L(%2) = (%3, %4) + %5\n", _name, playback ? "playback" : "capture", all_connections.min, all_connections.max, our_latency));