fir16mod

finite impulse response filter, with up to 8 presets of 16 randomisable coefficients and offset-modulation. (help-file into a single module)
Author: Remco van der Most
License: BSD
Github: sss/filter/fir16mod.axo

Inlets

frac32buffer input

bool32 rnd

bool32 sync

int32 preset

Outlets

frac32buffer output

Parameters

frac32.s.map rate

frac32.s.map mod

frac32.s.map softsync

int32 preset

bool32.mom rnd

frac32.u.map size

Attributes

combo size

spinner presets

Declaration
arm_fir_instance_q31 f;
q31_t state[BUFSIZE + BUFSIZE - 1];
static const uint32_t LENGTHPOW = attr_size;
static const uint32_t LENGTH = 1 << attr_size;
static const uint32_t LENGTHMASK = (1 << attr_size) - 1;
int32_t Array[LENGTH * attr_presets];
int i;
int j;
int32_t buffer[BUFSIZE];
bool rnd;
int32_t phase;
int32_t sine;
bool snc;
int32_t SNC;
Init
arm_fir_init_q31(&f, BUFSIZE, 0, &state[0], BUFSIZE);
for (i = 0; i < LENGTH * attr_presets; i++) {
  Array[i] = (int32_t)(GenerateRandomNumber()) >> 2;
}
Control Rate
if (param_preset >= attr_presets) {
  PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_preset],
                     attr_presets - 1, 0xFFFD);
}

uint32_t soft;
MTOF(param_softsync, soft)
int32_t freq;
MTOFEXTENDED(param_rate, freq)
freq = freq >> 14;
int32_t preset = param_preset + inlet_preset;
preset = preset - preset / attr_presets * attr_presets;
preset += preset < 0 ? attr_presets : 0;
preset = preset << LENGTHPOW;
for (i = 0; i < BUFSIZE; i++) {
  SNC -= ___SMMUL(SNC, soft) >> 7;
  if ((inlet_sync > 0) && !snc) {
    snc = 1;
    SNC += phase;
    phase = 0;
  } else if (inlet_sync <= 0) {
    snc = 0;
  }
  phase += freq;
  int32_t sine;
  SINE2TINTERP(phase + SNC, sine)
  sine = ___SMMUL(sine >> 2, param_mod << 2);
  sine = ___SMMUL(param_size << 3, i << 25) + sine;
  // sine=__USAT(sine,27);
  sine = sine & ((1 << 27) - 1);
  uint32_t asat = sine;
  int index = asat >> (27 - LENGTHPOW);
  int32_t y1 = Array[index + preset];
  int32_t y2 = Array[((index + 1) & LENGTHMASK) + preset];
  int frac = (asat - (index << (27 - LENGTHPOW))) << (LENGTHPOW + 3);
  int32_t rr;
  rr = ___SMMUL(y1, (1 << 30) - frac);
  rr = ___SMMLA(y2, frac, rr);
  buffer[i] = rr << 2;
}

f.pCoeffs = (q31_t *)buffer;

arm_fir_fast_q31(&f, (q31_t *)inlet_in, outlet_out, BUFSIZE);

bool RND = (inlet_rnd + param_rnd) & 1;
if ((RND > 0) && !rnd) {
  rnd = 1;
  for (i = 0; i < (LENGTH * attr_presets); i++) {
    Array[i] = (int32_t)(GenerateRandomNumber()) >> 3;
  }
} else if (RND == 0) {
  rnd = 0;
}

Privacy

© 2024 Zrna Research