Fix initial sync to LTC with small buffersizes
authorRobin Gareus <robin@gareus.org>
Wed, 26 Jul 2017 20:54:31 +0000 (22:54 +0200)
committerRobin Gareus <robin@gareus.org>
Wed, 26 Jul 2017 20:58:16 +0000 (22:58 +0200)
Ardour follow_slave() does nothing (not even seek) if the slave is not
locked.

The LTC-slave assumes it's locked if LTC is stable for 5 continuous
process-calls.

If the difference of Ardour's transport-position to the LTC-timecode
is large (> 2sec), the slave reset itself (assuming drift, seek don't vari-
speed).

A LTC-slave does reset does reset the locked counter.

Hence: If initially Ardour's transport differs > 2 sec and the buffersize
is small (many process-callbacks), the slave kept resetting itself
never informing Ardour that it locked to the external TC, and Ardour
never issued a seek.

libs/ardour/ardour/slave.h
libs/ardour/ltc_slave.cc

index cf8060d029efeb6dd98a4b810fe3b86be2da4425..80ff20857201d3560d0174aecbb44acf924688be 100644 (file)
@@ -364,7 +364,7 @@ public:
        bool detect_discontinuity(LTCFrameExt *, int, bool);
        bool detect_ltc_fps(int, bool);
        bool equal_ltc_frame_time(LTCFrame *a, LTCFrame *b);
-       void reset();
+       void reset (bool with_ts = true);
        void resync_xrun();
        void resync_latency();
        void parse_timecode_offset();
index 2501378017d9de198aefcc5032240207dc5c20f5..04af930f0ea2d32626f75e59733af14aa560b29a 100644 (file)
@@ -143,11 +143,13 @@ LTC_Slave::resync_latency()
 }
 
 void
-LTC_Slave::reset()
+LTC_Slave::reset (bool with_ts)
 {
        DEBUG_TRACE (DEBUG::LTC, "LTC reset()\n");
-       last_timestamp = 0;
-       current_delta = 0;
+       if (with_ts) {
+               last_timestamp = 0;
+               current_delta = 0;
+       }
        transport_direction = 0;
        ltc_speed = 0;
        engine_dll_initstate = 0;
@@ -466,7 +468,7 @@ LTC_Slave::speed_and_position (double& speed, framepos_t& pos)
                        DEBUG_TRACE (DEBUG::LTC, string_compose("engine skipped %1 frames. Feeding silence to LTC parser.\n", skip));
                        if (skip >= 8192) skip = 8192;
                        unsigned char sound[8192];
-                       memset(sound, 0, sizeof(char) * skip);
+                       memset(sound, 0x80, sizeof(char) * skip);
                        ltc_decoder_write(decoder, sound, nframes, now);
                } else if (skip != 0) {
                        /* this should never happen. it may if monotonic_cnt, now overflow on 64bit */
@@ -548,9 +550,8 @@ LTC_Slave::speed_and_position (double& speed, framepos_t& pos)
 
        if (((pos < 0) || (labs(current_delta) > 2 * session.frame_rate()))) {
                DEBUG_TRACE (DEBUG::LTC, string_compose ("LTC large drift: %1\n", current_delta));
-               reset();
+               reset(false);
                speed = 0;
-               pos = session.transport_frame();
                return true;
        }