frac32buffer in
frac32buffer out
bool32.mom randomise
int32 bits
frac32.u.map rangeIn
frac32.u.map rangeOut
int bit[32];
int32_t val[32];
int32_t left[32];
int32_t vloft[32];
int32_t vlaft[32];
int32_t vol[32];
int32_t vil[32];
int32_t vul[32];
int i;
int ntrig;
int posbit;
int32_t out;
int32_t filt;
if ((param_randomise > 0) && (!ntrig)) {
for (i = 0; i < 32; i++) {
vol[i] = ((GenerateRandomNumber()) >> 6);
vul[i] = ((GenerateRandomNumber()) >> 6);
}
ntrig = 1;
} else if (!(param_randomise > 0)) {
ntrig = 0;
}
val[0] = vol[0];
vloft[0] = param_rangeIn - ___SMMUL(param_rangeIn << 3, val[0] << 2);
for (i = 1; i < (param_bits - 1); i++) {
val[i] = ___SMMUL(vloft[i - 1] << 3, vol[i]);
vloft[i] = vloft[i - 1] - val[i];
}
val[param_bits - 1] = vloft[param_bits - 2];
vil[0] = vul[0];
vlaft[0] = param_rangeOut - ___SMMUL(param_rangeOut << 3, vil[0] << 2);
for (i = 1; i < (param_bits - 1); i++) {
vil[i] = ___SMMUL(vlaft[i - 1] << 3, vul[i]);
vlaft[i] = vlaft[i - 1] - vil[i];
}
vil[param_bits - 1] = vloft[param_bits - 2];
for (i = param_bits; i < 32; i++) {
bit[i] = 0;
}
// from continuous to bits
posbit = inlet_in > 0 ? 1 : -1;
left[0] = inlet_in > 0 ? inlet_in : -inlet_in;
for (i = 0; i < param_bits; i++) {
bit[i] = left[i] > val[i] ? 1 : 0;
left[i + 1] = left[i] - bit[i] * val[i];
}
// from bits to continuous
out = 0;
for (i = 0; i < param_bits; i++) {
out += bit[i] * vil[i];
}
filt = filt + ((out * posbit - filt) >> 1);
outlet_out = filt;