tablesaveX

save table to sdcard, added a "save ready" trigger. Useful if you need to halt another load/save until this one has finished. Also has a length multiplier in case you need to store wavetables that use "LENGTH" as the basis for a single cycle waveform, but save multiple samples/versions to a bigger table.
Author: Remco van der Most
License: BSD
Github: sss/table/tablesaveX.axo

Inlets

charptr32 file name

bool32.rising trigger

Outlets

bool32 ready

Attributes

spinner multiplies the length of the table. Some of my wavetable objects use "LENGTH" as the standard of a 1 cycle waveform, thus the entire table is LENGTH * SAMPLES * ... (check the table initiation to see the multiplication of the LENGTH)

objref refers to the module containing the table

Declaration
int ntrig;
Init
ntrig = 0;
Control Rate
outlet_ready = 0;
if ((inlet_trig > 0) && !ntrig) {
  ntrig = 1;
  FIL FileObject;
  FRESULT err;
  UINT bytes_written;
  codec_clearbuffer();
  err = f_open(&FileObject, inlet_filename, FA_WRITE | FA_CREATE_ALWAYS);
  if (err != FR_OK) {
    report_fatfs_error(err, inlet_filename);
    return;
  }
  int rem_sz = sizeof(*attr_table.array) * (attr_table.LENGTH * attr_sizemult);
  int offset = 0;
  while (rem_sz > 0) {
    if (rem_sz > sizeof(fbuff)) {
      memcpy((char *)fbuff, (char *)(&attr_table.array[0]) + offset,
             sizeof(fbuff));
      err = f_write(&FileObject, fbuff, sizeof(fbuff), &bytes_written);
      rem_sz -= sizeof(fbuff);
      offset += sizeof(fbuff);
    } else {
      memcpy((char *)fbuff, (char *)(&attr_table.array[0]) + offset, rem_sz);
      err = f_write(&FileObject, fbuff, rem_sz, &bytes_written);
      rem_sz = 0;
    }
  }
  if (err != FR_OK)
    report_fatfs_error(err, inlet_filename);
  err = f_close(&FileObject);
  if (err != FR_OK)
    report_fatfs_error(err, inlet_filename);
  outlet_ready = 1;
} else if (!(inlet_trig > 0))
  ntrig = 0;

Privacy

© 2024 Zrna Research