polyplay

A variant on the wave/play streaming playback object for mono 16bit .raw (headerless .wav) files. This version has pitch control and works in poly patches, but is less efficient and more memory hungry. Max 6 instances because of memory restrictions.
Author: Kai Drange
License: BSD
Github: abhoth/wave/polyplay.axo

Inlets

frac32 position

bool32.rising trigger

bool32.rising trigger

charptr32 file name

Outlets

frac32buffer output

bool32.pulse end of stream

Parameters

frac32.u.map Pitch 0.5 to 1.5

Declaration
WORKING_AREA(waThreadSD, 850);
sdReadFilePingpong *stream;
int starttrig;
int stoptrig;
Init
static sdReadFilePingpong s[attr_poly] __attribute__((section(".data")));
// unmap from aliased memory for DMA
stream = (sdReadFilePingpong *)(0x20000000 | (int)&s[parent->polyIndex]);
stream->pingpong = CLOSED;
stream->doSeek = 0;
stream->offset = -1;
stream->rate = 1;
stream->sampleFrac = 0;
starttrig = 0;
stoptrig = 0;
stream->pThreadSD = chThdCreateStatic(waThreadSD, sizeof(waThreadSD), LOWPRIO,
                                      ThreadSD, (void *)stream);
Control Rate
int32_t i;

outlet_end = 0;
if ((inlet_start > 0) && !starttrig) {
  UINT lowres_rate = (param_rate / (float)(1 << 27) + 0.5) * 256;
  stream->rate = lowres_rate / 256.0;
  sdOpenStream(stream, inlet_filename);
  sdSeekStream(stream, ((inlet_pos) >> 4) << 2);
  starttrig = 1;
} else if ((!(inlet_start > 0)) && starttrig) {
  starttrig = 0;
}
if ((inlet_stop > 0) && !stoptrig) {
  sdCloseStream(stream);
  stoptrig = 1;
} else if ((!(inlet_stop > 0)) && stoptrig) {
  stoptrig = 0;
}
int16_t *p = 0;
int16_t *q = 0;
p = sdReadStream(stream);
if (p) {
  for (i = 0; i < BUFSIZE; i++) {
    outlet_out[i] = (*(p++)) << 10;
  }
} else {
  for (i = 0; i < BUFSIZE; i++)
    outlet_out[i] = 0;
  outlet_end = 1;
}
Dispose
sdStopStreamer(stream);

Privacy

© 2024 Zrna Research