streamplay

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

Inlets

int32 sample

bool32 direction

frac32 pitch

frac32.positive start position in table

bool32.rising start playback

bool32.rising stop playback

Outlets

frac32buffer wave

Parameters

frac32.s.map pitch

Attributes

objref table

Declaration
int pstart;
int pstop;
int pos;
int32_t phs;
int32_t prv;
int32_t stp;
int32_t vi30 = (1 << 30) - 1;
Init
pos = 0;
pstart = 0;
pstop = 1;
Control Rate
bool dir = inlet_direction;

int32_t pitch;
int32_t base;
MTOFEXTENDED(0, base)
MTOFEXTENDED(param_pitch + inlet_pitch, pitch)
pitch -= base;
if ((inlet_start > 0) && !pstart) {
  pstart = 1;
  pstop = 0;
  uint32_t asat = __USAT(inlet_pos, 27);
  if (dir) {
    asat = (1 << 27) - asat - 1;
  }
  pos = (asat >> (27 - attr_table.LENGTHPOW));
} else if (!(inlet_start > 0)) {
  pstart = 0;
}
if ((inlet_stop > 0) && !pstop) {
  pstop = 1;
  pstart = 0;
}

int32_t sample = inlet_sample & (attr_table.SAMPLES - 1);
sample *= attr_table.LENGTH;
Audio Rate
if (!pstop) {

  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) {
        (pos++);
      } else {
        (pos--);
      }
    }
    pos -= pos >= attr_table.LENGTH ? 2 : 0;
    pos += pos <= 0 ? 1 : 0;
    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;
    outlet_wave = tmp1 + (___SMMUL(tmp2 - tmp1, p1) << 2);
    prv = stp;
  } else
    outlet_wave = 0;
} else
  outlet_wave = 0;

Privacy

© 2024 Zrna Research