Browse Source

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.
pull/9/head
falkTX 9 years ago
parent
commit
eb19b1a582
1 changed files with 8 additions and 3 deletions
  1. +8
    -3
      transport.c

+ 8
- 3
transport.c View File

@@ -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) {


Loading…
Cancel
Save