4RngCount

quad range counter (divremc with internal level manipulation)
Author: Remco van der Most
License: BSD
Github: sss/patt/4RngCount.axo

Inlets

int32 nominator

int32 denominator

int32 MidRng

int32 PstRng

int32 AftRng

frac32 PreMul

frac32 PreJmp

frac32 PreChg

frac32 MidMul

frac32 MidJmp

frac32 MidChg

frac32 PstMul

frac32 PstJmp

frac32 PstChg

Outlets

int32 PreRng

int32 MidRng

int32 PstRng

int32 AftRng

Declaration
int32_t ptrig;
int32_t pval;
Init
ptrig = 0;
pval = 0;
Control Rate
int r;
int s;
int t;
int u;
int a;
int b;
int c;
int d;
int e;
int f;
int g;
int h;
int i;
int j;
int k;
int l;
int m;
int n;

if (inlet_Count >= 0)
  r = ((unsigned int)inlet_Count) / inlet_PreRng;
else
  r = -(((unsigned int)(inlet_PreRng - inlet_Count)) / inlet_PreRng);

a = inlet_Count - (r * inlet_PreRng);
c = inlet_MidRng << 2;
b = a * ___SMMUL((inlet_PreMul) << 3, c) + r * ___SMMUL(inlet_PreJmp << 3, c) +
    r * a * ___SMMUL(inlet_PreChg << 3, c);

if (b >= 0)
  s = ((unsigned int)b) / inlet_MidRng;
else
  s = -(((unsigned int)(inlet_MidRng - b)) / inlet_MidRng);

d = b - (s * inlet_MidRng);
f = inlet_PstRng << 2;
e = d * ___SMMUL((inlet_MidMul) << 3, f) + s * ___SMMUL(inlet_MidJmp << 3, f) +
    s * d * ___SMMUL(inlet_MidChg << 3, f);

if (e >= 0)
  t = ((unsigned int)e) / inlet_PstRng;
else
  t = -(((unsigned int)(inlet_PstRng - e)) / inlet_PstRng);

g = e - (t * inlet_PstRng);
h = inlet_PstRng << 2;
i = g * ___SMMUL((inlet_PstMul) << 3, h) + t * ___SMMUL(inlet_PstJmp << 3, h) +
    t * g * ___SMMUL(inlet_PstChg << 3, h);

if (i >= 0)
  u = ((unsigned int)i) / inlet_AftRng;
else
  u = -(((unsigned int)(inlet_AftRng - i)) / inlet_AftRng);

j = i - (u * inlet_AftRng);

outlet_AftRng = j;
outlet_PstRng = g;
outlet_MidRng = d;
outlet_PreRng = a;

Privacy

© 2024 Zrna Research