O4DP HardClip

4x oversampled HardClip with Differentiated Polynomial Anti aliasing.
Author: Smashed Transistors
License: BSD
Github: tiar/dev/O4DPHardClip.axo

Inlets

frac32buffer.bipolar in3

frac32buffer.bipolar in2

frac32buffer.bipolar in1

frac32buffer.bipolar in0

Outlets

frac32buffer.bipolar out3

frac32buffer.bipolar out2

frac32buffer.bipolar out1

frac32buffer.bipolar out0

Parameters

frac32.u.map InGain

frac32.u.map OutGain

Declaration
float x0, x1, I0, I1, out, inGain, outGain;
int32_t old_in;
int32_t outMax, outMin;
Init
x0 = x1 = I0 = I1 = out = 0;
old_in = 0;
Control Rate
inGain = param_InGain * (1.0f / (1 << 25)) * (1.0f / (1 << 27));
outGain = 2.0f * param_OutGain;
outMax = (int32_t)(outGain);
outMin = -outMax;
Audio Rate
x1 = x0;
x0 = inlet_in3 * inGain;
I1 = I0;
I0 = fabs(x0);
if (I0 <= 1) {
  I0 = 0.5f * I0 * I0;
} else {
  I0 = I0 - 0.5f;
}
if ((inlet_in3 & 0xFFFFF000) != (old_in & 0xFFFFF000)) {
  outlet_out3 = (int32_t)(outGain * (I0 - I1) / (x0 - x1));
} else {
  outlet_out3 = x0 >= 1 ? outMax : x0 <= -1 ? outMin : (int32_t)(outGain * x0);
}
old_in = inlet_in3;
// _________________________________________________________________
x1 = x0;
x0 = inlet_in2 * inGain;
I1 = I0;
I0 = fabs(x0);
if (I0 <= 1) {
  I0 = 0.5f * I0 * I0;
} else {
  I0 = I0 - 0.5f;
}
if ((inlet_in2 & 0xFFFFF000) != (old_in & 0xFFFFF000)) {
  outlet_out2 = (int32_t)(outGain * (I0 - I1) / (x0 - x1));
} else {

  outlet_out2 = x0 >= 1 ? outMax : x0 <= -1 ? outMin : (int32_t)(outGain * x0);
}
old_in = inlet_in2;
// _________________________________________________________________
x1 = x0;
x0 = inlet_in1 * inGain;
I1 = I0;
I0 = fabs(x0);
if (I0 <= 1) {
  I0 = 0.5f * I0 * I0;
} else {
  I0 = I0 - 0.5f;
}
if ((inlet_in1 & 0xFFFFF000) != (old_in & 0xFFFFF000)) {
  outlet_out1 = (int32_t)(outGain * (I0 - I1) / (x0 - x1));
} else {
  outlet_out1 = x0 >= 1 ? outMax : x0 <= -1 ? outMin : (int32_t)(outGain * x0);
}
old_in = inlet_in1;
// _________________________________________________________________
x1 = x0;
x0 = inlet_in0 * inGain;
I1 = I0;
I0 = fabs(x0);
if (I0 <= 1) {
  I0 = 0.5f * I0 * I0;
} else {
  I0 = I0 - 0.5f;
}
if ((inlet_in0 & 0xFFFFF000) != (old_in & 0xFFFFF000)) {
  outlet_out0 = (int32_t)(outGain * (I0 - I1) / (x0 - x1));
} else {
  outlet_out0 = x0 >= 1 ? outMax : x0 <= -1 ? outMin : (int32_t)(outGain * x0);
}
old_in = inlet_in0;

Privacy

© 2024 Zrna Research