summaryrefslogtreecommitdiff
path: root/libs/ardour/session_transport.cc
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2017-09-28 06:31:12 +0200
committerRobin Gareus <robin@gareus.org>2017-09-29 05:03:48 +0200
commit8139becb1898187729b0ea57f145302d4975bf3a (patch)
tree79638d87c587765784fe56eeb530ff792442e0c5 /libs/ardour/session_transport.cc
parent8ff3b5ecf6bd2b7d69b8f154ba8d21eb4fe86304 (diff)
Ongoing work on latency compensation
The general goal is to align transport-sample to be the audible frame and use that as "anchor" for all processing. transport_sample cannot become negative (00:00:00:00 is the first audible frame). Internally transport pre-rolls (read-ahead) before the transport starts to move. This allows inputs and disk to prefill the pipeline. When starting to roll, the session counts down a global "remaning preroll" counter, which is the worst-latency from in-to-out. Each route in turn will start processing at its own output-latency. Route::process_output_buffers() - which does the actual processing incl disk i/o - begins by offsetting the "current sample" by the route's process-latency and decrements the offset for each latent processor. At the end of the function the output will be aligned and match transport-sample - downstream-playback-latency (if any). PS. This commit is a first step only: transport looping & vari-speed have not yet been implemented/updated.
Diffstat (limited to 'libs/ardour/session_transport.cc')
-rw-r--r--libs/ardour/session_transport.cc34
1 files changed, 27 insertions, 7 deletions
diff --git a/libs/ardour/session_transport.cc b/libs/ardour/session_transport.cc
index bb89ff57d4..07782750e3 100644
--- a/libs/ardour/session_transport.cc
+++ b/libs/ardour/session_transport.cc
@@ -1171,6 +1171,12 @@ Session::start_locate (samplepos_t target_sample, bool with_roll, bool with_flus
}
}
+samplecnt_t
+Session::worst_latency_preroll () const
+{
+ return _worst_output_latency + _worst_input_latency;
+}
+
int
Session::micro_locate (samplecnt_t distance)
{
@@ -1250,15 +1256,16 @@ Session::locate (samplepos_t target_sample, bool with_roll, bool with_flush, boo
// thread(s?) can restart.
g_atomic_int_inc (&_seek_counter);
_last_roll_or_reversal_location = target_sample;
- timecode_time(_transport_sample, transmitting_timecode_time);
+ _remaining_latency_preroll = worst_latency_preroll ();
+ timecode_time(_transport_sample, transmitting_timecode_time); // XXX here?
/* do "stopped" stuff if:
*
* we are rolling AND
- * no autoplay in effect AND
- * we're not going to keep rolling after the locate AND
- * !(playing a loop with JACK sync)
- *
+ * no autoplay in effect AND
+ * we're not going to keep rolling after the locate AND
+ * !(playing a loop with JACK sync)
+ *
*/
bool transport_was_stopped = !transport_rolling();
@@ -1492,6 +1499,9 @@ Session::set_transport_speed (double speed, samplepos_t destination_sample, bool
/* not zero, not 1.0 ... varispeed */
+ // TODO handled transport start.. _remaining_latency_preroll
+ // and reversal of playback direction.
+
if ((synced_to_engine()) && speed != 0.0 && speed != 1.0) {
warning << string_compose (
_("Global varispeed cannot be supported while %1 is connected to JACK transport control"),
@@ -1659,6 +1669,7 @@ Session::start_transport ()
_last_roll_location = _transport_sample;
_last_roll_or_reversal_location = _transport_sample;
+ _remaining_latency_preroll = worst_latency_preroll ();
have_looped = false;
@@ -1728,13 +1739,22 @@ Session::start_transport ()
_count_in_samples *= 1. + bar_fract;
}
+ if (_count_in_samples > _remaining_latency_preroll) {
+ _remaining_latency_preroll = _count_in_samples;
+ }
+
int clickbeat = 0;
samplepos_t cf = _transport_sample - _count_in_samples;
- while (cf < _transport_sample) {
- add_click (cf - _worst_track_latency, clickbeat == 0);
+ samplecnt_t offset = _click_io->connected_latency (true);
+ while (cf < _transport_sample + offset) {
+ add_click (cf, clickbeat == 0);
cf += dt;
clickbeat = fmod (clickbeat + 1, num);
}
+
+ if (_count_in_samples < _remaining_latency_preroll) {
+ _count_in_samples = _remaining_latency_preroll;
+ }
}
}