From 8aa4ae825dc99a8112deb9d27664504a04330b94 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 27 Apr 2020 07:25:32 +0200 Subject: [PATCH] Skip delayline updates if no change is required --- libs/ardour/ardour/route.h | 2 +- libs/ardour/ardour/session.h | 2 +- libs/ardour/route.cc | 11 ++++++++++- libs/ardour/session.cc | 14 ++++++++------ 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/libs/ardour/ardour/route.h b/libs/ardour/ardour/route.h index c9bd8492d7..788d669e55 100644 --- a/libs/ardour/ardour/route.h +++ b/libs/ardour/ardour/route.h @@ -346,7 +346,7 @@ public: */ bool remove_sidechain (boost::shared_ptr proc) { return add_remove_sidechain (proc, false); } - samplecnt_t update_signal_latency (bool apply_to_delayline = false); + samplecnt_t update_signal_latency (bool apply_to_delayline = false, bool* delayline_update_needed = NULL); virtual void apply_latency_compensation (); samplecnt_t set_private_port_latencies (bool playback) const; diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index ac50c07a29..b9ced0bd85 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -1342,7 +1342,7 @@ private: void remove_monitor_section (); void update_latency (bool playback); - bool update_route_latency (bool reverse, bool apply_to_delayline); + bool update_route_latency (bool reverse, bool apply_to_delayline, bool* delayline_update_needed); void initialize_latencies (); void set_worst_output_latency (); void set_worst_input_latency (); diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc index 6d1dfab77d..8def7e4b5c 100644 --- a/libs/ardour/route.cc +++ b/libs/ardour/route.cc @@ -4221,7 +4221,7 @@ Route::add_export_point() } samplecnt_t -Route::update_signal_latency (bool apply_to_delayline) +Route::update_signal_latency (bool apply_to_delayline, bool* delayline_update_needed) { if (!active()) { _signal_latency = 0; @@ -4303,6 +4303,15 @@ Route::update_signal_latency (bool apply_to_delayline) if (apply_to_delayline) { /* see also Session::post_playback_latency() */ apply_latency_compensation (); + } else if (delayline_update_needed && _delayline) { + samplecnt_t play_lat_in = _input->connected_latency (true); + samplecnt_t latcomp = play_lat_in - play_lat_out - _signal_latency; + if (latcomp < 0) { + latcomp = 0; + } + if (_delayline->delay () != latcomp) { + *delayline_update_needed = true; + } } _output_latency = _output->latency (); diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 4750f5f853..d0bb24407f 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -6473,7 +6473,7 @@ Session::send_latency_compensation_change () } bool -Session::update_route_latency (bool playback, bool apply_to_delayline) +Session::update_route_latency (bool playback, bool apply_to_delayline, bool* delayline_update_needed) { /* apply_to_delayline can no be called concurrently with processing * caller must hold process lock when apply_to_delayline == true */ @@ -6502,7 +6502,7 @@ restart: for (RouteList::iterator i = r->begin(); i != r->end(); ++i) { // if (!(*i)->active()) { continue ; } // TODO samplecnt_t l; - if ((*i)->signal_latency () != (l = (*i)->update_signal_latency (apply_to_delayline))) { + if ((*i)->signal_latency () != (l = (*i)->update_signal_latency (apply_to_delayline, delayline_update_needed))) { changed = true; } _worst_route_latency = std::max (l, _worst_route_latency); @@ -6603,7 +6603,7 @@ Session::update_latency (bool playback) /* prevent any concurrent latency updates */ Glib::Threads::Mutex::Lock lx (_update_latency_lock); set_worst_output_latency (); - update_route_latency (true, /*apply_to_delayline*/ true); + update_route_latency (true, /*apply_to_delayline*/ true, NULL); /* relese before emiting signals */ lm.release (); @@ -6613,7 +6613,7 @@ Session::update_latency (bool playback) lm.release (); Glib::Threads::Mutex::Lock lx (_update_latency_lock); set_worst_input_latency (); - update_route_latency (false, false); + update_route_latency (false, false, NULL); } DEBUG_TRACE (DEBUG::LatencyCompensation, "Engine latency callback: DONE\n"); @@ -6691,7 +6691,8 @@ Session::update_latency_compensation (bool force_whole_graph, bool called_from_b DEBUG_TRACE (DEBUG::LatencyCompensation, string_compose ("update_latency_compensation%1.\n", (force_whole_graph ? " of whole graph" : ""))); - bool some_track_latency_changed = update_route_latency (false, false); + bool delayline_update_needed = false; + bool some_track_latency_changed = update_route_latency (false, false, &delayline_update_needed); if (some_track_latency_changed || force_whole_graph) { @@ -6724,8 +6725,9 @@ Session::update_latency_compensation (bool force_whole_graph, bool called_from_b } else { DEBUG_TRACE (DEBUG::LatencyCompensation, "update_latency_compensation called from engine, don't call back into engine\n"); } - } else { + } else if (delayline_update_needed) { DEBUG_TRACE (DEBUG::LatencyCompensation, "update_latency_compensation: directly apply to routes\n"); + lx.release (); // XXX cannot hold this lock when acquiring process_lock ?! #ifndef MIXBUS Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK); #endif