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

develop
midilab 6 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() void uClockClass::calculateReferencedata()
{ {
mod_clock_ref = ppqn / clock_ppqn; mod_clock_ref = ppqn / clock_ppqn;
mod_sync1_ref = ppqn / PPQN_1; mod_sync1_ref = ppqn / PPQN_1;
mod_sync2_ref = ppqn / PPQN_2; mod_sync2_ref = ppqn / PPQN_2;
mod_sync4_ref = ppqn / PPQN_4; mod_sync4_ref = ppqn / PPQN_4;
mod_sync8_ref = ppqn / PPQN_8; mod_sync8_ref = ppqn / PPQN_8;
mod_sync12_ref = ppqn / PPQN_12; mod_sync12_ref = ppqn / PPQN_12;
mod_sync24_ref = ppqn / PPQN_24; mod_sync24_ref = ppqn / PPQN_24;
mod_sync48_ref = ppqn / PPQN_48; mod_sync48_ref = ppqn / PPQN_48;
mod_step_ref = ppqn / 4; mod_step_ref = ppqn / 4;
} }
void uClockClass::setPPQN(PPQNResolution resolution) void uClockClass::setPPQN(PPQNResolution resolution)
{ {
// TODO: dont allow PPQN lower than 4(to avoid problems with mod_step_ref)
ATOMIC( ATOMIC(
ppqn = resolution; ppqn = resolution;
calculateReferencedata(); calculateReferencedata();
@ -318,10 +319,11 @@ void uClockClass::resetCounters()
} }
} }
// TODO: Tap stuff
void uClockClass::tap() 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) void uClockClass::setShuffle(bool active)
@ -409,7 +411,6 @@ bool inline uClockClass::processShuffle()
return false; return false;
} }
// TODO: needs to check clock signals against current phase lock parameters(based on 24ppqn sync)
void uClockClass::handleExternalClock() void uClockClass::handleExternalClock()
{ {
switch (state) { switch (state) {

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

Loading…
Cancel
Save