Skip to content

Commit

Permalink
Working on #5 clock input is harder than i thought!
Browse files Browse the repository at this point in the history
  • Loading branch information
wraybowling committed Jun 7, 2020
1 parent 0e61724 commit ccd5910
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 28 deletions.
112 changes: 91 additions & 21 deletions tri_ger_plus/time.ino
Original file line number Diff line number Diff line change
@@ -1,32 +1,102 @@
/**
* collect the knob value
* then slice the range in half
* then normalize that half range so that 512 is in the center
* split the half range into five roughly equal parts 100 units apart
* convert the value into an integer ranging from -5 to +5
* use the sign of the integer to determine if we multiply or divide
* take the absolute value to use a lookup. range from 0-4 will be 2^x
* 5 will equal 24
* therefore zero will map to -5 which will divide a 24ppqn signal to quarter notes
* therefore 1023 will map to +5 which will accept quarter notes and output 24ppqn
* therefore 512 will map to 2^0=1 which will neither multiply nor divide
*
* Next an internal clock is maintained.
* Each loop, we can recalculate div/mult based on the knob
* If a new input signal comes in, recalculate period
* Time since last pulse sent > period * multiplier = new pulse
*
* count up each frame. then modulo over multiplier * period
* when the new frame is lower than the previous, then we have a new pulse
*/

bool prevClockWasHigh = false;
#include "peaks_pattern_predictor.h"

uint32_t prevClockMillis;
class Clock {
PatternPredictor<32, 8> predictor;
byte sync_debounce = 0;
uint32_t millis_prev_sync = 0;
uint32_t sync_period;
uint32_t sync_counter;
uint32_t prev_modulo;
uint32_t clock_skips;
uint8_t clock_counter;
// uint32_t clock_slip;
// byte clock_debounce = 0;

// uint32_t millis_next_clock_on;
// bool clock_is_on;
uint32_t millis_next_clock_off;

constructor(){
predictor.Init();
}

void clockIn(int sync_voltage){
this.sync_debounce = this.sync_debounce << 1 + sync_voltage > 900;
this.syncCounter++;
if(sync_debounce == 1) {
const uint32_t NEW_PERIOD = millis() - this.millis_prev_sync;
this.sync_period = predictor.Predict(NEW_PERIOD);
this.syncCounter = 0;
}
}

uint32_t periodPrediction;
bool clockOut(){
const int MULTIPLIER_STEP = (getMux(clock_div_knob) * 10 + 512) / 1023 - 5;
const int MULTIPLIER = abs(MULTIPLIER_STEP) == 5
? 24
: 1 << abs(MULTIPLIER_STEP);

uint32_t nextClockOffAtMillis;
uint32_t prevClockOffAtMillis;


void doTimeStuff() {

// collect the knob value
// then slice the range in half
// then normalize that half range so that 512 is in the center
// split the half range into five roughly equal parts 100 units apart
// convert the value into an integer ranging from -5 to +5
// use the sign of the integer to determine if we multiply or divide
// take the absolute value to use a lookup. range from 0-4 will be 2^x
// 5 will equal 24
// therefore zero will map to -5 which will divide a 24ppqn signal to quarter notes
// therefore 1023 will map to +5 which will accept quarter notes and output 24ppqn
// therefore 512 will map to 2^0=1 which will neither multiply nor divide

if(MULTIPLIER_STEP <= 0) { // less knob = multiply period (slower)
//= this.sync_period * MULTIPLIER;
// actually just skip

if(something) {
this.clock_skips++;
if(this.clock_skips >= MULTIPLIER) {
this.clock_skips = 0;

}
}



} else { // divide period (faster)
const NEXT_MODULO =
//prev_modulo


//millis_next_clock_on = now + periodPrediction / multiplier;
}
millis_next_clock_off = millis_next_clock_on + 25;

}

void reTrigger() {
this.skips = 0;
}
}


void doTimeStuff() {

// y = floor((x10+512)/1023-5)+5
const int multiplier_step = (getMux(clock_div_knob) * 10 + 512) / 1023 - 5;
const int multiplier = abs(multiplier_step) == 5
? 24
: 1 << abs(multiplier_step);



// int multiplier = getMux(clock_div_knob) * 24 / 512 - 24;
Expand Down
8 changes: 1 addition & 7 deletions tri_ger_plus/tri_ger_plus.ino
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,12 @@ c pins: digital 16-23 analog 0-7
#define record_button B110 // 6
#define record_button_master B111 // 7

/*
* TODO section
* these things have not been found yet
*/

#include "peaks_pattern_predictor.h"

PatternPredictor<32, 8> bpm;


void setup() {
bpm.Init();


pinMode(clock_out, OUTPUT);

Expand Down

0 comments on commit ccd5910

Please sign in to comment.