// File: /workspace/github_cpp_makefile_star2_O3/ke6jjj[P]r-dat/AudioFrameReceiver.cc
// Function: AudioFrameReceiver::ReceiveFrame(Track const&, Track const&)
void
AudioFrameReceiver::ReceiveFrame(const Track& a, const Track& b)
{
  const uint8_t *item;
  uint32_t absoluteFrame = 0;

  printf("\n");

  //
  // Examine the Absolute Time subcode.
  //
  if (a.GetSubcode(2, &item)) {
    TimeCode time(item);
    absoluteFrame = time.AbsoluteFrame();
    printf("Absolute time: %02dh-%02dm-%02ds-%02df (%d)\n",
      time.Hour(),
      time.Minute(),
      time.Second(),
      time.Frame(),
      absoluteFrame
    );
    uint16_t program = time.Program();
    switch (program) {
    case TimeCode::PROGRAM_NOT_VALID:
      break;
    case TimeCode::PROGRAM_LEAD_IN:
    case TimeCode::PROGRAM_LEAD_OUT:
      printf("Program ID   : (%s)\n",
             program == TimeCode::PROGRAM_LEAD_IN ? "LEAD IN" : "LEAD_OUT");
      break;
    default:
      printf("Program ID   : %03d\n", program);
      break;
    }
    uint8_t index = time.Index();
    switch (index) {
    case TimeCode::INDEX_NOT_VALID:
      break;
    default:
      printf("Index ID     : %03d\n", index);
      break;
    }
  }
  
  //
  // If the absolute frame number is corrupted or the universal "I don't know"
  // value of 100h-100m-100s-100f (12203433), then display a session-psuedo
  // frame.
  //
  if (absoluteFrame == 0 || absoluteFrame == 12203433) {
    TimeCode time(static_cast<uint32_t>(mNextSessionFrameNumber));
    printf("Psuedo   time: %02dh-%02dm-%02ds-%02df (%d)\n",
      time.Hour(),
      time.Minute(),
      time.Second(),
      time.Frame(),
      mNextSessionFrameNumber
    );
    absoluteFrame = mNextSessionFrameNumber;
  }

  uint8_t control_id;
  if (a.GetControlID(control_id) && control_id != 0) {
    printf("Control      :");
    if (control_id & 0x1)
      // TOC ID
      printf(" TOC");
    if (control_id & 0x2)
      // Shortening ID
      printf(" SKIP");
    if (control_id & 0x4)
      // Start ID
      printf(" START");
    if (control_id & 0x8)
      printf(" PRIORITY");
    printf("\n");
  }
  
  //
  // Examine Program Time subcode.
  //
  if (a.GetSubcode(1, &item)) {
    TimeCode time(item);
    printf("Program time : %02dh-%02dm-%02ds-%02df\n",
      time.Hour(),
      time.Minute(),
      time.Second(),
      time.Frame()
    );
  }
    
  //
  // Examine Running Time / Pro R time.
  //
  if (a.GetSubcode(3, &item)) {
    TimeCode time(item);
    if (item[0] & 0x4) {
      //
      // Running Time.
      //
      printf("Running time : %02dh-%02dm-%02ds-%02df\n",
        time.Hour(),
        time.Minute(),
        time.Second(),
        time.Frame()
      );
    } else {
      //
      // Pro R Time
      //
      uint8_t sid = (item[0] & 3);
      uint8_t freq = (item[1] & 0xC0) >> 6;
      uint8_t xrate = (item[1] & 0x38) >> 3;
      uint8_t msb = (item[1] & 0x07);
      uint8_t lsb = item[2];
      const char *code_type;
      switch (sid) {
      case 0:
        code_type = "IEC/SMPTE";
        break;
      case 1:
        code_type = "Pro DIO; sample address";
        break;
      case 2:
        code_type = "Pro DIO; Time-of-day";
        break;
      case 3:
        code_type = "Reserved-3";
        break;
      default:
        code_type = "?";
        break;
      }
      const char *freq_str;
      switch (freq) {
      case 0:
        freq_str = "48 kHz";
        break;
      case 1:
        freq_str = "44.1 kHz";
        break;
      case 2:
        freq_str = "32 kHz";
        break;
      case 3:
        freq_str = "Reserved-3";
        break;
      default:
        freq_str = "?";
        break;
      }
      const char *smpte_xrate;
      switch (xrate) {
      case 0:
        smpte_xrate = "30 Hz";
        break;
      case 1:
        smpte_xrate = "29.97 Hz NDF";
        break;
      case 2:
        smpte_xrate = "29.97 Hz DF";
        break;
      case 3:
        smpte_xrate = "25 Hz";
        break;
      case 4:
        smpte_xrate = "24 Hz";
        break;
      case 5:
        smpte_xrate = "Reserved-5";
        break;
      case 6:
        smpte_xrate = "Reserved-6";
        break;
      case 7:
        smpte_xrate = "Reserved-7";
        break;
      default:
        smpte_xrate = "?";
        break;
      }
      printf("Pro R Time   : %02dh-%02dm-%02ds-%02df (%s-%s-%s)\n",
        time.Hour(),
        time.Minute(),
        time.Second(),
        time.Frame(),
        code_type,
        freq_str,
        smpte_xrate
      );
    }
  }

  //
  // Examine Table of Contents subcode.
  //
  if (a.GetSubcode(4, &item)) {
    printf("Table of Cont:\n");
    TimeCode time(item);
    uint16_t program = time.Program();
    switch (program) {
    case TimeCode::PROGRAM_NOT_VALID:
      break;
    case TimeCode::PROGRAM_LEAD_IN:
    case TimeCode::PROGRAM_LEAD_OUT:
      printf("  Program ID : (%s)\n",
             program == TimeCode::PROGRAM_LEAD_IN ? "LEAD IN" : "LEAD_OUT");
      break;
    default:
      printf("  Program ID : %03d\n", program);
      break;
    }
    uint8_t index = time.Index();
    switch (index) {
    case TimeCode::INDEX_NOT_VALID:
      break;
    default:
      printf("  Index ID   : %03d\n", index);
      break;
    }
    printf("  Time       : %02dh-%02dm-%02ds-%02df\n",
      time.Hour(),
      time.Minute(),
      time.Second(),
      time.Frame()
    );
  }

  //
  // Examine the Date & Time subcode.
  //
  if (a.GetSubcode(5, &item))
    HandleDateTime(item, absoluteFrame);
  else
    HandleDateTime(NULL, absoluteFrame);

  //
  // Examine Catalog Number subcode.
  //
  if (a.GetSubcode(6, &item)) {
  }

  //
  // Examine ISRC subcode.
  //
  if (a.GetSubcode(7, &item)) {
    printf("ISRC         : (not yet)\n");
  }

  //
  // Examine Pro Binary subcode.
  //
  if (a.GetSubcode(8, &item)) {
    printf("Pro Binary   : (not yet)\n");
  }

  //
  // Print the sub-code signature.
  //
  const Track::SubcodeSignatureArray& signature = a.SubcodeSignature();
  printf("Subcode packs:");
  for (size_t i = 0; i < 7; i++)
    printf(" %-2d", signature[i]);
  putchar('\n');

  //
  // Fetch and demultiplex all the data from the track pair.
  //
  mFrame.FillFromTrackPair(a, b);
  const DATFrame::DataArray& data = mFrame.Data();

  //
  // Print out error statistics for the frame.
  //
  unsigned int c1_errors = mFrame.C1Errors();
  unsigned int c1_uncorrectable = mFrame.C1UncorrectableErrors();
  unsigned int c1_corrected = c1_errors - c1_uncorrectable;
  unsigned int c2_uncorrectable = mFrame.C2UncorrectableErrors();
  unsigned int c2_corrected = c1_uncorrectable - c2_uncorrectable;

  printf("Errors  C1/C2: %d/%d",
    c1_corrected,
    c2_corrected
  );

  if (c2_uncorrectable > 0)
    printf(" %d UNCORRECTED\n", c2_uncorrectable);
  else
    printf(" (all corrected)\n");
  

  printf("Samples      : L    R\n");
  for (size_t i = 0; i < 8; i++) {
    printf("               %02x%02x %02x%02x\n",
      data[i][1], data[i][0],
      data[i][3], data[i][2]
    );
  }

  //
  // Ensure that everything printed so far is immediately visible.
  //
  fflush(stdout);

  //
  // Dump samples to file, if asked.
  //
  if (mFile != NULL) {
    for (size_t i = 0; i < DATFrame::kUserDataRows; i++) {
      fwrite(data[i], DATFrame::kBytesPerRow, 1, mFile);
    }
    mFramesWritten += DATFrame::kUserDataRows;
  }

  mHaveLastAbsoluteFrameNumber = true;
  mLastAbsoluteFrameNumber = absoluteFrame;
  mNextSessionFrameNumber++;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, 0x40(%rsp)
movq %rsi, %r15
movq %rdi, %rbx
movl $0xa, %edi
callq 0x2170
leaq 0x18(%rsp), %rdx
movq %r15, %rdi
movl $0x2, %esi
callq 0x35ac
testb %al, %al
je 0x3d4b
movq 0x18(%rsp), %rsi
leaq 0xe(%rsp), %r14
movq %r14, %rdi
callq 0x77f8
movq %r14, %rdi
callq 0x7934
movl %eax, %r13d
leaq 0xe(%rsp), %rdi
callq 0x7924
movl %eax, %r12d
leaq 0xe(%rsp), %rdi
callq 0x7928
movl %eax, %r14d
leaq 0xe(%rsp), %rdi
callq 0x792c
movl %eax, %ebp
leaq 0xe(%rsp), %rdi
callq 0x7930
movzbl %r12b, %esi
movzbl %r14b, %edx
movzbl %bpl, %ecx
movzbl %al, %r8d
leaq 0x5f40(%rip), %rdi      # 0x9bf9
movl %r13d, %r9d
xorl %eax, %eax
callq 0x2040
leaq 0xe(%rsp), %rdi
callq 0x791c
movzwl %ax, %esi
cmpl $0x80aa, %esi           # imm = 0x80AA
je 0x3d1e
cmpl $0x80bb, %esi           # imm = 0x80BB
je 0x3ce8
cmpl $0x80ee, %esi           # imm = 0x80EE
jne 0x3d10
cmpl $0x80bb, %esi           # imm = 0x80BB
leaq 0x5f46(%rip), %rax      # 0x9c3b
leaq 0x5f47(%rip), %rsi      # 0x9c43
cmoveq %rax, %rsi
leaq 0x5f1f(%rip), %rdi      # 0x9c26
xorl %eax, %eax
callq 0x2040
jmp 0x3d1e
leaq 0x5f35(%rip), %rdi      # 0x9c4c
xorl %eax, %eax
callq 0x2040
leaq 0xe(%rsp), %rdi
callq 0x7920
cmpb $-0x56, %al
je 0x3d3d
movzbl %al, %esi
leaq 0x5f2b(%rip), %rdi      # 0x9c61
xorl %eax, %eax
callq 0x2040
cmpl $0xba35a9, %r13d        # imm = 0xBA35A9
je 0x3d4b
testl %r13d, %r13d
jne 0x3db1
movl 0x2db8(%rbx), %esi
leaq 0xe(%rsp), %r14
movq %r14, %rdi
callq 0x789a
movq %r14, %rdi
callq 0x7924
movzbl %al, %ebp
movq %r14, %rdi
callq 0x7928
movzbl %al, %r12d
movq %r14, %rdi
callq 0x792c
movl %eax, %r13d
movq %r14, %rdi
callq 0x7930
movzbl %r13b, %ecx
movzbl %al, %r8d
movl 0x2db8(%rbx), %r9d
leaq 0x5ed8(%rip), %rdi      # 0x9c76
movl %ebp, %esi
movl %r12d, %edx
xorl %eax, %eax
callq 0x2040
movl 0x2db8(%rbx), %r13d
leaq 0xd(%rsp), %rsi
movq %r15, %rdi
callq 0x396c
testb %al, %al
je 0x3e39
cmpb $0x0, 0xd(%rsp)
je 0x3e39
leaq 0x5ed3(%rip), %rdi      # 0x9ca3
xorl %eax, %eax
callq 0x2040
movb 0xd(%rsp), %al
testb $0x1, %al
je 0x3df1
leaq 0x5ecc(%rip), %rdi      # 0x9cb2
xorl %eax, %eax
callq 0x2040
movb 0xd(%rsp), %al
testb $0x2, %al
je 0x3e07
leaq 0x5ebb(%rip), %rdi      # 0x9cb7
xorl %eax, %eax
callq 0x2040
movb 0xd(%rsp), %al
testb $0x4, %al
je 0x3e1d
leaq 0x5eab(%rip), %rdi      # 0x9cbd
xorl %eax, %eax
callq 0x2040
movb 0xd(%rsp), %al
testb $0x8, %al
je 0x3e2f
leaq 0x5e9c(%rip), %rdi      # 0x9cc4
xorl %eax, %eax
callq 0x2040
movl $0xa, %edi
callq 0x2170
leaq 0x18(%rsp), %rdx
movq %r15, %rdi
movl $0x1, %esi
callq 0x35ac
testb %al, %al
je 0x3ead
movq 0x18(%rsp), %rsi
leaq 0xe(%rsp), %r14
movq %r14, %rdi
callq 0x77f8
movq %r14, %rdi
callq 0x7924
movl %eax, %r12d
leaq 0xe(%rsp), %rdi
callq 0x7928
movl %eax, %r14d
leaq 0xe(%rsp), %rdi
callq 0x792c
movl %eax, %ebp
leaq 0xe(%rsp), %rdi
callq 0x7930
movzbl %r12b, %esi
movzbl %r14b, %edx
movzbl %bpl, %ecx
movzbl %al, %r8d
leaq 0x5e28(%rip), %rdi      # 0x9cce
xorl %eax, %eax
callq 0x2040
leaq 0x18(%rsp), %rdx
movq %r15, %rdi
movl $0x3, %esi
callq 0x35ac
testb %al, %al
movl %r13d, 0x24(%rsp)
je 0x3fee
movq 0x18(%rsp), %rsi
leaq 0xe(%rsp), %rdi
callq 0x77f8
movq 0x18(%rsp), %rcx
movzbl (%rcx), %eax
testb $0x4, %al
jne 0x3fa0
andl $0x3, %eax
movzbl 0x1(%rcx), %ecx
leaq 0x61b7(%rip), %r12      # 0xa0b0
movslq (%r12,%rax,4), %rax
movq %rax, 0x38(%rsp)
movl %ecx, %eax
shrl $0x6, %eax
leaq 0x61d2(%rip), %r13      # 0xa0e0
movslq (%r13,%rax,4), %rax
movq %rax, 0x30(%rsp)
shrl %ecx
andl $0x1c, %ecx
leaq 0x619c(%rip), %r14      # 0xa0c0
movslq (%rcx,%r14), %rax
movq %rax, 0x28(%rsp)
leaq 0xe(%rsp), %rdi
callq 0x7924
movb %al, 0x17(%rsp)
leaq 0xe(%rsp), %rdi
callq 0x7928
movb %al, 0x16(%rsp)
leaq 0xe(%rsp), %rdi
callq 0x792c
movl %eax, %ebp
leaq 0xe(%rsp), %rdi
callq 0x7930
addq 0x38(%rsp), %r12
addq 0x30(%rsp), %r13
addq 0x28(%rsp), %r14
movzbl 0x17(%rsp), %esi
movzbl 0x16(%rsp), %edx
movzbl %bpl, %ecx
movzbl %al, %r8d
leaq 0x5e3c(%rip), %rdi      # 0x9dc3
movq %r12, %r9
xorl %eax, %eax
pushq %r14
pushq %r13
callq 0x2040
addq $0x10, %rsp
movl 0x24(%rsp), %r13d
jmp 0x3fee
leaq 0xe(%rsp), %rdi
callq 0x7924
movl %eax, %r12d
leaq 0xe(%rsp), %rdi
callq 0x7928
movl %eax, %r14d
leaq 0xe(%rsp), %rdi
callq 0x792c
movl %eax, %ebp
leaq 0xe(%rsp), %rdi
callq 0x7930
movzbl %r12b, %esi
movzbl %r14b, %edx
movzbl %bpl, %ecx
movzbl %al, %r8d
leaq 0x5d0f(%rip), %rdi      # 0x9cf6
xorl %eax, %eax
callq 0x2040
leaq 0x18(%rsp), %rdx
movq %r15, %rdi
movl $0x4, %esi
callq 0x35ac
testb %al, %al
je 0x40ec
leaq 0x5f36(%rip), %rdi      # 0x9f45
callq 0x21b0
movq 0x18(%rsp), %rsi
leaq 0xe(%rsp), %r14
movq %r14, %rdi
callq 0x77f8
movq %r14, %rdi
callq 0x791c
movzwl %ax, %esi
cmpl $0x80aa, %esi           # imm = 0x80AA
je 0x407f
cmpl $0x80bb, %esi           # imm = 0x80BB
je 0x4049
cmpl $0x80ee, %esi           # imm = 0x80EE
jne 0x4071
cmpl $0x80bb, %esi           # imm = 0x80BB
leaq 0x5be5(%rip), %rax      # 0x9c3b
leaq 0x5be6(%rip), %rsi      # 0x9c43
cmoveq %rax, %rsi
leaq 0x5d8e(%rip), %rdi      # 0x9df6
xorl %eax, %eax
callq 0x2040
jmp 0x407f
leaq 0x5d93(%rip), %rdi      # 0x9e0b
xorl %eax, %eax
callq 0x2040
leaq 0xe(%rsp), %rdi
callq 0x7920
cmpb $-0x56, %al
je 0x409e
movzbl %al, %esi
leaq 0x5d89(%rip), %rdi      # 0x9e20
xorl %eax, %eax
callq 0x2040
leaq 0xe(%rsp), %rdi
callq 0x7924
movl %eax, %r12d
leaq 0xe(%rsp), %rdi
callq 0x7928
movl %eax, %r14d
leaq 0xe(%rsp), %rdi
callq 0x792c
movl %eax, %ebp
leaq 0xe(%rsp), %rdi
callq 0x7930
movzbl %r12b, %esi
movzbl %r14b, %edx
movzbl %bpl, %ecx
movzbl %al, %r8d
leaq 0x5d50(%rip), %rdi      # 0x9e35
xorl %eax, %eax
callq 0x2040
leaq 0x18(%rsp), %r12
movq %r15, %rdi
movl $0x5, %esi
movq %r12, %rdx
callq 0x35ac
testb %al, %al
je 0x410c
movq 0x18(%rsp), %rsi
jmp 0x410e
xorl %esi, %esi
movq %rbx, %rdi
movl %r13d, %edx
callq 0x42ee
movq %r15, %rdi
movl $0x6, %esi
movq %r12, %rdx
callq 0x35ac
movq %r15, %rdi
movl $0x7, %esi
movq %r12, %rdx
callq 0x35ac
testb %al, %al
je 0x4149
leaq 0x5e10(%rip), %rdi      # 0x9f54
callq 0x21b0
leaq 0x18(%rsp), %rdx
movq %r15, %rdi
movl $0x8, %esi
callq 0x35ac
testb %al, %al
je 0x416b
leaq 0x5e07(%rip), %rdi      # 0x9f6d
callq 0x21b0
movq %r15, %rdi
callq 0x3606
movq %rax, %r14
leaq 0x5ce0(%rip), %rdi      # 0x9e5d
xorl %eax, %eax
callq 0x2040
leaq 0x5ce1(%rip), %r12      # 0x9e6c
xorl %r13d, %r13d
movzbl (%r14,%r13), %esi
movq %r12, %rdi
xorl %eax, %eax
callq 0x2040
incq %r13
cmpq $0x7, %r13
jne 0x418e
movl $0xa, %edi
callq 0x2170
leaq 0x18(%rbx), %r12
movq %r12, %rdi
movq %r15, %rsi
movq 0x40(%rsp), %rdx
callq 0x5926
movq %r12, %rdi
callq 0x5b20
movq %rax, %r14
movq %r12, %rdi
callq 0x5b44
movq %rax, %r13
movq %r12, %rdi
callq 0x5b4c
movq %rax, %rbp
subl %ebp, %r13d
movq %r12, %rdi
callq 0x5b54
movq %rax, %r15
subl %r15d, %ebp
leaq 0x5c75(%rip), %rdi      # 0x9e72
movl %r13d, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x2040
testl %r15d, %r15d
je 0x4221
leaq 0x5c72(%rip), %rdi      # 0x9e87
movl %r15d, %esi
xorl %eax, %eax
callq 0x2040
jmp 0x422d
leaq 0x5d5e(%rip), %rdi      # 0x9f86
callq 0x21b0
movl 0x24(%rsp), %ebp
leaq 0x5d5f(%rip), %rdi      # 0x9f97
callq 0x21b0
leaq 0x5c54(%rip), %r15      # 0x9e98
xorl %r12d, %r12d
movzbl 0x1(%r14,%r12,4), %esi
movzbl (%r14,%r12,4), %edx
movzbl 0x3(%r14,%r12,4), %ecx
movzbl 0x2(%r14,%r12,4), %r8d
movq %r15, %rdi
xorl %eax, %eax
callq 0x2040
incq %r12
cmpq $0x8, %r12
jne 0x4247
movq 0xbd48(%rip), %rax      # 0xffc0
movq (%rax), %rdi
callq 0x2110
cmpq $0x0, 0x8(%rbx)
je 0x42b6
xorl %r15d, %r15d
leaq (%r14,%r15), %rdi
movq 0x8(%rbx), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x21f0
addq $0x4, %r15
cmpq $0x1680, %r15           # imm = 0x1680
jne 0x428a
addq $0x5a0, 0x10(%rbx)      # imm = 0x5A0
movb $0x1, 0x2db0(%rbx)
movl %ebp, 0x2db4(%rbx)
incl 0x2db8(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x42e6
jmp 0x42e6
jmp 0x42e6
jmp 0x42e6
jmp 0x42e6
jmp 0x42e6
jmp 0x42e6
movq %rax, %rdi
callq 0x21d0