rectifier full

full-wave rectifier distortion, bandlimited
Author: Johannes Taelman
License: BSD
Github: dist/rectifier full.axo

Inlets

frac32buffer audio input

Outlets

frac32buffer.bipolar audio output

Declaration
static const int blepvoices = 8;
const int16_t *oscp[blepvoices];
int16_t amp[blepvoices];
uint32_t nextvoice;
int32_t in1;
int32_t in2;
int32_t in3;
Init
int j;
for (j = 0; j < blepvoices; j++)
  oscp[j] = &blt[BLEPSIZE - 1];
nextvoice = 0;
in1 = 0;
in2 = 0;
in3 = 0;
Control Rate
int j;
const int16_t *lastblep = &blt[BLEPSIZE - 1];
for (j = 0; j < BUFSIZE; j++) {
  int i;
  int in0 = inlet_in[j] >> 2;
  int32_t sum = 0;
  if ((in0 > 0) && (in1 < 0)) { // dispatch
                                // rising
    nextvoice = (nextvoice + 1) & (blepvoices - 1);
    int32_t x = ((in0 << 6) / (in0 - in1));
    oscp[nextvoice] = &blt[x];
    amp[nextvoice] = (in0 - in1) >> 16;
  } else if ((in0 < 0) && (in1 > 0)) { // dispatch
                                       // falling
    nextvoice = (nextvoice + 1) & (blepvoices - 1);
    int32_t x = ((in0 << 6) / (in0 - in1));
    oscp[nextvoice] = &blt[x];
    amp[nextvoice] = (in1 - in0) >> 16;
  }
  sum = (in3 > 0) ? in3 >> 1 : -in3 >> 1;
  in3 = in2;
  in2 = in1;
  in1 = in0;
  for (i = 0; i < blepvoices; i++) { // sample
    const int16_t *t = oscp[i];
    sum += (*t) * amp[i];
    t += 64;
    if (t >= lastblep)
      t = lastblep;
    oscp[i] = t;
  }
  outlet_out[j] = sum << 2;
}

Privacy

© 2024 Zrna Research