bool32 loop
frac32 position
frac32 size
bool32.rising trigger
bool32.rising trigger
charptr32 file name
bool32.pulse end of stream
frac32buffer output
WORKING_AREA(waThreadSD, 800);
sdReadFilePingpong *stream;
int starttrig;
int stoptrig;
int cnt;
bool loop;
bool end;
int32_t size;
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;
cnt = -1;
stream->pThreadSD = chThdCreateStatic(waThreadSD, sizeof(waThreadSD), HIGHPRIO,
ThreadSD, (void *)stream);
int32_t i;
outlet_end = 0;
bool start = inlet_start && !(cnt == 0);
if (inlet_loop && (cnt == 0)) {
cnt = size;
}
size = inlet_size >> 18;
if ((start > 0) && !starttrig) {
if (inlet_loop) {
cnt = size;
}
sdOpenStream(stream, inlet_filename);
sdSeekStream(stream, ((inlet_pos) >> 10) << 2);
starttrig = 1;
} else if ((!(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;
}
// loop=inlet_loop>0?outlet_end&&!end:0;
// end=outlet_end;
cnt -= cnt >= 0 ? 1 : 0;
sdStopStreamer(stream);