tests and tunnings

pull/5/head
midilab 3 years ago
parent 59cd1c7e18
commit 16d0ea9804
  1. 55
      src/uClock.cpp
  2. 1
      src/uClock.h

@ -324,13 +324,34 @@ void uClockClass::handleExternalClock()
void uClockClass::handleTimerInt() void uClockClass::handleTimerInt()
{ {
counter = interval; if (mode == EXTERNAL_CLOCK) {
if ((internal_tick < external_tick) || (internal_tick > (external_tick + 1))) {
internal_tick = external_tick;
div32th_counter = indiv32th_counter;
div16th_counter = indiv16th_counter;
mod6_counter = inmod6_counter;
}
counter = interval;
uint32_t u_timer = micros();
sync_interval = clock_diff(external_clock, u_timer);
if (internal_tick <= external_tick) {
counter -= phase_mult(sync_interval);
} else {
if (counter > sync_interval) {
counter += phase_mult(counter - sync_interval);
}
}
if ((internal_tick < external_tick) || (internal_tick > (external_tick + 1))) { // update internal clock timer frequency
internal_tick = external_tick; float bpm = freqToBpm(counter);
div32th_counter = indiv32th_counter; if (bpm != tempo) {
div16th_counter = indiv16th_counter; if (bpm >= MIN_BPM && bpm <= MAX_BPM) {
mod6_counter = inmod6_counter; tempo = bpm;
setTimerTempo(tempo);
}
}
} }
if (onClock96PPQNCallback) { if (onClock96PPQNCallback) {
@ -363,28 +384,6 @@ void uClockClass::handleTimerInt()
mod6_counter = 0; mod6_counter = 0;
} }
if (mode == EXTERNAL_CLOCK) {
uint32_t u_timer = micros();
sync_interval = clock_diff(external_clock, u_timer);
if (internal_tick <= external_tick) {
counter -= phase_mult(sync_interval);
} else {
if (counter > sync_interval) {
counter += phase_mult(counter - sync_interval);
}
}
// update internal clock timer frequency
float bpm = freqToBpm(counter);
if (bpm != tempo) {
if (bpm >= MIN_BPM && bpm <= MAX_BPM) {
tempo = bpm;
setTimerTempo(tempo);
}
}
}
} }
// elapsed time support // elapsed time support

@ -63,7 +63,6 @@ class uClockClass {
void (*onClockStartCallback)(); void (*onClockStartCallback)();
void (*onClockStopCallback)(); void (*onClockStopCallback)();
volatile uint32_t interval; volatile uint32_t interval;
volatile uint32_t external_clock; volatile uint32_t external_clock;
uint32_t tick_us_interval; uint32_t tick_us_interval;

Loading…
Cancel
Save