bitmangler

analogue style bitcrusher/mangler (CPU HEAVY!!!) range In and Out set the max values that can be covered by the internal converters. Each bit is given a random value. This value determines the percentage of the left-over value, when all "higher" bits would be on, except for the last, which gets the remaining value that's needed to get it all together (sum of all bits) to the max value. This randomisation is done for both incoming bits(converting continous to bits) and outgoing bits (converting bits back to audio) independently. So, although perhaps bit1 goes on when incoming value is higher then 32, output bit1 might actually just be worth 0.0023. But all bits taken together sum up to the max, set by the range parameters. Use the "bits" parameter to set how many bits you want to use for conversion.
Author: Remco van der Most
License: BSD
Github: sss/dist/bitmangler.axo

Inlets

frac32buffer in

Outlets

frac32buffer out

Parameters

bool32.mom randomise

int32 bits

frac32.u.map rangeIn

frac32.u.map rangeOut

Declaration
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;
Control Rate
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;
}
Audio Rate
// 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;

Privacy

© 2024 Zrna Research