added phase-lock for slave mode

pull/7/head 0.10.4
midilab 4 years ago
parent f0750eb6bb
commit 5eb220db81
  1. 18
      src/uClock.cpp
  2. 1
      src/uClock.h

@ -104,6 +104,7 @@ uClockClass::uClockClass()
// drift is used to sligth calibrate with your slave clock
drift = 1;
slave_drift = 0;
pll_x = 220;
tempo = 120;
start_timer = 0;
last_interval = 0;
@ -291,15 +292,12 @@ void uClockClass::handleExternalClock()
last_interval = clock_diff(last_clock, _clock);
last_clock = _clock;
// accumulate interval incomming ticks data for getTempo() smooth reads on slave mode
ext_interval_buffer[ext_interval_idx++ % EXT_INTERVAL_BUFFER_SIZE] = last_interval;
// slave tick me!
external_tick++;
// callback counters
inmod6_counter++;
if (inmod6_counter == 6) {
inmod6_counter = 0;
}
switch (state) {
case PAUSED:
break;
@ -309,9 +307,11 @@ void uClockClass::handleExternalClock()
break;
case STARTED:
interval = last_interval + slave_drift;
// accumulate interval incomming ticks data for getTempo() smooth reads on slave mode
ext_interval_buffer[ext_interval_idx++ % EXT_INTERVAL_BUFFER_SIZE] = interval;
if (external_tick == 1) {
interval = last_interval;
} else {
interval = (((uint32_t)interval * (uint32_t)pll_x) + (uint32_t)(256 - pll_x) * (uint32_t)last_interval) >> 8;
}
break;
}
}

@ -65,6 +65,7 @@ class uClockClass {
uint32_t div16th_counter;
uint8_t mod6_counter;
uint16_t counter;
uint16_t pll_x;
uint32_t last_tick;
uint8_t drift;

Loading…
Cancel
Save