external sync 24PPQN revised for v2

pull/34/head
midilab 10 months ago
parent 7ece8b9341
commit 38bde64519
  1. 66
      src/uClock.cpp

@ -241,9 +241,6 @@ void uClockClass::resetCounters()
ext_clock_tick = 0; ext_clock_tick = 0;
ext_clock_us = 0; ext_clock_us = 0;
ext_interval_idx = 0; ext_interval_idx = 0;
//ext_mod24_counter = 0;
//ext_mod_step_counter = 0;
//ext_step_counter = 0;
for (uint8_t i=0; i < EXT_INTERVAL_BUFFER_SIZE; i++) { for (uint8_t i=0; i < EXT_INTERVAL_BUFFER_SIZE; i++) {
ext_interval_buffer[i] = 0; ext_interval_buffer[i] = 0;
@ -378,45 +375,44 @@ void uClockClass::handleExternalClock()
void uClockClass::handleTimerInt() void uClockClass::handleTimerInt()
{ {
// do we put a limit here to check external sync phase? // reset mod24 counter reference ?
// try on at max PPQN if (mod24_counter == mod24_ref)
if (mode == EXTERNAL_CLOCK) { mod24_counter = 0;
// sync tick position with external tick clock
if ((int_clock_tick < ext_clock_tick) || (int_clock_tick > (ext_clock_tick + 1))) {
int_clock_tick = ext_clock_tick;
tick = int_clock_tick * mod24_ref;
mod24_counter = int_clock_tick % mod24_ref;
mod_step_counter = int_clock_tick % mod_step_ref;
}
uint32_t counter = ext_interval; // process sync signals first please...
uint32_t now_clock_us = micros(); if (mod24_counter == 0) {
sync_interval = clock_diff(ext_clock_us, now_clock_us);
if (int_clock_tick <= ext_clock_tick) { if (mode == EXTERNAL_CLOCK) {
counter -= phase_mult(sync_interval); // sync tick position with external tick clock
} else { if ((int_clock_tick < ext_clock_tick) || (int_clock_tick > (ext_clock_tick + 1))) {
if (counter > sync_interval) { int_clock_tick = ext_clock_tick;
counter += phase_mult(counter - sync_interval); tick = int_clock_tick * mod24_ref;
mod24_counter = tick % mod24_ref;
mod_step_counter = tick % mod_step_ref;
} }
}
// update internal clock timer frequency uint32_t counter = ext_interval;
float bpm = freqToBpm(counter); uint32_t now_clock_us = micros();
if (bpm != tempo) { sync_interval = clock_diff(ext_clock_us, now_clock_us);
if (bpm >= MIN_BPM && bpm <= MAX_BPM) {
tempo = bpm; if (int_clock_tick <= ext_clock_tick) {
setTimerTempo(bpm); counter -= phase_mult(sync_interval);
} else {
if (counter > sync_interval) {
counter += phase_mult(counter - sync_interval);
}
} }
}
}
// reset mod24 counter reference ? // update internal clock timer frequency
if (mod24_counter == mod24_ref) float bpm = freqToBpm(counter);
mod24_counter = 0; if (bpm != tempo) {
if (bpm >= MIN_BPM && bpm <= MAX_BPM) {
tempo = bpm;
setTimerTempo(bpm);
}
}
}
// sync signals first please...
if (mod24_counter == 0) {
if (onSync24Callback) { if (onSync24Callback) {
onSync24Callback(int_clock_tick); onSync24Callback(int_clock_tick);
} }

Loading…
Cancel
Save