f_to_c4

Author: Smashed Transistors
License: LGPL
Github: tiar/conv/f_to_c4.axo

Inlets

frac32 i0

frac32 i1

frac32 i2

frac32 i3

Outlets

charptr32 o

Declaration
char c[21];
Control Rate
c[20] = '\0';
int32_t in[4];
in[0] = inlet_i0;
in[1] = inlet_i1;
in[2] = inlet_i2;
in[3] = inlet_i3;
for (int i = 0; i < 4; i++) {
  char *p = c + i * 5;
  float f = arm::q_to_float(in[i], 21);
  // sign
  if (in[i] >= 0)
    p[0] = ' ';
  else {
    p[0] = '-';
    f = -f;
  }

  if (f >= 100) {
    // overflow
    p[1] = 127;
    p[2] = 127;
    p[3] = 127;
    p[4] = ' ';
  } else {
    { // decades
      int decades = (int)(f * 0.1f);
      if (decades == 0) {
        p[1] = p[0];
        p[0] = ' ';
      } else {
        p[1] = '0' + decades;
      }
      f -= decades * 10;
    }
    { // units
      int units = (int)(f);
      p[2] = '0' + units;
      f -= units * 1;
      p[3] = '.';
    }
    { // tenths
      int tenths = (int)(f * 10);
      p[4] = '0' + tenths;
    }
  }
}
outlet_o = c;

Privacy

© 2024 Zrna Research