splicer

Audio splicer module
Author: Remco van der Most
License: BSD
Github: sss/delay/splicer.axo

Inlets

frac32buffer wave input

frac32 duck

bool32 rec

bool32 dub

bool32 selfRec

bool32 selfDub

bool32 sameRec

Outlets

frac32buffer out

frac32buffer fade

int32 splicerec

Parameters

int32 splice

frac32.u.map genesize

frac32.u.map offset

frac32.u.map offstep

frac32.u.map steps

frac32.s.map rate

bool32.tgl dir

bool32.tgl alternate

Attributes

combo size

Displays

bool32 rec

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;
uint32_t writepos;
int32_t tmp_r;
int32_t Read(uint32_t TIME, uint32_t POS) {
  TIME = TIME;
  uint32_t tmp_di = (TIME >> (27 - LENGTHPOW)) + POS;
  uint32_t tmp_w1 = (POS << (24)) + (TIME << (LENGTHPOW + 3)) & 0x3FFFFFFF;
  int32_t tmp_a1 = array[tmp_di & LENGTHMASK] << 16;
  int32_t tmp_a2 = array[(tmp_di + 1) & LENGTHMASK] << 16;
  return tmp_r =
             ___SMMUL(tmp_a1, tmp_w1) + ___SMMUL(tmp_a2, (1 << 30) - tmp_w1);
};
int32_t OUT;

int32_t OFS;
bool rtrig;
bool REC;
bool Rtrig;
uint32_t splice[64];
uint32_t cnt;
uint32_t readpos;
int Cnt;
int32_t fadeRec;
int32_t fadeDub;
int i;
uint32_t LFO;
int dir;
Init
static int16_t _array[attr_poly][1 << attr_size]
    __attribute__((section(".sdram")));
array = &_array[parent->polyIndex][0];
int i;
writepos = 0;
readpos = 0;
for (i = 0; i < LENGTH; i++)
  array[i] = 0;
REC = 0;
cnt = 0;
for (i = 0; i < 64; i++) {
  splice[i] = LENGTHMASK;
}
Control Rate
if ((inlet_rec + inlet_selfRec > 0) && !Rtrig) {
  if (cnt == 0) {
    splice[0] = 0;
  }
  Rtrig = 1;
  cnt += 1;
  cnt = cnt > 63 ? 1 : cnt;
} else if ((!(inlet_rec + inlet_selfRec > 0)) && Rtrig) {
  Rtrig = 0;
  splice[cnt] = writepos;
  // for(i=0;i<1012;i++){
  //	array[splice[cnt]-i]=array[splice[cnt]-i]*i>>10;
  //}
}

int32_t duck = (1 << 27) - inlet_duck;
int32_t size = (splice[param_splice + 1] - splice[param_splice]);
int32_t genesize = size;
int32_t offset = ___SMMUL((1 << 27) - param_genesize << 3, genesize << 2);
genesize = genesize - offset;
outlet_splicerec = cnt;
int steps = param_steps >> 20;

int32_t R1;
MTOFEXTENDED(0, R1)
int32_t R2;
MTOFEXTENDED((param_rate >> 21) << 21, R2)
float32_t ratio = (float32_t)R2 / R1;
Audio Rate
fadeRec = __USAT(fadeRec + (inlet_rec + inlet_selfRec > 0 ? 1 : -1), 10);
readpos += 1;

if (readpos > (genesize / ratio)) {
  if (param_alternate > 0) {
    dir = dir > 0 ? -1 : 1;
  }
  readpos = 0;
  Cnt += 1;
  OFS = (OFS + ___SMMUL(offset << 2, param_offstep << 3)) & ((1 << 27) - 1);
  if (Cnt >= steps) {
    dir = param_dir > 0 ? 1 : -1;
    Cnt = 0;
    OFS = ___SMMUL(offset << 2, param_offset << 3);
  }
}
uint32_t RP = readpos * ratio;
uint32_t tR = OFS + RP * dir;
tR = tR - tR / size * size;

int32_t TMP;
int32_t out1 = Read(0, splice[param_splice] + tR);
tR -= dir * 2;
tR = tR - tR / size * size;
TMP = out1;

fadeDub = (1 << 30) - (__USAT((genesize / 100 + 1) - RP, 30) +
                       __USAT(RP - genesize + (genesize / 100 + 1), 30)) *
                          ((float32_t)(1 << 30) / (genesize / 100 + 1));
outlet_fade = fadeDub >> 1;

OUT = (___SMMUL(TMP, fadeDub) << 2);
outlet_out = OUT;
if (inlet_rec > 0) {
  writepos = (writepos + 1) & LENGTHMASK;
  array[writepos] = __SSAT(___SMMUL(inlet_in, fadeRec << 7), 16);
}

if (inlet_selfRec > 0) {
  writepos = (writepos + 1) & LENGTHMASK;
  array[writepos] = __SSAT(___SMMUL(OUT, fadeRec << 7), 16);
}

if (inlet_dub > 0) {
  array[(splice[param_splice] + tR) & LENGTHMASK] =
      __SSAT((int32_t)(___SMMUL(inlet_in, fadeDub) >> 11) +
                 ___SMMUL(array[splice[param_splice] + tR] << 3, duck << 2),
             16);
}

if (inlet_selfDub > 0) {
  array[(splice[param_splice] + tR) & LENGTHMASK] =
      __SSAT((int32_t)(___SMMUL(OUT, fadeDub) >> 11) +
                     array[splice[param_splice] + tR] >>
                 1,
             16);
}

if (inlet_sameRec > 0) {
  array[(splice[param_splice] + tR) & LENGTHMASK] =
      __SSAT((int32_t)(___SMMUL(inlet_in, fadeDub) >> 11), 16);
}

Privacy

© 2024 Zrna Research