scalebank3

To be able to use this module, first load the "scaleGenerator" to create a table on your SDcard. This module then automatically loads this table from your SDcard. I found that in big projects, this scaling-array took too many memory. This way the array isn't stored as part of the code, leaving more memory for adding modules.
Author: Remco van der Most
License: GPL
Github: sss/harmony/scalebank3.axo

Inlets

None

Outlets

None

Declaration
static const uint32_t LENGTH = 552;
int8_t *note;
static const uint32_t tLENGTH = 1644;
int32_t *TMPR;
int i;

bool DO = 1;
Init
static int8_t _note[LENGTH] __attribute__((section(".sdram")));
note = &_note[0];
static int32_t _TMPR[tLENGTH] __attribute__((section(".sdram")));
TMPR = &_TMPR[0];

FIL FileObject;
FRESULT err;
UINT bytes_read;
err = f_open(&FileObject, "0:/scalebank.tab", FA_READ | FA_OPEN_EXISTING);
if (err != FR_OK) {
  report_fatfs_error(err, "0:/scalebank.tab");
  return;
}
int rem_sz = sizeof(*note) * 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 *)(&note[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 *)(&note[0]) + offset, (char *)fbuff, bytes_read);
    rem_sz = 0;
  }
}
if (err != FR_OK) {
  report_fatfs_error(err, "0:/scalebank.tab");
  return;
};
err = f_close(&FileObject);
if (err != FR_OK) {
  report_fatfs_error(err, "0:/scalebank.tab");
  return;
};

if (DO == 1) {

  FIL FileObject;
  FRESULT err;
  UINT bytes_read;
  err = f_open(&FileObject, "0:/tempbank.tab", FA_READ | FA_OPEN_EXISTING);
  if (err != FR_OK) {
    report_fatfs_error(err, "0:/tempbank.tab");
    return;
  }
  int rem_sz = sizeof(*TMPR) * tLENGTH;
  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 *)(&TMPR[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 *)(&TMPR[0]) + offset, (char *)fbuff, bytes_read);
      rem_sz = 0;
    }
  }
  if (err != FR_OK) {
    report_fatfs_error(err, "0:/tempbank.tab");
    return;
  };
  err = f_close(&FileObject);
  if (err != FR_OK) {
    report_fatfs_error(err, "0:/tempbank.tab");
    return;
  };
}

Privacy

© 2024 Zrna Research