waveformLoader

allocate 32bit table in SDRAM memory for loading tables created with the waveformGenerator, guitarTable or other wavetable-generating modules.
Author: Remco van der Most
License: BSD
Github: sss/osc/waveformLoader.axo

Inlets

charptr32 filename

bool32 load

Outlets

None

Parameters

bool32.mom load

Attributes

combo size

combo wavesize

Declaration
static const uint32_t SIZEPOW = attr_size;
static const uint32_t SIZE = 1 << attr_size;
static const uint32_t SIZEMASK = (1 << attr_size) - 1;
static const uint32_t LENGTHPOW = attr_wavesize;
static const uint32_t LENGTH = 1 << attr_wavesize;
static const uint32_t LENGTHMASK = (1 << attr_wavesize) - 1;
int32_t *array;
int32_t Waveforms = 127;
int32_t presets = 127;
int ltrig;
Init
static int32_t _array[SIZE] __attribute__((section(".sdram")));
array = &_array[0];
Control Rate
int load = param_load + inlet_load;
if ((load > 0) && !ltrig) {
  ltrig = 1;
  FIL FileObject;
  FRESULT err;
  UINT bytes_read;
  err = f_open(&FileObject, inlet_filename, FA_READ | FA_OPEN_EXISTING);
  if (err != FR_OK) {
    report_fatfs_error(err, inlet_filename);
    return;
  }
  int rem_sz = sizeof(*array) * SIZE;
  int offset = 0;
  while (rem_sz > 0) {
    if (rem_sz > sizeof(fbuff)) {
      err = f_read(&FileObject, fbuff, sizeof(fbuff), &bytes_read);
      if (bytes_read == 0)
        break;
      memcpy((char *)(&array[0]) + offset, (char *)fbuff, bytes_read);
      rem_sz -= bytes_read;
      offset += bytes_read;
    } else {
      err = f_read(&FileObject, fbuff, rem_sz, &bytes_read);
      memcpy((char *)(&array[0]) + offset, (char *)fbuff, bytes_read);
      rem_sz = 0;
    }
  }
  if (err != FR_OK) {
    report_fatfs_error(err, inlet_filename);
    return;
  };
  err = f_close(&FileObject);
  if (err != FR_OK) {
    report_fatfs_error(err, inlet_filename);
    return;
  };
} else if (!(load > 0))
  ltrig = 0;

Privacy

© 2024 Zrna Research