tablecombo2

A combination of 3 objects: table/alloc 16b sdram table/load string/indexed This version has also got Dr. Justice deglitcher implemented, which mutes all sound from the patch = no BLIIIIP when changing table content.
Author: Jaffasplaffa
License: BSD
Github: jaffa/table/tablecombo2.axo

Inlets

int32 index

Outlets

frac32.positive volume

Attributes

combo size

combo volfade

table prefix

table suffix

Declaration
// String/index

int ntrig;
char c[64];
int offset;
int pval;

// Logic change //
int ptrig2;
int32_t pval2;

// Connect inlet to string/index VIA logic  change //
int32_t LcOut;

// Block BLEEEP //

//#define DEBUGF LogTextMessage
#define DEBUGF(...)                                                            \
  {}
enum { TABLE_LOAD_STATE_idle = 0, TABLE_LOAD_STATE_load } TABLE_LOAD_STATE;

int32_t old_inlet_trig;
int32_t trig_pulse;
int32_t gain_coeff;
#if attr_volfade < (1 << 27)
int32_t fade_rate;
int32_t table_load_state;
#endif

// outlet trigger fra deglitch
int32_t Deglitchout;

// 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;

/*
 *  Table load function
 */

int table_load(void) {
  char *filename = &c[0]; // filename internally //
  FIL FileObject;
  FRESULT err;
  UINT bytes_read;
  DEBUGF("Filename %s\n", filename);
  err = f_open(&FileObject, filename, FA_READ | FA_OPEN_EXISTING);
  if (err != FR_OK) {
    report_fatfs_error(err, filename);
    return err;
  }
  int rem_sz = sizeof(*array) * 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 *)(&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, filename);
    return err;
  }
  err = f_close(&FileObject);
  if (err != FR_OK) {
    report_fatfs_error(err, filename);
  }
  return err;
}
Init
// Table allocation
static int16_t _array[attr_poly][LENGTH] __attribute__((section(".sdram")));
array = &_array[parent->polyIndex][0];
for (int i = 0; i < LENGTH; i++) {
  array[i] = 0;
}

// String/index
ntrig = 0;
strcpy(&c[0], "attr_prefix000attr_suffix");
offset = strlen("attr_prefix");
pval = 0;

// Logic change //
ptrig2 = 0;
pval2 = 0;

// Block BLEEEP //

old_inlet_trig = 0;
trig_pulse = 0;
gain_coeff = (1 << 27);
#if attr_volfade < (1 << 27)
fade_rate = 0;
table_load_state = TABLE_LOAD_STATE_idle;
#endif
Control Rate
// String index

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;
}

// logic change //
if ((pval2 != inlet_index) & (!ptrig2)) {
  LcOut = 1;
  pval2 = inlet_index;
  ptrig2 = 1;
} else {
  ptrig2 = 0;
  LcOut = 0;
}

// Block BLEEEP //

if (LcOut && !old_inlet_trig) {
#if attr_volfade < (1 << 27)
  // Start fade out
  fade_rate = -attr_volfade;
  DEBUGF("deglitcher::krate(): initiate trigger");
#else
  // Use immediate trigger
  codec_clearbuffer();
  trig_pulse = 1;
  DEBUGF("deglitcher::krate(): immediate trigger");
#endif
}

#if attr_volfade < (1 << 27)
/*
 *  Waits for the volume to ramp down before performing deferred triggering
 *  then ramps the volume back up when the potentially blocking operation is
 * done We save this codespace if immedate preset switching is used.
 */
if (fade_rate < 0) {
  // Fading out before load
  gain_coeff += fade_rate;
  if (gain_coeff <= 0) {
    gain_coeff = 0;
    fade_rate = 0;
    codec_clearbuffer();
    if (table_load_state == TABLE_LOAD_STATE_load) {
      if (table_load() == FR_OK) {
        // Trig other potentially blocking operations
        trig_pulse = 1;
      }
    }
    // Start fade in after load
    fade_rate = attr_volfade;
    table_load_state = TABLE_LOAD_STATE_idle;
  }
} else if (fade_rate > 0) {
  // Fading in after trigger
  gain_coeff += fade_rate;
  if (gain_coeff >= 1 << 27) {
    gain_coeff = 1 << 27;
    fade_rate = 0;
  }
}
#endif

outlet_volume = gain_coeff;
Deglitchout = trig_pulse; // outlet_trig
old_inlet_trig = LcOut;
trig_pulse = 0;

// Table/load
if ((LcOut > 0) && !ntrig) {
  table_load_state = TABLE_LOAD_STATE_load;
  ntrig = 1;
} else if (!(LcOut > 0)) {
  ntrig = 0;
}

Privacy

© 2024 Zrna Research