diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2009-12-01 02:04:10 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2009-12-01 02:04:10 +0000 |
commit | 1614402e50bee4deca5c2c20cdd89eb09d10252b (patch) | |
tree | 78c614bf0f656484da8e60e4a27b2a4da5215c36 /libs/ardour/mtc_slave.cc | |
parent | 929f9a101a26ba11230a8185f72524185fe05953 (diff) |
continue with MTC debugging
git-svn-id: svn://localhost/ardour2/branches/3.0@6235 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/mtc_slave.cc')
-rw-r--r-- | libs/ardour/mtc_slave.cc | 71 |
1 files changed, 41 insertions, 30 deletions
diff --git a/libs/ardour/mtc_slave.cc b/libs/ardour/mtc_slave.cc index 609f9862c3..a0830f3f06 100644 --- a/libs/ardour/mtc_slave.cc +++ b/libs/ardour/mtc_slave.cc @@ -77,10 +77,13 @@ MTC_Slave::update_mtc_qtr (Parser& /*p*/) qtr = (long) (session.frames_per_timecode_frame() / 4); mtc_frame += qtr; + + double speed = compute_apparent_speed (now); current.guard1++; current.position = mtc_frame; current.timestamp = now; + current.speed = speed; current.guard2++; last_inbound_frame = now; @@ -146,7 +149,6 @@ MTC_Slave::update_mtc_time (const byte *msg, bool was_full) } else { - double speed; /* We received the last quarter frame 7 quarter frames (1.75 mtc frames) after the instance when the contents of the mtc quarter @@ -156,47 +158,56 @@ MTC_Slave::update_mtc_time (const byte *msg, bool was_full) */ mtc_frame += (long) (1.75 * session.frames_per_timecode_frame()) + session.worst_output_latency(); - - if (current.timestamp != 0) { - - speed = (double) ((mtc_frame - current.position) / (double) (now - current.timestamp)); - DEBUG_TRACE (DEBUG::MTC, string_compose ("instantaneous speed = %1 from %2 - %3 / %4 - %5\n", - speed, mtc_frame, current.position, now, current.timestamp)); - - accumulator[accumulator_index++] = speed; - - if (accumulator_index >= accumulator_size) { - have_first_accumulated_speed = true; - accumulator_index = 0; - } - - if (have_first_accumulated_speed) { - double total = 0; - - for (int32_t i = 0; i < accumulator_size; ++i) { - total += accumulator[i]; - } - - speed = total / accumulator_size; - DEBUG_TRACE (DEBUG::MTC, string_compose ("speed smoothed to %1\n", speed)); - } - - } else { - - speed = 0; - } + + double speed = compute_apparent_speed (now); current.guard1++; current.position = mtc_frame; current.timestamp = now; current.speed = speed; current.guard2++; + DEBUG_TRACE (DEBUG::MTC, string_compose ("stored TC frame = %1 @ %2, sp = %3\n", mtc_frame, now, speed)); } last_inbound_frame = now; } +double +MTC_Slave::compute_apparent_speed (nframes64_t now) +{ + if (current.timestamp != 0) { + + double speed = (double) ((mtc_frame - current.position) / (double) (now - current.timestamp)); + DEBUG_TRACE (DEBUG::MTC, string_compose ("instantaneous speed = %1 from %2 - %3 / %4 - %5\n", + speed, mtc_frame, current.position, now, current.timestamp)); + + accumulator[accumulator_index++] = speed; + + if (accumulator_index >= accumulator_size) { + have_first_accumulated_speed = true; + accumulator_index = 0; + } + + if (have_first_accumulated_speed) { + double total = 0; + + for (int32_t i = 0; i < accumulator_size; ++i) { + total += accumulator[i]; + } + + speed = total / accumulator_size; + DEBUG_TRACE (DEBUG::MTC, string_compose ("speed smoothed to %1\n", speed)); + } + + return speed; + + } else { + + return 0; + } +} + void MTC_Slave::handle_locate (const MIDI::byte* mmc_tc) { |