flashplay

Substitute for the wave/flashplay object, those samples are removed from flash. This object auto-uploads the samples to sdcard (only if missing), and then reads the samples into sdram at startup. Single-shot playback of a sample table in flash, without transposition.
Author: Johannes Taelman
License: BSD
Github: wave/flashplay.axo

Inlets

bool32.rising trigger

Outlets

frac32buffer wave

Attributes

combo sample

Declaration
const static int max_length = 32 * 1024;
int16_t *sample;
uint32_t _pos = max_length;
int ntrig = 0;
Init
static int16_t _sample[max_length] __attribute__((section(".sdram")));
sample = &_sample[0];
FIL FileObject;
FRESULT err;
UINT bytes_read;
const char fn[] = "/shared/808/attr_sample.raw";
err = f_open(&FileObject, fn, FA_READ | FA_OPEN_EXISTING);
if (err != FR_OK) {
  LogTextMessage("Open failed: %s", fn);
  // clear from file end to array end
  int i;
  for (i = 0; i < max_length; i++) {
    sample[i] = 0;
  }
  return;
}
err = f_read(&FileObject, (char *)sample, sizeof(_sample), &bytes_read);
if (err != FR_OK) {
  LogTextMessage("Read failed\n");
  return;
}
err = f_close(&FileObject);
if (err != FR_OK) {
  LogTextMessage("Close failed\n");
  return;
}

int i = bytes_read / 2; // 16 bit per sample
// clear from file end to array end
for (; i < max_length; i++) {
  sample[i] = 0;
}
Control Rate
if ((inlet_trig > 0) && !ntrig) {
  _pos = 0;
  ntrig = 1;
}
if (!(inlet_trig > 0))
  ntrig = 0;
int32_t i;
if (_pos < max_length) {
  for (i = 0; i < BUFSIZE; i++)
    (outlet_out)[i] = (sample[_pos++]) << 12;
} else {
  for (i = 0; i < BUFSIZE; i++)
    (outlet_out)[i] = 0;
}

Privacy

© 2024 Zrna Research