tri

triangle oscillator Bandwith limited
Author: Johannes Taelman
License: BSD
Github: osc/tri.axo

Inlets

frac32.bipolar pitch

Outlets

frac32buffer.bipolar triangle wave, anti-aliased

Parameters

frac32.s.map.pitch pitch

Declaration
uint32_t osc_p;
static const int blepvoices = 4;
const int16_t *oscp[blepvoices];
int16_t amp[blepvoices];
uint32_t nextvoice;
Init
int j;
for (j = 0; j < blepvoices; j++) {
  oscp[j] = &blt[BLEPSIZE - 1];
  amp[j] = 0;
}
nextvoice = 0;
Control Rate
uint32_t freq;
MTOFEXTENDED(param_pitch + inlet_pitch, freq);
int j;
const int16_t *lastblep = &blt[BLEPSIZE - 1];
for (j = 0; j < BUFSIZE; j++) {
  int i;
  uint32_t p;
  p = osc_p;
  int32_t p3 = p - 2 * freq;
  int32_t tri;
  if (p3 > 0) {
    tri = ((1 << 30) - (p3)) >> 4;
  } else {
    tri = (p3 + (1 << 30)) >> 4;
  }
  osc_p = p + freq;
  if ((((int32_t)osc_p) > 0) ^ (((int32_t)p) > 0)) { // dispatch
    if ((freq >> 6) > 0) {
      nextvoice = (nextvoice + 1) & (blepvoices - 1);
      int32_t x = (osc_p & 0x7FFFFFFF) / (((uint32_t)freq) >> 6);
      oscp[nextvoice] = &blt[x];
      amp[nextvoice] = (((int32_t)osc_p) < 0) ? freq >> 16 : -(freq >> 16);
    }
  }
  int32_t sum = 0;
  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_wave[j] = tri + (sum >> 3);
}

Privacy

© 2024 Zrna Research