From 1aad6805b3d7c56793fe9a6d820f8717f9783683 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 30 Sep 2024 23:36:06 +0200 Subject: [PATCH] Fix count-in/preroll recording offsets Notably `Route::process_output_buffers` uses ``` output_latency = speed * _output_latency; ``` here, speed already needs to be non-zero during count-in and pre-roll. --- libs/ardour/ardour/session.h | 2 +- libs/ardour/route.cc | 8 ++++---- libs/ardour/session_transport.cc | 5 ++++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index bfc029ff93..e06a579c98 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -811,7 +811,7 @@ public: double engine_speed() const { return _engine_speed; } double actual_speed() const; - double transport_speed() const; + double transport_speed (bool incl_preroll = false) const; /** @return true if the transport state (TFSM) is stopped */ bool transport_stopped() const; /** @return true if the transport state (TFSM) is stopped or stopping */ diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc index f5c1375362..b47cea9aa0 100644 --- a/libs/ardour/route.cc +++ b/libs/ardour/route.cc @@ -410,7 +410,7 @@ Route::process_output_buffers (BufferSet& bufs, _pannable->automation_run (start_sample, nframes); } - const int speed = (is_auditioner() ? 1 : _session.transport_speed ()); + const int speed = (is_auditioner() ? 1 : _session.transport_speed (true)); assert (speed == -1 || speed == 0 || speed == 1); const samplecnt_t output_latency = speed * _output_latency; @@ -4050,7 +4050,7 @@ Route::latency_preroll (pframes_t nframes, samplepos_t& start_sample, samplepos_ return nframes; } if (!_disk_reader) { - if (_session.transport_speed() < 0) { + if (_session.transport_speed (true) < 0) { start_sample += latency_preroll; end_sample += latency_preroll; } else { @@ -4060,12 +4060,12 @@ Route::latency_preroll (pframes_t nframes, samplepos_t& start_sample, samplepos_ return nframes; } - if (latency_preroll > playback_latency ()) { + if (latency_preroll >= playback_latency ()) { no_roll_unlocked (nframes, start_sample - latency_preroll, end_sample - latency_preroll, false); return 0; } - if (_session.transport_speed() < 0) { + if (_session.transport_speed (true) < 0) { start_sample += latency_preroll; end_sample += latency_preroll; } else { diff --git a/libs/ardour/session_transport.cc b/libs/ardour/session_transport.cc index c751e3258b..22fc3ee670 100644 --- a/libs/ardour/session_transport.cc +++ b/libs/ardour/session_transport.cc @@ -2142,11 +2142,14 @@ Session::transport_will_roll_forwards () const } double -Session::transport_speed() const +Session::transport_speed (bool incl_preroll) const { if (_transport_fsm->transport_speed() != _transport_fsm->transport_speed()) { // cerr << "\n\n!!TS " << _transport_fsm->transport_speed() << " TFSM::speed " << _transport_fsm->transport_speed() << " via " << _transport_fsm->current_state() << endl; } + if (incl_preroll) { + return _transport_fsm->transport_speed(); + } return _count_in_samples > 0 ? 0. : _transport_fsm->transport_speed(); }