tload

load table from sdcard
Author: Johannes Taelman
License: BSD
Github: rbrt/testing/tload.axo

Inlets

bool32.rising trigger

int32 start

int32 length

int32 slot

charptr32 file name

Outlets

None

Attributes

objref wave

objref data

Declaration
int ntrig;
Init
ntrig = 0;
Control Rate
if ((inlet_trig > 0) && !ntrig) {
  ntrig = 1;
  FIL FileObject;
  FRESULT err;
  UINT bytes_read;
  codec_clearbuffer();
  err = f_open(&FileObject, inlet_filename, FA_READ | FA_OPEN_EXISTING);
  if (err != FR_OK) {
    report_fatfs_error(err, inlet_filename);
    return;
  }
  attr_data.array[(inlet_slot << 2)] = inlet_start;
  attr_data.array[(inlet_slot << 2) + 1] = inlet_start + inlet_length;
  attr_data.array[(inlet_slot << 2) + 3] = 1;
  int rem_sz = inlet_length << 2;
  int offset = inlet_start << 2;
  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 *)(&attr_wave.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 *)(&attr_wave.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 (!(inlet_trig > 0))
  ntrig = 0;

Privacy

© 2024 Zrna Research