waveformTableCombinor

Combines tables from the waveformGenerator. After creating a big wavetable, the "waveformLoader" module can be used to load the wavetables later on. The waveformGenerator can be used together with the waveformGuitar and waveformRandom modules to create different kinds of waveforms and load them all into a single table. Pressing "get" will get the current wavetable from the waveformGenerator and saves it behind the "wavesReady" position. At waveform-size 8192 (on waveformGenerator), "best" total amount of waveforms would be 127. As this is also the amount of waveforms the waveformLoader will expect.
Author: Remco van der Most
License: BSD
Github: sss/osc/waveformTableCombinor.axo

Inlets

bool32 save

bool32 load

charptr32 filename

Outlets

None

Parameters

bool32.mom get

bool32.mom save

bool32.mom load

int32 wavesReady

Attributes

combo size

objref table

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;
uint32_t LENGTHPOW = attr_table.LENGTHPOW;
uint32_t LENGTH = attr_table.LENGTH;
uint32_t LENGTHMASK = attr_table.LENGTHMASK;
int32_t *array;
int strig;
int ltrig;
int gtrig;
int i;
int32_t Waveforms;
int32_t presets;
Init
static int32_t _array[SIZE] __attribute__((section(".sdram")));
array = &_array[0];
Control Rate
int save = param_save + inlet_save;
int load = param_load + inlet_load;

if ((save > 0) && !strig) {
  strig = 1;
  FIL FileObject;
  FRESULT err;
  UINT bytes_written;
  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(*array) * SIZE;
  int offset = 0;
  while (rem_sz > 0) {
    if (rem_sz > sizeof(fbuff)) {
      memcpy((char *)fbuff, (char *)(&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 *)(&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");
} else if (!(save > 0))
  strig = 0;

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;

if ((param_get > 0) && !gtrig) {
  gtrig = 1;
  for (i = 0; i < (attr_table.Waveforms * attr_table.LENGTH); i++) {
    array[i + (param_wavesReady * attr_table.LENGTH)] = attr_table.array[i];
    PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_wavesReady],
                       param_wavesReady + attr_table.Waveforms, 0xFFFD);
  }
} else if (param_get == 0) {
  gtrig = 0;
}

presets = Waveforms = param_wavesReady > 0 ? param_wavesReady : 1;

Privacy

© 2024 Zrna Research