|
|
@ -79,67 +79,6 @@ uint16_t clock_diff(uint16_t old_clock, uint16_t new_clock) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void uClockClass::handleClock()
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
uint16_t cur_clock = _clock; |
|
|
|
|
|
|
|
uint16_t diff; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cur_clock > last_clock) { |
|
|
|
|
|
|
|
diff = cur_clock - last_clock; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
diff = cur_clock + (65535 - last_clock); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
last_interval = diff; |
|
|
|
|
|
|
|
last_clock = cur_clock; |
|
|
|
|
|
|
|
indiv96th_counter++; |
|
|
|
|
|
|
|
inmod6_counter++; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (inmod6_counter == 6) { |
|
|
|
|
|
|
|
inmod6_counter = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (state) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case PAUSED: |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case STARTING: |
|
|
|
|
|
|
|
state = STARTED; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case STARTED: |
|
|
|
|
|
|
|
if (indiv96th_counter == 2) { |
|
|
|
|
|
|
|
interval = diff; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
interval = (((uint32_t)interval * (uint32_t)pll_x) + (uint32_t)(256 - pll_x) * (uint32_t)diff) >> 8; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void uClockClass::handleStart()
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (mode == EXTERNAL_CLOCK) { |
|
|
|
|
|
|
|
init(); |
|
|
|
|
|
|
|
state = STARTING; |
|
|
|
|
|
|
|
mod6_counter = 0; |
|
|
|
|
|
|
|
div96th_counter = 0; |
|
|
|
|
|
|
|
div32th_counter = 0; |
|
|
|
|
|
|
|
div16th_counter = 0; |
|
|
|
|
|
|
|
counter = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void uClockClass::handleStop()
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (mode == EXTERNAL_CLOCK) { |
|
|
|
|
|
|
|
state = PAUSED; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define PHASE_FACTOR 16 |
|
|
|
#define PHASE_FACTOR 16 |
|
|
|
static uint32_t phase_mult(uint32_t val)
|
|
|
|
static uint32_t phase_mult(uint32_t val)
|
|
|
|
{ |
|
|
|
{ |
|
|
@ -154,9 +93,19 @@ void uClockClass::start() |
|
|
|
div96th_counter = 0; |
|
|
|
div96th_counter = 0; |
|
|
|
div32th_counter = 0; |
|
|
|
div32th_counter = 0; |
|
|
|
div16th_counter = 0; |
|
|
|
div16th_counter = 0; |
|
|
|
if (onClockStartCallback) { |
|
|
|
} else { |
|
|
|
onClockStartCallback(); |
|
|
|
//if (mode == EXTERNAL_CLOCK) {
|
|
|
|
} |
|
|
|
init(); |
|
|
|
|
|
|
|
state = STARTING; |
|
|
|
|
|
|
|
mod6_counter = 0; |
|
|
|
|
|
|
|
div96th_counter = 0; |
|
|
|
|
|
|
|
div32th_counter = 0; |
|
|
|
|
|
|
|
div16th_counter = 0; |
|
|
|
|
|
|
|
counter = 0; |
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (onClockStartCallback) { |
|
|
|
|
|
|
|
onClockStartCallback(); |
|
|
|
}
|
|
|
|
}
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -164,25 +113,33 @@ void uClockClass::stop() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (mode == INTERNAL_CLOCK) { |
|
|
|
if (mode == INTERNAL_CLOCK) { |
|
|
|
state = PAUSED; |
|
|
|
state = PAUSED; |
|
|
|
if (onClockStopCallback) { |
|
|
|
} else { |
|
|
|
onClockStopCallback(); |
|
|
|
//if (mode == EXTERNAL_CLOCK) {
|
|
|
|
} |
|
|
|
state = PAUSED; |
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (onClockStopCallback) { |
|
|
|
|
|
|
|
onClockStopCallback(); |
|
|
|
}
|
|
|
|
}
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void uClockClass::pause()
|
|
|
|
void uClockClass::pause()
|
|
|
|
{ |
|
|
|
{ |
|
|
|
if (mode == INTERNAL_CLOCK) { |
|
|
|
//if (mode == INTERNAL_CLOCK) {
|
|
|
|
if (state == PAUSED) { |
|
|
|
if (state == PAUSED) { |
|
|
|
start(); |
|
|
|
start(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
stop(); |
|
|
|
stop(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//}
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void uClockClass::setTempo(uint16_t _tempo)
|
|
|
|
void uClockClass::setTempo(uint16_t _tempo)
|
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (mode == EXTERNAL_CLOCK) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ( tempo == _tempo ) { |
|
|
|
if ( tempo == _tempo ) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -198,6 +155,11 @@ uint16_t uClockClass::getTempo() |
|
|
|
return tempo; |
|
|
|
return tempo; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void uClockClass::setMode(uint8_t tempo_mode)
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
mode = tempo_mode; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void uClockClass::clockMe()
|
|
|
|
void uClockClass::clockMe()
|
|
|
|
{ |
|
|
|
{ |
|
|
|
if (uClock.mode == uClock.EXTERNAL_CLOCK) { |
|
|
|
if (uClock.mode == uClock.EXTERNAL_CLOCK) { |
|
|
@ -217,6 +179,54 @@ void uClockClass::shuffle() |
|
|
|
// shuffle me
|
|
|
|
// shuffle me
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void uClockClass::handleClock()
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
uint16_t cur_clock = _clock; |
|
|
|
|
|
|
|
uint16_t diff; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cur_clock > last_clock) { |
|
|
|
|
|
|
|
diff = cur_clock - last_clock; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
diff = cur_clock + (65535 - last_clock); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
last_interval = diff; |
|
|
|
|
|
|
|
last_clock = cur_clock; |
|
|
|
|
|
|
|
indiv96th_counter++; |
|
|
|
|
|
|
|
inmod6_counter++; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (inmod6_counter == 6) { |
|
|
|
|
|
|
|
inmod6_counter = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (state) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case PAUSED: |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case STARTING: |
|
|
|
|
|
|
|
state = STARTED; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case STARTED: |
|
|
|
|
|
|
|
if (indiv96th_counter == 2) { |
|
|
|
|
|
|
|
interval = diff; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
interval = (((uint32_t)interval * (uint32_t)pll_x) + (uint32_t)(256 - pll_x) * (uint32_t)diff) >> 8; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
interval = (uint32_t)((uint32_t)156250 / tempo) - 16; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interval = x(156250 / tempo) - 16; |
|
|
|
|
|
|
|
x(156250 / tempo) = -16 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void uClockClass::handleTimerInt()
|
|
|
|
void uClockClass::handleTimerInt()
|
|
|
|
{ |
|
|
|
{ |
|
|
|
if (counter == 0) { |
|
|
|
if (counter == 0) { |
|
|
|