streamplayB

plays audio from the tablestream module
Author: Remco van der Most
License: BSD
Github: sss/wave/streamplayB.axo

Inlets

bool32.rising start playback

frac32 velocity

frac32 pitch

bool32 direction

int32 sample

Outlets

frac32buffer wave

Attributes

objref table

Declaration
int pstart;

int pos;
int32_t phs;
int32_t prv;
int32_t stp;
int32_t vi30 = (1 << 30) - 1;
int32_t pv1, pv2;
int32_t hp;
int32_t vel;
Init
pos = 0;
pstart = 0;
Control Rate
bool dir = inlet_direction;
int32_t sample = inlet_sample & (attr_table.SAMPLES - 1);
int sm = sample;
sample *= attr_table.LENGTH;
int32_t pitch;
int32_t base;
MTOFEXTENDED(0, base)
MTOFEXTENDED(inlet_pitch, pitch)
pitch -= base;
if ((inlet_trig) && !pstart) {
  pstart = 1;
  vel = __USAT(inlet_velocity, 27) << 4;
  int32_t asat = 0;
  if (dir > 0) {
    asat = (1 << 26) - asat - 4;
  }

  pos = (dir > 0 ? (attr_table.END[sm] & attr_table.LENGTHMASK) : 0);
} else if (!(inlet_trig)) {
  pstart = 0;
}
Audio Rate
if ((pos < attr_table.LENGTH) && (pos >= 0)) {

  phs += pitch;
  int32_t p1 = phs & vi30;
  stp = p1 >> 25;
  p1 = p1 - (stp << 25) << 5;

  if (!(stp == prv)) {
    if (pitch > 0) {
      if (dir > 0) {
        (pos--);
      } else {
        (pos++);
      }
    } else {
      if (dir > 0) {
        (pos++);
      } else {
        (pos--);
      }
    }
  }

  if (dir > 0) {
    (pos--);
  } else {
    (pos++);
  }

  int32_t tmp1 = attr_table.array[__USAT(pos, attr_table.LENGTHPOW) + sample]
                 << attr_table.GAIN;
  int32_t tmp2 =
      attr_table.array[__USAT(pos + 1, attr_table.LENGTHPOW) + sample]
      << attr_table.GAIN;
  tmp1 = tmp1 + (___SMMUL(tmp2 - tmp1, p1) << 2);

  outlet_wave = ___SMMUL(tmp1, vel) << 1;

  prv = stp;

} else {
  outlet_wave = 0;
}

Privacy

© 2024 Zrna Research