|
|
|
|
@@ -44,25 +44,21 @@ using namespace Timecode;
|
|
|
|
|
LTC_Slave::LTC_Slave (Session& s)
|
|
|
|
|
: session (s)
|
|
|
|
|
{
|
|
|
|
|
frames_per_ltc_frame = session.frames_per_timecode_frame(); // XXX at most 30fps ?
|
|
|
|
|
frames_per_ltc_frame = session.frames_per_timecode_frame();
|
|
|
|
|
timecode.rate = session.timecode_frames_per_second();
|
|
|
|
|
timecode.drop = session.timecode_drop_frames();
|
|
|
|
|
|
|
|
|
|
ltc_transport_pos = 0;
|
|
|
|
|
did_reset_tc_format = false;
|
|
|
|
|
delayedlocked = 10;
|
|
|
|
|
engine_dll_initstate = 0;
|
|
|
|
|
monotonic_cnt = 0;
|
|
|
|
|
|
|
|
|
|
memset(&prev_ltc_frame, 0, sizeof(LTCFrame));
|
|
|
|
|
|
|
|
|
|
ltc_timecode = timecode_60; // track changes of LTC timecode
|
|
|
|
|
a3e_timecode = timecode_60; // track canges of Ardour's timecode
|
|
|
|
|
printed_timecode_warning = false;
|
|
|
|
|
ltc_detect_fps_cnt = ltc_detect_fps_max = 0;
|
|
|
|
|
|
|
|
|
|
decoder = ltc_decoder_create((int) frames_per_ltc_frame, 128 /*queue size*/);
|
|
|
|
|
reset();
|
|
|
|
|
//session.engine().Xrun.connect_same_thread (*this, boost::bind (<C_Slave::reset, this));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LTC_Slave::~LTC_Slave()
|
|
|
|
|
@@ -74,13 +70,6 @@ LTC_Slave::~LTC_Slave()
|
|
|
|
|
ltc_decoder_free(decoder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
LTC_Slave::give_slave_full_control_over_transport_speed() const
|
|
|
|
|
{
|
|
|
|
|
return true; // DLL align to engine transport
|
|
|
|
|
// return false; // for Session-level computed varispeed
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ARDOUR::framecnt_t
|
|
|
|
|
LTC_Slave::resolution () const
|
|
|
|
|
{
|
|
|
|
|
@@ -109,28 +98,31 @@ void
|
|
|
|
|
LTC_Slave::reset()
|
|
|
|
|
{
|
|
|
|
|
DEBUG_TRACE (DEBUG::LTC, "LTC reset()\n");
|
|
|
|
|
frames_in_sequence = 0;
|
|
|
|
|
ltc_detect_fps_cnt = ltc_detect_fps_max = 0;
|
|
|
|
|
last_timestamp = 0;
|
|
|
|
|
current_delta = 0;
|
|
|
|
|
transport_direction = 0;
|
|
|
|
|
ltc_speed = 0;
|
|
|
|
|
ltc_decoder_queue_flush(decoder);
|
|
|
|
|
engine_dll_initstate = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
void
|
|
|
|
|
LTC_Slave::parse_ltc(const jack_nframes_t nframes, const jack_default_audio_sample_t * const in, const framecnt_t posinfo)
|
|
|
|
|
{
|
|
|
|
|
jack_nframes_t i;
|
|
|
|
|
unsigned char sound[8192];
|
|
|
|
|
if (nframes > 8192) return 1;
|
|
|
|
|
if (nframes > 8192) {
|
|
|
|
|
/* TODO warn once or wrap, loop conversion below
|
|
|
|
|
* does A3 support > 8192 spp anyway?
|
|
|
|
|
*/
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nframes; i++) {
|
|
|
|
|
const int snd=(int)rint((127.0*in[i])+128.0);
|
|
|
|
|
sound[i] = (unsigned char) (snd&0xff);
|
|
|
|
|
}
|
|
|
|
|
ltc_decoder_write(decoder, sound, nframes, posinfo);
|
|
|
|
|
return 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
@@ -142,6 +134,7 @@ LTC_Slave::detect_ltc_fps(int frameno, bool df)
|
|
|
|
|
ltc_detect_fps_max = frameno;
|
|
|
|
|
}
|
|
|
|
|
ltc_detect_fps_cnt++;
|
|
|
|
|
|
|
|
|
|
if (ltc_detect_fps_cnt > 60)
|
|
|
|
|
{
|
|
|
|
|
if (ltc_detect_fps_cnt > ltc_detect_fps_max
|
|
|
|
|
@@ -187,8 +180,8 @@ LTC_Slave::detect_ltc_fps(int frameno, bool df)
|
|
|
|
|
Timecode::timecode_format_name(cur_timecode),
|
|
|
|
|
Timecode::timecode_format_name(tc_format))
|
|
|
|
|
<< endmsg;
|
|
|
|
|
session.config.set_timecode_format (tc_format);
|
|
|
|
|
}
|
|
|
|
|
session.config.set_timecode_format (tc_format);
|
|
|
|
|
} else {
|
|
|
|
|
/* only warn about TC mismatch */
|
|
|
|
|
if (ltc_timecode != tc_format) printed_timecode_warning = false;
|
|
|
|
|
@@ -208,53 +201,21 @@ LTC_Slave::detect_ltc_fps(int frameno, bool df)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
LTC_Slave::detect_ltc_discontinuity(LTCFrameExt *frame) {
|
|
|
|
|
bool discontinuity_detected = false;
|
|
|
|
|
/* detect discontinuities */
|
|
|
|
|
if (frame->reverse) {
|
|
|
|
|
ltc_frame_decrement(&prev_ltc_frame, ceil(timecode.rate), 0);
|
|
|
|
|
} else {
|
|
|
|
|
ltc_frame_increment(&prev_ltc_frame, ceil(timecode.rate), 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (memcmp(&prev_ltc_frame, &frame->ltc, sizeof(LTCFrame))) {
|
|
|
|
|
discontinuity_detected = true;
|
|
|
|
|
}
|
|
|
|
|
memcpy(&prev_ltc_frame, &frame->ltc, sizeof(LTCFrame));
|
|
|
|
|
|
|
|
|
|
/* notfify about discontinuities */
|
|
|
|
|
if (frames_in_sequence > 0 && discontinuity_detected) {
|
|
|
|
|
DEBUG_TRACE (DEBUG::LTC, "# LTC DISCONTINUITY\n");
|
|
|
|
|
frames_in_sequence=0;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
frames_in_sequence++;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
LTC_Slave::process_ltc(framepos_t const now, framepos_t const sess_pos, framecnt_t const nframes)
|
|
|
|
|
void
|
|
|
|
|
LTC_Slave::process_ltc(framepos_t const now)
|
|
|
|
|
{
|
|
|
|
|
bool have_frame = false;
|
|
|
|
|
DEBUG_TRACE (DEBUG::LTC, string_compose ("LTC Process eng-tme: %1 eng-pos: %2\n", now, sess_pos));
|
|
|
|
|
|
|
|
|
|
LTCFrameExt frame;
|
|
|
|
|
while (ltc_decoder_read(decoder,&frame)) {
|
|
|
|
|
bool reinitialize_ltc_dll = false;
|
|
|
|
|
while (ltc_decoder_read(decoder, &frame)) {
|
|
|
|
|
SMPTETimecode stime;
|
|
|
|
|
|
|
|
|
|
ltc_frame_to_time(&stime, &frame.ltc, 0);
|
|
|
|
|
timecode.negative = false;
|
|
|
|
|
timecode.subframes = 0;
|
|
|
|
|
|
|
|
|
|
/* set timecode.rate and timecode.drop: */
|
|
|
|
|
if (detect_ltc_fps(stime.frame, (frame.ltc.dfbit)? true : false)) {
|
|
|
|
|
reset();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (detect_ltc_discontinuity(&frame)) {
|
|
|
|
|
ltc_discontinuity = true;
|
|
|
|
|
last_timestamp = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if 0 // Devel/Debug
|
|
|
|
|
@@ -268,20 +229,8 @@ LTC_Slave::process_ltc(framepos_t const now, framepos_t const sess_pos, framecnt
|
|
|
|
|
frame.off_end,
|
|
|
|
|
frame.reverse ? " R" : " "
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (frames_in_sequence < 1) {
|
|
|
|
|
fprintf(stdout, " ####### FIRST LTC FRAME in SEQ #######\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ltc_discontinuity) {
|
|
|
|
|
fprintf(stdout, " ####### LTC DISCONTINUITY #######\n");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (frames_in_sequence < 1) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* when a full LTC frame is decoded, the timecode the LTC frame
|
|
|
|
|
* is referring has just passed.
|
|
|
|
|
* So we send the _next_ timecode which
|
|
|
|
|
@@ -291,11 +240,13 @@ LTC_Slave::process_ltc(framepos_t const now, framepos_t const sess_pos, framecnt
|
|
|
|
|
if (!frame.reverse) {
|
|
|
|
|
ltc_frame_increment(&frame.ltc, fps_i , 0);
|
|
|
|
|
ltc_frame_to_time(&stime, &frame.ltc, 0);
|
|
|
|
|
transport_direction = 1;
|
|
|
|
|
} else {
|
|
|
|
|
ltc_frame_decrement(&frame.ltc, fps_i , 0);
|
|
|
|
|
int off = frame.off_end - frame.off_start;
|
|
|
|
|
frame.off_start += off;
|
|
|
|
|
frame.off_end += off;
|
|
|
|
|
transport_direction = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
timecode.hours = stime.hours;
|
|
|
|
|
@@ -311,210 +262,172 @@ LTC_Slave::process_ltc(framepos_t const now, framepos_t const sess_pos, framecnt
|
|
|
|
|
session.config.get_timecode_offset_negative(), session.config.get_timecode_offset()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/* (frame.off_end + 1) = start of next LTC frame */
|
|
|
|
|
double poff = (frame.off_end + 1 - now);
|
|
|
|
|
ltc_transport_pos = ltc_frame - poff;
|
|
|
|
|
|
|
|
|
|
#if 0 // vari-speed LTC, no DLL
|
|
|
|
|
frames_per_ltc_frame = 1 + frame.off_end - frame.off_start;
|
|
|
|
|
#else
|
|
|
|
|
frames_per_ltc_frame = (double(session.frame_rate()) / timecode.rate);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
DEBUG_TRACE (DEBUG::LTC, string_compose ("LTC frame: %1 poff: %2 pos: %3\n", ltc_frame, poff, ltc_transport_pos));
|
|
|
|
|
|
|
|
|
|
if (ltc_discontinuity) {
|
|
|
|
|
ltc_discontinuity=false;
|
|
|
|
|
if (ltc_speed==0
|
|
|
|
|
|| !locked()
|
|
|
|
|
|| (ltc_transport_pos - sess_pos) > FLYWHEEL_TIMEOUT)
|
|
|
|
|
{
|
|
|
|
|
engine_dll_initstate = 0;
|
|
|
|
|
reset();
|
|
|
|
|
}
|
|
|
|
|
reinitialize_ltc_dll = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (last_timestamp == 0
|
|
|
|
|
|| ((now - last_timestamp) > FLYWHEEL_TIMEOUT)
|
|
|
|
|
|| (abs(ltc_transport_pos - sess_pos) > frames_per_ltc_frame)
|
|
|
|
|
|| (frame.reverse && transport_direction != -1)
|
|
|
|
|
|| (!frame.reverse && transport_direction != 1)
|
|
|
|
|
) {
|
|
|
|
|
reinitialize_ltc_dll = true;
|
|
|
|
|
engine_dll_initstate = 0;
|
|
|
|
|
reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reinitialize_ltc_dll) {
|
|
|
|
|
init_ltc_dll(ltc_transport_pos, frames_per_ltc_frame);
|
|
|
|
|
|
|
|
|
|
if (ltc_speed==0 || !locked()) {
|
|
|
|
|
if (frame.reverse) {
|
|
|
|
|
transport_direction = -1;
|
|
|
|
|
ltc_transport_pos -= nframes * rint((2 * frames_per_ltc_frame + poff)/nframes);
|
|
|
|
|
} else {
|
|
|
|
|
transport_direction = 1;
|
|
|
|
|
ltc_transport_pos += nframes * rint((2 * frames_per_ltc_frame + poff)/nframes);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
framepos_t cur_timestamp = frame.off_end + 1;
|
|
|
|
|
DEBUG_TRACE (DEBUG::LTC, string_compose ("LTC F: %1 LF: %2 N: %3 L: %4\n", ltc_frame, last_ltc_frame, cur_timestamp, last_timestamp));
|
|
|
|
|
if (frame.off_end + 1 <= last_timestamp || last_timestamp == 0) {
|
|
|
|
|
DEBUG_TRACE (DEBUG::LTC, string_compose ("LTC speed: UNCHANGED: %1\n", ltc_speed));
|
|
|
|
|
} else {
|
|
|
|
|
// update DLL
|
|
|
|
|
double e = (double(ltc_frame) - poff - double(sess_pos));
|
|
|
|
|
t0 = t1;
|
|
|
|
|
t1 += b * e + e2;
|
|
|
|
|
e2 += c * e;
|
|
|
|
|
|
|
|
|
|
ltc_speed = (t1 - t0) / frames_per_ltc_frame;
|
|
|
|
|
//current_delta = (ltc_transport_pos - sess_pos);
|
|
|
|
|
DEBUG_TRACE (DEBUG::LTC, string_compose ("LTC DLL t0:%1 t1:%2 err:%3 spd:%4 ddt:%5\n", t0, t1, e, ltc_speed, e2 - frames_per_ltc_frame));
|
|
|
|
|
|
|
|
|
|
ltc_speed = double(ltc_frame - last_ltc_frame) / double(cur_timestamp - last_timestamp);
|
|
|
|
|
DEBUG_TRACE (DEBUG::LTC, string_compose ("LTC speed: %1\n", ltc_speed));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fabs(ltc_speed) > 10.0) {
|
|
|
|
|
ltc_speed = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* the are equivalent
|
|
|
|
|
* TODO: choose the value with larger diff ->
|
|
|
|
|
* minimize roundig errors when extrapolating
|
|
|
|
|
*/
|
|
|
|
|
#if 1
|
|
|
|
|
last_timestamp = now;
|
|
|
|
|
last_ltc_frame = ltc_transport_pos;
|
|
|
|
|
#else
|
|
|
|
|
last_timestamp = frame.off_end + 1;
|
|
|
|
|
last_ltc_frame = ltc_frame;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
have_frame = true;
|
|
|
|
|
} /* end foreach decoded LTC frame */
|
|
|
|
|
|
|
|
|
|
return have_frame;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
LTC_Slave::init_ltc_dll(framepos_t const tme, double const dt)
|
|
|
|
|
LTC_Slave::init_engine_dll (framepos_t pos, int32_t inc)
|
|
|
|
|
{
|
|
|
|
|
omega = 2.0 * M_PI * (2.0 * dt) / double(session.frame_rate());
|
|
|
|
|
double omega = 2.0 * M_PI * double(inc) / double(session.frame_rate());
|
|
|
|
|
b = 1.4142135623730950488 * omega;
|
|
|
|
|
c = omega * omega;
|
|
|
|
|
|
|
|
|
|
e2 = dt;
|
|
|
|
|
t0 = double(tme);
|
|
|
|
|
e2 = double(ltc_speed * inc);
|
|
|
|
|
t0 = double(pos);
|
|
|
|
|
t1 = t0 + e2;
|
|
|
|
|
DEBUG_TRACE (DEBUG::LTC, string_compose ("[re-]init LTC DLL %1 %2 %3\n", t0, t1, e2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
LTC_Slave::init_engine_dll (framepos_t pos, framepos_t inc)
|
|
|
|
|
{
|
|
|
|
|
/* the bandwidth of the DLL is a trade-off,
|
|
|
|
|
* because the max-speed of the transport in ardour is
|
|
|
|
|
* limited to +-8.0, a larger bandwidth would cause oscillations
|
|
|
|
|
*
|
|
|
|
|
* But this is only really a problem if the user performs manual
|
|
|
|
|
* seeks while transport is running and slaved to LTC.
|
|
|
|
|
*/
|
|
|
|
|
oe = 2.0 * M_PI * double(inc) / double(session.frame_rate());
|
|
|
|
|
be = 1.4142135623730950488 * oe;
|
|
|
|
|
ce = oe * oe;
|
|
|
|
|
|
|
|
|
|
ee2 = double(transport_direction * inc);
|
|
|
|
|
te0 = double(pos);
|
|
|
|
|
te1 = te0 + ee2;
|
|
|
|
|
DEBUG_TRACE (DEBUG::LTC, string_compose ("[re-]init Engine DLL %1 %2 %3\n", te0, te1, ee2));
|
|
|
|
|
DEBUG_TRACE (DEBUG::LTC, string_compose ("[re-]init Engine DLL %1 %2 %3\n", t0, t1, e2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* main entry point from session_process.cc
|
|
|
|
|
* called from jack_process callback context
|
|
|
|
|
* so it is OK to use jack_port_get_buffer() etc
|
|
|
|
|
* so it is OK to use jack_port_get_buffer()
|
|
|
|
|
*/
|
|
|
|
|
bool
|
|
|
|
|
LTC_Slave::speed_and_position (double& speed, framepos_t& pos)
|
|
|
|
|
{
|
|
|
|
|
//framepos_t now = session.engine().frame_time_at_cycle_start();
|
|
|
|
|
//framepos_t now = session.engine().processed_frames();
|
|
|
|
|
framepos_t now = monotonic_cnt;
|
|
|
|
|
bool engine_init_called = false;
|
|
|
|
|
framepos_t now = session.engine().frame_time_at_cycle_start();
|
|
|
|
|
framepos_t sess_pos = session.transport_frame(); // corresponds to now
|
|
|
|
|
framecnt_t nframes = session.engine().frames_per_cycle();
|
|
|
|
|
|
|
|
|
|
jack_default_audio_sample_t *in;
|
|
|
|
|
jack_latency_range_t ltc_latency;
|
|
|
|
|
|
|
|
|
|
monotonic_cnt += nframes;
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<Port> ltcport = session.engine().ltc_input_port();
|
|
|
|
|
ltcport->get_connected_latency_range(ltc_latency, false);
|
|
|
|
|
in = (jack_default_audio_sample_t*) jack_port_get_buffer (ltcport->jack_port(), nframes);
|
|
|
|
|
|
|
|
|
|
DEBUG_TRACE (DEBUG::LTC, string_compose ("LTC_Slave::speed_and_position - TID:%1 | latency: %2\n", ::pthread_self(), ltc_latency.max));
|
|
|
|
|
frameoffset_t skip = now - (monotonic_cnt + nframes);
|
|
|
|
|
monotonic_cnt = now;
|
|
|
|
|
DEBUG_TRACE (DEBUG::LTC, string_compose ("speed_and_position - TID:%1 | latency: %2 | skip %3\n", ::pthread_self(), ltc_latency.max, skip));
|
|
|
|
|
|
|
|
|
|
if (last_timestamp == 0) {
|
|
|
|
|
engine_dll_initstate = 0;
|
|
|
|
|
delayedlocked++;
|
|
|
|
|
}
|
|
|
|
|
else if (engine_dll_initstate != transport_direction) {
|
|
|
|
|
else if (engine_dll_initstate != transport_direction && ltc_speed != 0) {
|
|
|
|
|
engine_dll_initstate = transport_direction;
|
|
|
|
|
init_engine_dll(last_ltc_frame, session.engine().frames_per_cycle());
|
|
|
|
|
init_engine_dll(last_ltc_frame + rint(ltc_speed * double(2 * nframes + now - last_timestamp)),
|
|
|
|
|
session.engine().frames_per_cycle());
|
|
|
|
|
engine_init_called = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (in) {
|
|
|
|
|
parse_ltc(nframes, in, now + ltc_latency.max );
|
|
|
|
|
if (!process_ltc(now, sess_pos, nframes) && ltc_speed != 0) {
|
|
|
|
|
DEBUG_TRACE (DEBUG::LTC, string_compose ("LTC Process eng-tme: %1 eng-pos: %2\n", now, sess_pos));
|
|
|
|
|
/* when the jack-graph changes and if ardour performs
|
|
|
|
|
* locates, the audioengine is stopped (skipping frames) while
|
|
|
|
|
* jack [time] moves along.
|
|
|
|
|
*/
|
|
|
|
|
if (skip > 0) {
|
|
|
|
|
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);
|
|
|
|
|
ltc_decoder_write(decoder, sound, nframes, now);
|
|
|
|
|
} else if (skip != 0) {
|
|
|
|
|
/* this should never happen. it may if monotonic_cnt, now overflow on 64bit */
|
|
|
|
|
DEBUG_TRACE (DEBUG::LTC, string_compose("engine skipped %1 frames\n", skip));
|
|
|
|
|
reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parse_ltc(nframes, in, now + ltc_latency.max );
|
|
|
|
|
process_ltc(now);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (last_timestamp == 0) {
|
|
|
|
|
DEBUG_TRACE (DEBUG::LTC, "last timestamp == 0\n");
|
|
|
|
|
speed = 0;
|
|
|
|
|
pos = session.transport_frame();
|
|
|
|
|
return true;
|
|
|
|
|
} else if (ltc_speed != 0) {
|
|
|
|
|
delayedlocked = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (abs(now - last_timestamp) > FLYWHEEL_TIMEOUT) {
|
|
|
|
|
DEBUG_TRACE (DEBUG::LTC, "flywheel timeout\n");
|
|
|
|
|
reset();
|
|
|
|
|
speed = 0;
|
|
|
|
|
pos = session.transport_frame();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* it take 2 cycles from naught to rolling.
|
|
|
|
|
* during these to initial cycles the speed == 0
|
|
|
|
|
*
|
|
|
|
|
* the first cycle:
|
|
|
|
|
* DEBUG::Slave: slave stopped, move to NNN
|
|
|
|
|
* DEBUG::Transport: Request forced locate to NNN
|
|
|
|
|
* DEBUG::Slave: slave state 0 @ NNN speed 0 cur delta VERY-LARGE-DELTA avg delta 1800
|
|
|
|
|
* DEBUG::Slave: silent motion
|
|
|
|
|
* DEBUG::Transport: realtime stop @ NNN
|
|
|
|
|
* DEBUG::Transport: Butler transport work, todo = PostTransportStop,PostTransportLocate,PostTransportClearSubstate
|
|
|
|
|
*
|
|
|
|
|
* [engine skips frames to locate, jack time keeps rolling on]
|
|
|
|
|
*
|
|
|
|
|
* the second cycle:
|
|
|
|
|
*
|
|
|
|
|
* DEBUG::LTC: [re-]init Engine DLL
|
|
|
|
|
* DEBUG::Slave: slave stopped, move to NNN+
|
|
|
|
|
* ...
|
|
|
|
|
*
|
|
|
|
|
* we need to seek two cycles ahead: 2 * nframes
|
|
|
|
|
*/
|
|
|
|
|
if (engine_dll_initstate == 0) {
|
|
|
|
|
DEBUG_TRACE (DEBUG::LTC, "engine DLL not initialized. ltc_speed\n");
|
|
|
|
|
speed = 0;
|
|
|
|
|
pos = last_ltc_frame + rint(ltc_speed * double(2 * nframes + now - last_timestamp));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* interpolate position according to speed and time since last LTC-frame*/
|
|
|
|
|
double speed_flt = ltc_speed;
|
|
|
|
|
framecnt_t elapsed;
|
|
|
|
|
if (speed_flt == 0.0f) {
|
|
|
|
|
elapsed = 0;
|
|
|
|
|
double elapsed = (now - last_timestamp) * speed_flt;
|
|
|
|
|
|
|
|
|
|
if (!engine_init_called) {
|
|
|
|
|
const double e = elapsed + double (last_ltc_frame - sess_pos);
|
|
|
|
|
t0 = t1;
|
|
|
|
|
t1 += b * e + e2;
|
|
|
|
|
e2 += c * e;
|
|
|
|
|
speed_flt = (t1 - t0) / double(session.engine().frames_per_cycle());
|
|
|
|
|
DEBUG_TRACE (DEBUG::LTC, string_compose ("LTC engine DLL t0:%1 t1:%2 err:%3 spd:%4 ddt:%5\n", t0, t1, e, speed_flt, e2 - session.engine().frames_per_cycle() ));
|
|
|
|
|
} else {
|
|
|
|
|
/* scale elapsed time by the current LTC speed */
|
|
|
|
|
if (last_timestamp && (now > last_timestamp)) {
|
|
|
|
|
elapsed = (now - last_timestamp) * speed_flt;
|
|
|
|
|
} else {
|
|
|
|
|
elapsed = 0;
|
|
|
|
|
}
|
|
|
|
|
/* update engine DLL and calculate speed */
|
|
|
|
|
const double e = double (last_ltc_frame + elapsed - sess_pos);
|
|
|
|
|
te0 = te1;
|
|
|
|
|
te1 += be * e + ee2;
|
|
|
|
|
ee2 += ce * e;
|
|
|
|
|
speed_flt = (te1 - te0) / double(session.engine().frames_per_cycle());
|
|
|
|
|
DEBUG_TRACE (DEBUG::LTC, string_compose ("LTC engine DLL t0:%1 t1:%2 err:%3 spd:%4 ddt:%5\n", te0, te1, e, speed_flt, ee2 - session.engine().frames_per_cycle() ));
|
|
|
|
|
DEBUG_TRACE (DEBUG::LTC, string_compose ("LTC adjusting elapsed (no DLL) from %1 by %2\n", elapsed, (2 * nframes * ltc_speed)));
|
|
|
|
|
speed_flt = 0;
|
|
|
|
|
elapsed += 2.0 * nframes * ltc_speed; /* see note above */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pos = last_ltc_frame + elapsed;
|
|
|
|
|
pos = last_ltc_frame + rint(elapsed);
|
|
|
|
|
speed = speed_flt;
|
|
|
|
|
current_delta = (pos - sess_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();
|
|
|
|
|
speed = 0;
|
|
|
|
|
pos = session.transport_frame();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DEBUG_TRACE (DEBUG::LTC, string_compose ("LTCsync spd: %1 pos: %2 | last-pos: %3 elapsed: %4 delta: %5\n",
|
|
|
|
|
speed, pos, last_ltc_frame, elapsed, current_delta));
|
|
|
|
|
|
|
|
|
|
if (last_timestamp != 0 /* && frames_in_sequence > 8*/) {
|
|
|
|
|
delayedlocked = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (last_timestamp == 0 || ((now - last_timestamp) > FLYWHEEL_TIMEOUT)) {
|
|
|
|
|
DEBUG_TRACE (DEBUG::LTC, "LTC no-signal - reset\n");
|
|
|
|
|
reset();
|
|
|
|
|
engine_dll_initstate = 0;
|
|
|
|
|
speed = 0;
|
|
|
|
|
pos = session.transport_frame();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (last_timestamp != 0 && ltc_speed != 0 && ((ltc_transport_pos < 0) || (labs(current_delta) > 10 * session.frame_rate()))) {
|
|
|
|
|
DEBUG_TRACE (DEBUG::LTC, string_compose ("LTC large drift. %1\n", current_delta));
|
|
|
|
|
// XXX only re-init engine DLL ?
|
|
|
|
|
reset();
|
|
|
|
|
engine_dll_initstate = 0;
|
|
|
|
|
speed = 0;
|
|
|
|
|
pos = session.transport_frame();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
/* provide a 1% deadzone to lock the speed */
|
|
|
|
|
if (fabs(speed - 1.0) <= 0.01)
|
|
|
|
|
#if 1 /* provide a .1% deadzone to lock the speed */
|
|
|
|
|
if (fabs(speed - 1.0) <= 0.001)
|
|
|
|
|
speed = 1.0;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
@@ -554,13 +467,11 @@ std::string
|
|
|
|
|
LTC_Slave::approximate_current_delta() const
|
|
|
|
|
{
|
|
|
|
|
char delta[24];
|
|
|
|
|
if (last_timestamp == 0 || frames_in_sequence < 2) {
|
|
|
|
|
if (last_timestamp == 0 || engine_dll_initstate == 0) {
|
|
|
|
|
snprintf(delta, sizeof(delta), "\u2012\u2012\u2012\u2012");
|
|
|
|
|
} else if ((monotonic_cnt - last_timestamp) > 2 * frames_per_ltc_frame) {
|
|
|
|
|
snprintf(delta, sizeof(delta), "flywheel");
|
|
|
|
|
} else {
|
|
|
|
|
// TODO if current_delta > 1 frame -> display timecode.
|
|
|
|
|
// delta >0 if A3's transport is _behind_ LTC
|
|
|
|
|
snprintf(delta, sizeof(delta), "%s%4" PRIi64 " sm",
|
|
|
|
|
PLUSMINUS(-current_delta), abs(current_delta));
|
|
|
|
|
}
|
|
|
|
|
|