4RngCount2

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

Inlets

int32 Count Input

int32 denominator

int32 MidRng

int32 PstRng

int32 AftRng

int32 AftOfs

frac32 Count Offset

frac32 PreMul

frac32 PreJmp

frac32 PreChg

frac32 PreOfs

frac32 MidMul

frac32 MidJmp

frac32 MidChg

frac32 MidOfs

frac32 PstMul

frac32 PstJmp

frac32 PstChg

frac32 PstOfs

Outlets

int32 PreRng

int32 MidRng

int32 PstRng

int32 AftRng

Displays

int32.label PreRng

int32.label MidRng

int32.label PstRng

int32.label 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;
int32_t coun0;
coun0 = inlet_Count + inlet_CntOfs;
if (coun0 >= 0)
  r = ((unsigned int)coun0) / inlet_PreRng;
else
  r = -(((unsigned int)(inlet_PreRng - coun0)) / inlet_PreRng);

a = coun0 - (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) + inlet_PreOfs;

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) + inlet_MidOfs;

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) + inlet_PstOfs;

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

j = i - (u * inlet_AftRng) + inlet_AftOfs;

outlet_AftRng = j;
outlet_PstRng = g;
outlet_MidRng = d;
outlet_PreRng = a;
disp_AftRng = j;
disp_PstRng = g;
disp_MidRng = d;
disp_PreRng = a;

Privacy

© 2024 Zrna Research