force static inline on clock_diff and phase_mult(just to make sure the gcc will do it for us)

pull/7/head
midilab 6 years ago
parent b169de4cbc
commit 3158a724f8
  1. 36
      src/uClock.cpp
  2. 30
      src/uClock.h

@ -31,10 +31,25 @@
namespace umodular { namespace clock { namespace umodular { namespace clock {
static inline uint32_t phase_mult(uint32_t val)
{
return (val * PHASE_FACTOR) >> 8;
}
static inline uint16_t clock_diff(uint16_t old_clock, uint16_t new_clock)
{
if (new_clock >= old_clock) {
return new_clock - old_clock;
} else {
return new_clock + (65535 - old_clock);
}
}
uClockClass::uClockClass() uClockClass::uClockClass()
{ {
init(); init();
mode = INTERNAL_CLOCK; mode = INTERNAL_CLOCK;
state = PAUSED;
setTempo(120); setTempo(120);
onClock96PPQNCallback = NULL; onClock96PPQNCallback = NULL;
@ -71,21 +86,6 @@ void uClockClass::init()
SREG = tmpSREG; SREG = tmpSREG;
} }
uint16_t clock_diff(uint16_t old_clock, uint16_t new_clock)
{
if (new_clock >= old_clock) {
return new_clock - old_clock;
} else {
return new_clock + (65535 - old_clock);
}
}
#define PHASE_FACTOR 16
static uint32_t phase_mult(uint32_t val)
{
return (val * PHASE_FACTOR) >> 8;
}
void uClockClass::start() void uClockClass::start()
{ {
start_timer = millis(); start_timer = millis();
@ -180,8 +180,8 @@ void uClockClass::setMode(uint8_t tempo_mode)
void uClockClass::clockMe() void uClockClass::clockMe()
{ {
if (uClock.mode == uClock.EXTERNAL_CLOCK) { if (mode == EXTERNAL_CLOCK) {
uClock.handleClock(); handleClock();
} }
} }
@ -354,7 +354,7 @@ ISR(TIMER1_OVF_vect)
// global timer counter // global timer counter
_timer = millis(); _timer = millis();
if (uClock.state == uClock.STARTED) { if (uClock.state == umodular::clock::STARTED) {
_clock++; _clock++;
uClock.handleTimerInt(); uClock.handleTimerInt();
} }

@ -33,15 +33,28 @@
#include <Arduino.h> #include <Arduino.h>
#include <inttypes.h> #include <inttypes.h>
#define PHASE_FACTOR 16
#define SECS_PER_MIN (60UL) #define SECS_PER_MIN (60UL)
#define SECS_PER_HOUR (3600UL) #define SECS_PER_HOUR (3600UL)
#define SECS_PER_DAY (SECS_PER_HOUR * 24L) #define SECS_PER_DAY (SECS_PER_HOUR * 24L)
namespace umodular { namespace clock { namespace umodular { namespace clock {
enum {
PAUSED = 0,
STARTING,
STARTED
} state;
enum {
INTERNAL_CLOCK = 0,
EXTERNAL_CLOCK
} mode;
class uClockClass { class uClockClass {
public: private:
void (*onClock96PPQNCallback)(uint32_t * tick); void (*onClock96PPQNCallback)(uint32_t * tick);
void (*onClock32PPQNCallback)(uint32_t * tick); void (*onClock32PPQNCallback)(uint32_t * tick);
@ -62,17 +75,11 @@ class uClockClass {
uint16_t pll_x; uint16_t pll_x;
uint16_t tempo; uint16_t tempo;
uint32_t start_timer; uint32_t start_timer;
uint8_t mode;
enum { public:
PAUSED = 0,
STARTING,
STARTED
} state;
enum { uint8_t state;
INTERNAL_CLOCK = 0,
EXTERNAL_CLOCK
} mode;
uClockClass(); uClockClass();
@ -107,11 +114,12 @@ class uClockClass {
void setTempo(uint16_t tempo); void setTempo(uint16_t tempo);
uint16_t getTempo(); uint16_t getTempo();
// External timming control // external timming control
void setMode(uint8_t tempo_mode); void setMode(uint8_t tempo_mode);
uint8_t getMode(); uint8_t getMode();
void clockMe(); void clockMe();
// todo!
void shuffle(); void shuffle();
void tap(); void tap();

Loading…
Cancel
Save