table2

A combination of 3 objects: table/alloc 16b sdram table/load string/indexed IMPORTANT: Se help file about how to connect!
Author: Johannes Taelman
License: BSD
Github: jaffa/table/table2.axo

Inlets

int32 index

charptr32 file name

bool32.rising trigger

Outlets

charptr32 out

Attributes

combo size

text init

objref table

table prefix

table suffix

Declaration
// Table allocation
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;

// String/index
int ntrig;
char c[64];
int offset;
int pval;
Init
// Table allocation
static int16_t _array[attr_poly][LENGTH] __attribute__((section(".sdram")));
array = &_array[parent->polyIndex][0];
{
  int i;
  for (i = 0; i < LENGTH; i++)
    array[i] = 0;
}
attr_init

    // String/index
    ntrig = 0;
strcpy(&c[0], "attr_prefix000attr_suffix");
offset = strlen("attr_prefix");
pval = 0;
Control Rate
if ((inlet_trig > 0) && !ntrig) {
  ntrig = 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(*attr_table.array) * attr_table.LENGTH;
  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 *)(&attr_table.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_table.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;

if (inlet_index != pval) {
  pval = inlet_index;
  int i = inlet_index;
  int i0 = i / 10;
  c[offset + 2] = '0' + i - 10 * i0;
  i = i0;
  i0 = i / 10;
  c[offset + 1] = '0' + i - 10 * i0;
  i = i0;
  i0 = i / 10;
  c[offset + 0] = '0' + i - 10 * i0;
}
outlet_out = &c[0];

Privacy

© 2024 Zrna Research