fplay_s

streaming playback of a stereo .wav file from sdcard (testing)
Author: Johannes Taelman
License: BSD
Github: rbrt/testing/fplay_s.axo

Inlets

bool32.rising trigger

bool32.rising trigger

frac32 position

Outlets

bool32.pulse end of stream

frac32buffer output left

frac32buffer output right

Attributes

file fn

Declaration
WORKING_AREA(waThreadSD, 800);
sdReadFilePingpong *stream;
int starttrig;
int stoptrig;
char c[64];
bool play;
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;
starttrig = 0;
stoptrig = 0;
strcpy(&c[0], "attr_fn");
stream->pThreadSD = chThdCreateStatic(waThreadSD, sizeof(waThreadSD), HIGHPRIO,
                                      ThreadSD, (void *)stream);
Control Rate
int32_t i;
outlet_end = 0;
if ((inlet_start > 0) && !starttrig) {
  sdOpenStream(stream, &c[0]);
  sdSeekStream(stream, ((inlet_pos) >> 4) << 2);
  starttrig = 1;
  play = 1;
} else if ((!(inlet_start > 0)) && starttrig) {
  starttrig = 0;
}
if ((inlet_stop > 0) && !stoptrig) {
  sdCloseStream(stream);
  stoptrig = 1;
  play = 0;
} else if ((!(inlet_stop > 0)) && stoptrig) {
  stoptrig = 0;
}
int16_t *p = 0;
int16_t *q = 0;
p = sdReadStream(stream);
q = sdReadStream(stream);
if (p && q) {
  for (i = 0; i < BUFSIZE / 2; i++) {
    outlet_outl[i] = (*(p++)) << 10;
    outlet_outr[i] = (*(p++)) << 10;
  }
  for (; i < BUFSIZE; i++) {
    outlet_outl[i] = (*(q++)) << 10;
    outlet_outr[i] = (*(q++)) << 10;
  }
} else {
  for (i = 0; i < BUFSIZE; i++)
    outlet_outl[i] = outlet_outr[i] = 0;
  if (play)
    outlet_end = 1;
}
Dispose
sdStopStreamer(stream);

Privacy

© 2024 Zrna Research