samplehold

high quality audio rate sample and hold using blit synthesis (bandwidth limited)
Author: Johannes Taelman
License: BSD
Github: dist/samplehold.axo

Inlets

frac32buffer level input

frac32buffer trigger input, triggers on rising zero-crossing

Outlets

frac32buffer.bipolar audio output

Declaration
static const int blepvoices = 8;
int16_t *oscp[blepvoices];
int32_t vgain[blepvoices];
uint32_t nextvoice;
int32_t i0;
int32_t in0;
int32_t acc;
Init
int j;
for (j = 0; j < blepvoices; j++)
  oscp[j] = &blept[BLEPSIZE - 1];
nextvoice = 0;
i0 = 0;
in0 = 0;
acc = 0;
Control Rate
int j;
int16_t *lastblep = &blept[BLEPSIZE - 1];
for (j = 0; j < BUFSIZE; j++) {
  int i;
  int i1 = inlet_trig[j] >> 2;
  if ((i1 > 0) && !(i0 > 0)) { // dispatch
    nextvoice = (nextvoice + 1) & (blepvoices - 1);
    int32_t x = (i1 << 6) / (i1 - i0);
    oscp[nextvoice] = &blept[x];
    int32_t val = (((64 - x) * (inlet_in[j] >> 2)) + (x * (in0 >> 2))) >> 6;
    vgain[nextvoice] = (acc - val) << 2;
    acc = val;
  }
  int32_t sum = 0;
  i0 = i1;
  in0 = inlet_in[j];
  for (i = 0; i < blepvoices; i++) { // sample
    int16_t *t = oscp[i];
    sum = ___SMMLA((16384 - (*t)) << 16, vgain[i], sum);
    t += 64;
    if (t >= lastblep) {
      t = lastblep;
      vgain[i] = 0;
    }
    oscp[i] = t;
  }
  outlet_out[j] = (sum + acc) << 1;
}

Privacy

© 2024 Zrna Research