SatPoly

SoftClip with Differentiated Polynomial Anti aliasing.
Author: Smashed Transistors
License: BSD
Github: tiar/dist/SatPoly.axo

Inlets

frac32buffer.bipolar in

Outlets

frac32buffer out

Parameters

frac32.s.map.ratio a

frac32.s.map.ratio b

frac32.s.map.ratio c

frac32.s.map.ratio d

frac32.s.map.ratio e

frac32.s.map.ratio f

Declaration
float poly(float x) {
  return a + x * (b + x * (c + x * (d + x * (e + x * f))));
}
float Poly(float x) {
  return x * (A + x * (B + x * (C + x * (D + x * (E + x * F)))));
}
float fsat(float x) {
  if (x >= +1)
    return poly(+1);
  else if (x <= -1)
    return poly(-1);
  else
    return poly(x);
}
/*float Fsat(float x){
        if(x >= +1) return F(+1) + f(+1) * (x - 1);
  else if (x <= -1) return F(-1) + f(-1) * (x + 1);
  else return F(x);
}*/
float Fsat(float x) {
  if (x >= +1)
    return Fp1mfp1 + fp1 * x;
  else if (x <= -1)
    return Fm1pfm1 + fm1 * x;
  else
    return Poly(x);
}

const float coef = 1.0f / (1 << 27);
float x0, x1;
float a, b, c, d, e, f;
float A, B, C, D, E, F;
float F0, F1;
float Fp1mfp1, fp1;
float Fm1pfm1, fm1;
int32_t _param_a, _param_b, _param_c, _param_d, _param_e, _param_f;
Init
x0 = x1 = F0 = F1 = 0;
_param_a = _param_b = _param_c = _param_d = _param_e, _param_f = -3245;
Control Rate
if (_param_a != param_a || _param_b != param_b || _param_c != param_c ||
    _param_d != param_d || _param_e != param_e || _param_f != param_f) {
  _param_a = param_a;
  _param_b = param_b;
  _param_c = param_c;
  _param_d = param_d;
  _param_e = param_e;
  _param_f = param_f;
  a = param_a * coef;
  b = param_b * coef;
  c = param_c * coef;
  d = param_d * coef;
  e = param_e * coef;
  f = param_f * coef;

  A = a;
  B = b * 0.5f;
  C = c * 0.33333333333333f;
  D = d * 0.25f;
  E = e * 0.2f;
  F = f * 0.16666666666667f;

  fp1 = poly(+1);
  Fp1mfp1 = Poly(+1) - fp1;
  fm1 = poly(-1);
  Fm1pfm1 = Poly(-1) + fm1;

  // DISPLAY
  /* for(int i = 0;i<128;i++){

   }*/
}
F1 = Fsat(x1);
Audio Rate
x0 = (float)(inlet_in * coef);
F0 = Fsat(x0);
if (x1 != x0)
  outlet_out = (int32_t)((1 << 27) * (F1 - F0) / (x1 - x0));
else
  outlet_out = (int32_t)((1 << 27) * fsat(x0));
x1 = x0;
F1 = F0;

Privacy

© 2024 Zrna Research