softquant

A "soft" quantizer with a filter to smoothly morph between unquantized (original) and quantized signal. The filter LP-filter dampens the offset that is created by the quantizer in comparison with the original signal.
Author: Remco van der most
License: BSD
Github: sss/dist/softquant.axo

Inlets

frac32buffer i1

frac32 quant

frac32 damp

Outlets

frac32buffer o1

Parameters

frac32.u.map Turn up quant to quantize the signal. Note that "damp" should be opened at least a bit to have quantizing effect

frac32.s.map.pitch Damps the quantizing. When fully damped, original signal will come. Note though, that the quantizing could generate a DC-offset

bool32.tgl sets the filter mode: OFF=normal 6dB filter without resonance, ON=SVF with resonanc

frac32.u.map.filterq filter resonance amount when mode is ON.

Declaration
int32_t LP;
int32_t prv;
int i;
int32_t low;
int32_t band;
int32_t notch;
int32_t high;
int32_t SVF(int32_t IN) {
  band -= ___SMMUL(___SMMUL(band << 2, band << 2), band << 2);
  notch = IN - (___SMMUL(res, band) << 1);
  low = low + (___SMMUL(freq, band) << 1);
  high = notch - low;
  band = (___SMMUL(freq, high) << 1) + band;
}
int32_t freq;
int32_t res;
Control Rate
int32_t quant = param_quant + inlet_quant;
quant = quant & ((1 << 28) - 1);
quant = quant > (1 << 27) ? (1 << 28) - quant : quant;
quant = ___SMMUL(quant << 3, quant << 2) + 1;
int32_t dmp;
if (param_mode == 0) {

  MTOF(param_damp + inlet_damp, dmp)
} else {
  res = (0x80 << 24) - (param_res << 4);
  res = ___SMMUL(res, res);
  int32_t alpha;
  MTOFEXTENDED(param_damp + inlet_damp, alpha);
  SINE2TINTERP(alpha, freq);
}
Audio Rate
int32_t diff = inlet_i1 - prv;
int32_t out;
for (i = 0; i < 2; i++) {
  int32_t i1 = prv + diff * i;
  int32_t o1 = i1 / quant * quant;
  int32_t d1 = i1 - o1;
  if (param_mode == 0) {
    LP = ___SMMLA((d1 - LP) << 1, dmp, LP);
    out = o1 + (d1 - LP);
  } else {
    SVF(d1);
    out = o1 + high;
  }
}
outlet_o1 = out;
prv = inlet_i1;

Privacy

© 2024 Zrna Research