tablestream

streaming playback of a mono .wav file from sdcard (testing)
Author: Johannes Taelman
License: BSD
Github: sss/wave/tablestream.axo

Inlets

int32 sample

bool32.rising trigger

charptr32 file name

Outlets

bool32 ended

Attributes

combo size

combo samples

combo init

combo fade

Displays

bool32 load

int32.label length

Declaration
WORKING_AREA(waThreadSD, 800);
sdReadFilePingpong *stream;
int starttrig;
int stoptrig;
int cnt;
bool loop;
bool end;
int32_t size;
static const uint32_t LENGTHPOW = (attr_size);
static const uint32_t LENGTH = (1 << attr_size);
static const uint32_t LENGTHMASK = ((1 << attr_size) - 1);
static const uint32_t BITS = 16;
static const uint32_t GAIN = 12;
int16_t *array;
static const int32_t SAMPLES = 1 << attr_samples;
int32_t sample;
int sm;
bool em, load;
int32_t *END;
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;
cnt = LENGTH;
stream->pThreadSD = chThdCreateStatic(waThreadSD, sizeof(waThreadSD), HIGHPRIO,
                                      ThreadSD, (void *)stream);

static int16_t _array[LENGTH * SAMPLES] __attribute__((section(".sdram")));
array = &_array[0];
static int32_t _END[SAMPLES] __attribute__((section(".sdram")));
END = &_END[0];
{
  int i;
  if (attr_init > 0) {
    for (i = 0; i < (LENGTH * SAMPLES); i++)
      array[i] = 0;
  }
}
em = 0;
Control Rate
int32_t i;
bool start = inlet_load;
sample = inlet_sample;
sm = sample = sample & (SAMPLES - 1);
sample = sample * LENGTH;
if ((start > 0) && !starttrig) {

  sdOpenStream(stream, inlet_filename);
  sdSeekStream(stream, 0);
  starttrig = 1;
  cnt = 0;
} else if ((!(start > 0)) && starttrig) {
  starttrig = 0;
}

int16_t *p = 0;
//  int16_t *q = 0;
p = sdReadStream(stream);
if (p) {
  em = 0;
  load = 1;
  for (i = 0; i < BUFSIZE; i++) {
    if (cnt < LENGTH) {
      array[cnt + sample] = (*(p++));
      cnt += 1;
    }
    // else{em=0;}
  }

} else {
  if (!em) {
    if (attr_fade > 0) {
      END[sm] = cnt;
      disp_length = cnt;
      for (int i = 0; i < 16; i++) {
        array[i] = ___SMMUL(array[i], i << 27) << 1;
      }
      for (int i = 0; i < 129; i++) {
        int k = __USAT(i - 129 + cnt, LENGTHPOW) + sample;
        array[k] = ___SMMUL(array[k], (128 - i) << 25) << 1;
      }
      for (int i = cnt; i < LENGTH; i++) {
        array[i + sample] = 0;
      }
    }
    em = 1;
  }
  load = 0;
}
disp_load = load;

outlet_ended = !load;
Dispose
sdStopStreamer(stream);

Privacy

© 2024 Zrna Research