deglitcher

Deglitcher, fade out -> trig (blocking operation) -> fade in
Author: Are Leistad
License: BSD
Github: drj/audio/deglitcher.axo

IO Variants: 2


Variant: 1

Inlets

bool32.rising Trigger input

frac32buffer.bipolar Left input

frac32buffer.bipolar Right input

Outlets

bool32.pulse Trigger output

frac32buffer.bipolar Left output

frac32buffer.bipolar Right output

Attributes

combo volfade

Declaration
//#define DEBUGF LogTextMessage
#define DEBUGF(...)                                                            \
  {}

int32_t old_inlet_trig;
int32_t trig_pulse;
int32_t gain_coeff;
#if attr_volfade < (1 << 27)
int32_t fade_rate;
#endif
Init
old_inlet_trig = 0;
trig_pulse = 0;
gain_coeff = (1 << 27);
#if attr_volfade < (1 << 27)
fade_rate = 0;
#endif
Control Rate
if (inlet_trig && !old_inlet_trig) {
#if attr_volfade < (1 << 27)
  // Start fade out
  fade_rate = -attr_volfade;
  DEBUGF("deglitcher::krate(): initiate trigger");
#else
  // Use immediate trigger
  codec_clearbuffer();
  trig_pulse = 1;
  DEBUGF("deglitcher::krate(): immediate trigger");
#endif
}

#if attr_volfade < (1 << 27)
/*
 *  Waits for the volume to ramp down before performing deferred triggering
 *  then ramps the volume back up when the potentially blocking operation is
 * done We save this codespace if immedate preset switching is used.
 */
if (fade_rate < 0) {
  // Fading out before trigger
  gain_coeff += fade_rate;
  if (gain_coeff <= 0) {
    gain_coeff = 0;
    fade_rate = 0;
    fade_rate = attr_volfade; // Start fade out
    trig_pulse = 1;           // Trick potentially blocking operation
    codec_clearbuffer();
    DEBUGF("deglitcher::krate(): deferred trigger");
  }
} else if (fade_rate > 0) {
  // Fading in after trigger
  gain_coeff += fade_rate;
  if (gain_coeff >= 1 << 27) {
    gain_coeff = 1 << 27;
    fade_rate = 0;
  }
}
#endif

outlet_trig = trig_pulse;
old_inlet_trig = inlet_trig;
trig_pulse = 0;

for (int i = 0; i < BUFSIZE; ++i) {
  outlet_left[i] = __SSAT(___SMMUL(gain_coeff, inlet_left[i]), 28);
  outlet_right[i] = __SSAT(___SMMUL(gain_coeff, inlet_right[i]), 28);
}

Variant: 2

Inlets

bool32.rising Trigger input

Outlets

bool32.pulse Trigger output

frac32.positive Volume fade out/in

Attributes

combo volfade

Declaration
//#define DEBUGF LogTextMessage
#define DEBUGF(...)                                                            \
  {}

int32_t old_inlet_trig;
int32_t trig_pulse;
int32_t gain_coeff;
#if attr_volfade < (1 << 27)
int32_t fade_rate;
#endif
Init
old_inlet_trig = 0;
trig_pulse = 0;
gain_coeff = (1 << 27);
#if attr_volfade < (1 << 27)
fade_rate = 0;
#endif
Control Rate
if (inlet_trig && !old_inlet_trig) {
#if attr_volfade < (1 << 27)
  // Start fade out
  fade_rate = -attr_volfade;
  DEBUGF("deglitcher::krate(): initiate trigger");
#else
  // Use immediate trigger
  codec_clearbuffer();
  trig_pulse = 1;
  DEBUGF("deglitcher::krate(): immediate trigger");
#endif
}

#if attr_volfade < (1 << 27)
/*
 *  Waits for the volume to ramp down before performing deferred triggering
 *  then ramps the volume back up when the potentially blocking operation is
 * done We save this codespace if immedate preset switching is used.
 */
if (fade_rate < 0) {
  // Fading out before trigger
  gain_coeff += fade_rate;
  if (gain_coeff <= 0) {
    gain_coeff = 0;
    fade_rate = 0;
    fade_rate = attr_volfade; // Start fade out
    trig_pulse = 1;           // Trick potentially blocking operation
    codec_clearbuffer();
    DEBUGF("deglitcher::krate(): deferred trigger");
  }
} else if (fade_rate > 0) {
  // Fading in after trigger
  gain_coeff += fade_rate;
  if (gain_coeff >= 1 << 27) {
    gain_coeff = 1 << 27;
    fade_rate = 0;
  }
}
#endif

outlet_volume = gain_coeff;
outlet_trig = trig_pulse;
old_inlet_trig = inlet_trig;
trig_pulse = 0;

Privacy

© 2024 Zrna Research