From eb19b1a582192ff5603a6c1e579ec71a1aa5e88d Mon Sep 17 00:00:00 2001 From: falkTX Date: Tue, 13 Dec 2016 16:58:48 +0100 Subject: [PATCH] transport.c: fix drift due to rounding errors store real tick value internally as double. use it when calculating changes, then finally set the real tick. --- transport.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/transport.c b/transport.c index a1b0ab7..9cc80cc 100644 --- a/transport.c +++ b/transport.c @@ -32,6 +32,7 @@ char *package; /* program name */ int done = 0; jack_client_t *client; +double last_tick; /* Time and tempo variables. These are global to the entire, * transport timeline. There is no attempt to keep a true tempo map. @@ -83,6 +84,8 @@ void timebase(jack_transport_state_t state, jack_nframes_t nframes, pos->ticks_per_beat; pos->bar++; /* adjust start to bar 1 */ + last_tick = pos->tick; + #if 0 /* some debug code... */ fprintf(stderr, "\nnew position: %" PRIu32 "\tBBT: %3" @@ -93,12 +96,12 @@ void timebase(jack_transport_state_t state, jack_nframes_t nframes, } else { /* Compute BBT info based on previous period. */ - pos->tick += + last_tick += nframes * pos->ticks_per_beat * pos->beats_per_minute / (pos->frame_rate * 60); - while (pos->tick >= pos->ticks_per_beat) { - pos->tick -= pos->ticks_per_beat; + while (last_tick >= pos->ticks_per_beat) { + last_tick -= pos->ticks_per_beat; if (++pos->beat > pos->beats_per_bar) { pos->beat = 1; ++pos->bar; @@ -107,6 +110,8 @@ void timebase(jack_transport_state_t state, jack_nframes_t nframes, * pos->ticks_per_beat; } } + + pos->tick = (int)(last_tick + 0.5); } if (avr_set) {