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

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

Loading…
Cancel
Save