autoFit

allocate 16bit table in SDRAM memory, -128.00 .. 127.99
Author: Johannes Taelman
License: BSD
Github: sss/patt/autoFit.axo

Inlets

int32 count

int32 max

Outlets

frac32 out

Parameters

frac32.s.map rnd

frac32.u.map CV

frac32.s.map.lfopitch rate

int32 steps

int32 wait

Attributes

combo size

Declaration
static const uint32_t LENGTHPOW = (attr_size);
static const uint32_t LENGTH = (1 << attr_size);
static const uint32_t LENGTHMASK = ((1 << attr_size) - 1);
int16_t *array;
int32_t phase;
int ctrig;
int rtrig;
int ftrig;
int rec;
uint32_t cnt1;
uint32_t cnt2;
int32_t pv;
int32_t pc;
int32_t pt;
int32_t A[4];
int32_t TMP;
Init
static int16_t _array[LENGTH] __attribute__((section(".sdram")));
array = &_array[0];
Control Rate
int32_t rate;
MTOFEXTENDED(param_rate, rate)
phase += rate;

if (!(pv == param_CV)) {
  rec = 1;
  cnt2 = 0;
}
pv = param_CV;

if ((rec > 0) && !ftrig) {
  ftrig = 1;
  cnt1 = 0;
} else if (rec == 0) {
  ftrig = 0;
}

int Do = ((phase > 0) && rec);
if ((Do) && (!rtrig)) {
  array[cnt1 & LENGTHMASK] = param_CV >> 12;
  cnt1 += 1;
  cnt2 += 1;
  cnt2 = cnt2 > 2000 ? 2000 : cnt2;
  rec = cnt2 > param_wait ? 0 : rec;
  rtrig = 1;

} else if (Do == 0) {
  rtrig = 0;
}

if ((!(pc == inlet_count)) || (!(pt == inlet_max))) {
  int32_t RND = (int32_t)(GenerateRandomNumber());
  int32_t tmp = cnt1 - cnt2;
  RND = ___SMMUL((RND >> 16) * (tmp) >> 14, param_rnd << 1);
  int32_t count = (tmp)*inlet_count / inlet_max * param_steps + RND;
  count = count - count / tmp * tmp;
  TMP = array[count & LENGTHMASK] << 12;
}
outlet_out = TMP;
pc = inlet_count;
pt = inlet_max;

Privacy

© 2024 Zrna Research