update all mod_clock_refs to uint16_t to avoid overflow on higher PPQNs.

develop
midilab 4 days ago
parent e1d6674635
commit 3619eb53f6
  1. 23
      src/uClock.cpp
  2. 27
      src/uClock.h

@ -155,18 +155,19 @@ uint32_t uClockClass::bpmToMicroSeconds(float bpm)
void uClockClass::calculateReferencedata()
{
mod_clock_ref = ppqn / clock_ppqn;
mod_sync1_ref = ppqn / PPQN_1;
mod_sync2_ref = ppqn / PPQN_2;
mod_sync4_ref = ppqn / PPQN_4;
mod_sync8_ref = ppqn / PPQN_8;
mod_sync12_ref = ppqn / PPQN_12;
mod_sync24_ref = ppqn / PPQN_24;
mod_sync48_ref = ppqn / PPQN_48;
mod_step_ref = ppqn / 4;
mod_sync1_ref = ppqn / PPQN_1;
mod_sync2_ref = ppqn / PPQN_2;
mod_sync4_ref = ppqn / PPQN_4;
mod_sync8_ref = ppqn / PPQN_8;
mod_sync12_ref = ppqn / PPQN_12;
mod_sync24_ref = ppqn / PPQN_24;
mod_sync48_ref = ppqn / PPQN_48;
mod_step_ref = ppqn / 4;
}
void uClockClass::setPPQN(PPQNResolution resolution)
{
// TODO: dont allow PPQN lower than 4(to avoid problems with mod_step_ref)
ATOMIC(
ppqn = resolution;
calculateReferencedata();
@ -318,10 +319,11 @@ void uClockClass::resetCounters()
}
}
// TODO: Tap stuff
void uClockClass::tap()
{
// tap me
// we can make use of mod_sync1_ref for tap
//uint8_t mod_tap_ref = ppqn / PPQN_1;
// we only set tap if SyncMode is INTERNAL_CLOCK
}
void uClockClass::setShuffle(bool active)
@ -409,7 +411,6 @@ bool inline uClockClass::processShuffle()
return false;
}
// TODO: needs to check clock signals against current phase lock parameters(based on 24ppqn sync)
void uClockClass::handleExternalClock()
{
switch (state) {

@ -50,7 +50,7 @@ typedef struct {
#define EXT_INTERVAL_BUFFER_SIZE 128
#define MIN_BPM 1
#define MAX_BPM 300
#define MAX_BPM 400
#define PHASE_FACTOR 16
#define PLL_X 220
@ -200,40 +200,39 @@ class uClockClass {
void (*onClockStartCallback)();
void (*onClockStopCallback)();
// internal clock control
// uint16_t ppqn;
// clock control
PPQNResolution ppqn = PPQN_96;
PPQNResolution clock_ppqn = PPQN_24;
// output and internal counters, ticks and references
uint32_t tick;
uint32_t int_clock_tick;
uint8_t mod_clock_counter;
uint8_t mod_clock_ref;
uint16_t mod_clock_ref;
uint8_t mod_step_counter;
uint8_t mod_step_ref;
uint32_t step_counter; // should we go uint16_t?
// clock output counters, ticks and references
uint32_t step_counter;
uint8_t mod_sync1_counter;
uint8_t mod_sync1_ref;
uint16_t mod_sync1_ref;
uint32_t sync1_tick;
uint8_t mod_sync2_counter;
uint8_t mod_sync2_ref;
uint16_t mod_sync2_ref;
uint32_t sync2_tick;
uint8_t mod_sync4_counter;
uint8_t mod_sync4_ref;
uint16_t mod_sync4_ref;
uint32_t sync4_tick;
uint8_t mod_sync8_counter;
uint8_t mod_sync8_ref;
uint16_t mod_sync8_ref;
uint32_t sync8_tick;
uint8_t mod_sync12_counter;
uint8_t mod_sync12_ref;
uint16_t mod_sync12_ref;
uint32_t sync12_tick;
uint8_t mod_sync24_counter;
uint8_t mod_sync24_ref;
uint16_t mod_sync24_ref;
uint32_t sync24_tick;
uint8_t mod_sync48_counter;
uint8_t mod_sync48_ref;
uint16_t mod_sync48_ref;
uint32_t sync48_tick;
// external clock control
volatile uint32_t ext_clock_us;
volatile uint32_t ext_clock_tick;

Loading…
Cancel
Save