|
|
@ -142,6 +142,9 @@ uClockClass::uClockClass() |
|
|
|
|
|
|
|
|
|
|
|
void uClockClass::init() |
|
|
|
void uClockClass::init() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (ext_interval_buffer == nullptr) |
|
|
|
|
|
|
|
setExtIntervalBuffer(1); |
|
|
|
|
|
|
|
|
|
|
|
uclockInitTimer(); |
|
|
|
uclockInitTimer(); |
|
|
|
// first interval calculus
|
|
|
|
// first interval calculus
|
|
|
|
setTempo(tempo); |
|
|
|
setTempo(tempo); |
|
|
@ -244,14 +247,14 @@ float uClockClass::getTempo() |
|
|
|
if (clock_mode == EXTERNAL_CLOCK) { |
|
|
|
if (clock_mode == EXTERNAL_CLOCK) { |
|
|
|
uint32_t acc = 0; |
|
|
|
uint32_t acc = 0; |
|
|
|
// wait the buffer to get full
|
|
|
|
// wait the buffer to get full
|
|
|
|
if (ext_interval_buffer[EXT_INTERVAL_BUFFER_SIZE-1] == 0) { |
|
|
|
if (ext_interval_buffer[ext_interval_buffer_size-1] == 0) { |
|
|
|
return tempo; |
|
|
|
return tempo; |
|
|
|
} |
|
|
|
} |
|
|
|
for (uint8_t i=0; i < EXT_INTERVAL_BUFFER_SIZE; i++) { |
|
|
|
for (uint8_t i=0; i < ext_interval_buffer_size; i++) { |
|
|
|
acc += ext_interval_buffer[i]; |
|
|
|
acc += ext_interval_buffer[i]; |
|
|
|
} |
|
|
|
} |
|
|
|
if (acc != 0) { |
|
|
|
if (acc != 0) { |
|
|
|
return freqToBpm(acc / EXT_INTERVAL_BUFFER_SIZE); |
|
|
|
return freqToBpm(acc / ext_interval_buffer_size); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return tempo; |
|
|
|
return tempo; |
|
|
@ -291,6 +294,16 @@ void uClockClass::clockMe() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void uClockClass::setExtIntervalBuffer(uint8_t buffer_size) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (ext_interval_buffer != nullptr) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// alloc once and forever policy
|
|
|
|
|
|
|
|
ext_interval_buffer_size = buffer_size; |
|
|
|
|
|
|
|
ext_interval_buffer = (uint32_t*) malloc( sizeof(uint32_t) * ext_interval_buffer_size ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void uClockClass::resetCounters() |
|
|
|
void uClockClass::resetCounters() |
|
|
|
{ |
|
|
|
{ |
|
|
|
tick = 0; |
|
|
|
tick = 0; |
|
|
@ -317,7 +330,7 @@ void uClockClass::resetCounters() |
|
|
|
mod_sync48_counter = 0; |
|
|
|
mod_sync48_counter = 0; |
|
|
|
sync48_tick = 0; |
|
|
|
sync48_tick = 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; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -434,7 +447,7 @@ void uClockClass::handleExternalClock() |
|
|
|
ext_clock_tick++; |
|
|
|
ext_clock_tick++; |
|
|
|
|
|
|
|
|
|
|
|
// accumulate interval incomming ticks data for getTempo() smooth reads on slave clock_mode
|
|
|
|
// accumulate interval incomming ticks data for getTempo() smooth reads on slave clock_mode
|
|
|
|
if(++ext_interval_idx >= EXT_INTERVAL_BUFFER_SIZE) { |
|
|
|
if(++ext_interval_idx >= ext_interval_buffer_size) { |
|
|
|
ext_interval_idx = 0; |
|
|
|
ext_interval_idx = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
ext_interval_buffer[ext_interval_idx] = last_interval; |
|
|
|
ext_interval_buffer[ext_interval_idx] = last_interval; |
|
|
|