sinseq

Author: Smashed Transistors
License: LGPL
Github: tiar/noise/sinseq1.axo

Inlets

frac32.bipolar pitch

Outlets

frac32buffer.bipolar out

Parameters

frac32.s.map.pitch pitch

Declaration
int32_t seq[4][5] = {
    {1, 8, 2, 4, 8}, {1, 4, 2, 8, 8}, {1, 8, 2, 4, 8}, {1, 2, 4, 8, 8}};
int32_t rat[4][5];
uint8_t cseq = 0;
uint8_t nseq = 0;
int32_t dp0, dp;
uint32_t p = 0;
uint32_t r = 137;
Init
for (int i = 0; i < 4; i++) {
  for (int j = 0; j < 5; j++) {
    rat[i][j] = arm::float_to_q(seq[i][j] / (float)seq[i][(j - 1 + 5) % 5], 25);
  }
}
Control Rate
MTOFEXTENDED(param_pitch + inlet_pitch + 12, dp0);
dp = seq[nseq][cseq] * dp0;
Audio Rate
p += dp;
if (p < dp) {
  cseq++;
  if (cseq >= 5) {
    cseq = 0;
    // random swap
    r = r * 69069 + 1;
    // odds : 1/2
    if (r > 0) {
      nseq = (r >> 25) & 3;
    }
  }
  dp = seq[nseq][cseq] * dp0;
  // corrects the phase as if dp was changed when it crossed zero
  p = ___SMMUL(p, rat[nseq][cseq]) << 7;
}

outlet_out = sine2t[(p + (1 << 30UL)) >> (32 - 12)] >> (31 - 27);

Privacy

© 2024 Zrna Research