glide_multi

glide module for control signals with 3 different glide modes: 1-exponential (continous calculation of difference between current output value and input value, adding a part of the difference to the output at each sample calculation) 2-linear difference (only when input changes, calculates difference and adds a portion of this to the current output value at each new sample until it reaches the input value. 3-linear static time (when input changes, adds/subtracts a fixed value to the current output value until it reaches the input value. Difference between values does not influence change-rate.
Author: Remco van der Most
License: BSD
Github: sss/math/glide_multi.axo

Inlets

frac32 in

bool32 glideOFF

Outlets

frac32 out

Parameters

frac32.u.map glide

int32.hradio exponential,linear,linear static time

Declaration
int32_t prev;
int32_t follow;
int64_t diff;
int64_t rate;
Control Rate
rate = ___SMMUL(param_glide << 3, param_glide << 2);
rate = rate << 8;
if (inlet_glideOFF == 0) {
  if (param_mode == 0) {
    diff = inlet_in - follow;
    diff = (diff << 21) / ((1 << 21) + rate);
    follow += diff;
    outlet_out = follow;
  }
  if (param_mode == 1) {
    if (!(inlet_in == prev)) {
      diff = inlet_in - follow;
    }
    if (diff > 0) {
      if (follow > inlet_in) {
        diff = 0;
        follow = inlet_in;
      }
    }
    if (diff < 0) {
      if (follow < inlet_in) {
        diff = 0;
        follow = inlet_in;
      }
    }
    follow += (diff << 21) / ((1 << 21) + rate);
    outlet_out = follow;
    prev = inlet_in;
  }

  if (param_mode == 2) {
    if (!(inlet_in == prev)) {
      diff = inlet_in - follow;
      diff = diff > 0 ? (1 << 27) : -(1 << 27);
    }
    if (diff > 0) {
      if (follow > inlet_in) {
        diff = 0;
        follow = inlet_in;
      }
    }
    if (diff < 0) {
      if (follow < inlet_in) {
        diff = 0;
        follow = inlet_in;
      }
    }
    follow += (diff << 21) / ((1 << 21) + rate);
    outlet_out = follow;
    prev = inlet_in;
  }
} else {
  outlet_out = inlet_in;
}

Privacy

© 2024 Zrna Research