gen

LTC (linear timecode) generator, in sync with the audio sample clock. Does not support drop-frame format. This implementation only works when the system clock is 48kHz or 96kHz, not at 44.1kHz!
Author: Johannes Taelman
License: BSD
Github: ltc/gen.axo

Inlets

None

Outlets

int32 hours

int32 minutes

int32 seconds

int32 frames

frac32buffer ltc output

Attributes

combo fps

Declaration
uint8_t h;  // hour counter
uint8_t m;  // minute counter
uint8_t s;  // seconds counter
uint8_t f;  // frame counter
uint8_t b;  // bit counter
uint8_t ss; // sample counter
int32_t bo; // bit output

void inc() {
  f++;
  if (f == attr_fps) {
    f = 0;
    s++;
    if (s == 60) {
      s = 0;
      m++;
      if (m == 60) {
        m = 0;
        h++;
      }
    }
  }
}
void getbit() {
  b++;
  if (b == 160) {
    b = 0;
    inc();
  }
  if ((b & 1) == 0) {
    bo = -bo;
  } else {
    switch (b >> 1) {
    case 0:
      bo = ((f % 10) & 0x1) ? -bo : bo;
      break;
    case 1:
      bo = ((f % 10) & 0x2) ? -bo : bo;
      break;
    case 2:
      bo = ((f % 10) & 0x4) ? -bo : bo;
      break;
    case 3:
      bo = ((f % 10) & 0x8) ? -bo : bo;
      break;
    case 4: // user bits field 1
    case 5:
    case 6:
    case 7:
      break;
    case 8:
      bo = ((f / 10) & 0x1) ? -bo : bo;
      break;
    case 9:
      bo = ((f / 10) & 0x2) ? -bo : bo;
      break;
    case 10: // drop frame
    case 11: // color frame
    case 12: // user bits field 2
    case 13:
    case 14:
    case 15:
      break;
    case 16:
      bo = ((s % 10) & 0x1) ? -bo : bo;
      break;
    case 17:
      bo = ((s % 10) & 0x2) ? -bo : bo;
      break;
    case 18:
      bo = ((s % 10) & 0x4) ? -bo : bo;
      break;
    case 19:
      bo = ((s % 10) & 0x8) ? -bo : bo;
      break;
    case 20: // user bits field 3
    case 21:
    case 22:
    case 23:
      break;
    case 24:
      bo = ((s / 10) & 0x1) ? -bo : bo;
      break;
    case 25:
      bo = ((s / 10) & 0x2) ? -bo : bo;
      break;
    case 26:
      bo = ((s / 10) & 0x4) ? -bo : bo;
      break;
    case 27: // even parity (unimplemented)
    case 28: // user bits field 4
    case 29:
    case 30:
    case 31:
      break;
    case 32:
      bo = ((m % 10) & 0x1) ? -bo : bo;
      break;
    case 33:
      bo = ((m % 10) & 0x2) ? -bo : bo;
      break;
    case 34:
      bo = ((m % 10) & 0x4) ? -bo : bo;
      break;
    case 35:
      bo = ((m % 10) & 0x8) ? -bo : bo;
      break;
    case 36: // user bits field 5
    case 37:
    case 38:
    case 39:
      break;
    case 40:
      bo = ((m / 10) & 0x1) ? -bo : bo;
      break;
    case 41:
      bo = ((m / 10) & 0x2) ? -bo : bo;
      break;
    case 42:
      bo = ((m / 10) & 0x4) ? -bo : bo;
      break;
    case 43: // binary group flag
    case 44: // user bits field 6
    case 45:
    case 46:
    case 47:
      break;
    case 48:
      bo = ((h % 10) & 0x1) ? -bo : bo;
      break;
    case 49:
      bo = ((h % 10) & 0x2) ? -bo : bo;
      break;
    case 50:
      bo = ((h % 10) & 0x4) ? -bo : bo;
      break;
    case 51:
      bo = ((h % 10) & 0x8) ? -bo : bo;
      break;
    case 52: // user bits field 7
    case 53:
    case 54:
    case 55:
      break;
    case 56:
      bo = ((h / 10) & 0x1) ? -bo : bo;
      break;
    case 57:
      bo = ((h / 10) & 0x2) ? -bo : bo;
      break;
    case 58:
      bo = ((h / 10) & 0x4) ? -bo : bo;
      break;
    case 59: // binary group flag
    case 60: // user bits field 8
    case 61:
    case 62:
    case 63:
      break;

    case 64:
    case 65:
      break;
    case 66:
    case 67:
    case 68:
    case 69:
    case 70:
    case 71:
    case 72:
    case 73:
    case 74:
    case 75:
    case 76:
    case 77:
      bo = -bo;
      break;
    case 78:
      break;
    case 79:
      bo = -bo;
      break;
    default:
      break;
    }
  }
}
Init
h = 0;
m = 0;
s = 0;
f = 0;
b = 0;
ss = 0;
bo = 1 << 26;
Control Rate
outlet_h = h;
outlet_m = m;
outlet_s = s;
outlet_f = f;
Audio Rate
outlet_out = bo;
ss++;
if (ss == ((SAMPLERATE / 160) / attr_fps)) {
  ss = 0;
  getbit();
}

Privacy

© 2024 Zrna Research